cast

Cast object to interface when created via reflection

I'm trying some stuff out in Android and I'm stuck at when trying to cast a class in another .apk to my interface. I have the interface and various classes in other .apks that implement that interface. I find the other classes using PackageManager's query methods and use Application#createPackageContext() to get the classloader for that ...

Fast double -> short conversion with clamping using SSE?

Is there a fast way to cast double values to shorts (16 bits signed), currently I'm doing something like this: double dval = <sum junk> int16_t sval; if (val > int16_max) { sval = int16_max; } else if (val < int16_min) { sval = int16_min; } else sval = (int16_t)val; I suspect there's a fast way to do this using SSE that wi...

How to cast a doubleto a decimal in Oracle SQL?

I am trying to cast a number, I think it is a double, to a decimal using the following: CAST(syr_ep AS decimal(10,3)) As EP which is still returning a double, so how do I achieve this? ...

Delphi interface cast using TValue

I've recently experimented extensively with interfaces and D2010 RTTI. I don't know at runtime the actual type of the interface; although I will have access to it's qualified name using a string. Consider the following: program rtti_sb_1; {$APPTYPE CONSOLE} uses SysUtils, Rtti, TypInfo, mynamespace in 'mynamespace.pas'; var ctx: ...

JTree TreePath casting problem

I got this casting problem java.lang.String cannot be cast to java.io.File, when I trying to do this TreePath p = new TreePath(new Object[] {"src","file","My Diary" }); This is my jtree file model class FileTreeModel implements TreeModel { private FileNode root; public FileTreeModel(String directory) { root = new FileNode(dir...

How to cast list to enumerable

I've got a problem with the following code: public IEnumerable<ISession> GetSessions() { // ... using (ProvaDbEntities DBEntities = new ProvaDbEntities(Utilities.ToEntitiesConnectionString())) { ObjectQuery<session> sessions = DBEntities.session; IEnumerable<session> q1 = from session in sessions ...

Casting from any

Hello, I'm packing some classes into ptr_map with any typed value. class EventManager { ptr_map<string, any> mSomeMap; public: typedef signals2::signal<void (int someSignature)> KeyEvent; EventManager() { mSomeMap["KeyPressed"] = new any(new KeyEvent()); } }; Now I want to restore my signal objec...

Sql server convert/cast int to varchar independent of db language/collation

I would like to convert/cast some int or bigint to varchar (in tsql). But I would like it to be in English regardless of database language, collation, etc. (I need to parse it back on the client side) Basically I am looking for tsql equivalent of this C# code 1234.ToString(CultureInfo.InvariantCulture) What should I do? Is this lan...

С++ TYPE CASTING

Hello there, i have very low C++ experiences and i need little help in casting a type. I actually in a big dependence for that cast, need it rly hard. So ... I have this types : typedef short DCTELEM; typedef DCTELEM DCTBLOCK[64]; Array of last type and a pointer to a malloc'ed array of shorts: DCTBLOCK MQUAD; short * ptrArray; ...

Java Custom ListCellRenderer casting problem (SSCCE included)

Hello all, I am trying to create a custom ListCellRenderer in order to give different foreground colors in each line, depending on the input of the jList. I am not an expert or anything, but I really can't figure this out. I get a casting error: Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast ...

Cast Stored Procedure Result as a Table? (SQL Server 2008)

Hey all, I currently have a stored procedure that runs a complex query and returns a data set. I'd like to cast this data set to a table (on which I can perform further queries) if at all possible. I know I can do this using a table-valued UDF but I'd prefer to avoid that at this point. Is there any way I can accomplish this task? T...

Cast generic dictionary in C#.

Is there a way to cast a dictionary i a one-liner and without all the overhead in C# .net 3? var result = new Dictionary<string, AccessoryVariant>(); foreach (BaseVariant variant in mVariants.Values) { result.Add(variant.Id, (AccessoryVariant)variant); } return result; I would like to do something like this: return (Dictionary<st...

Running a Quartz job with Java class name stored in database

I have a two jobs in Quartz which will run perfetly well but I find I have to use code like: jd = new JobDetail(sj.getJobName(), scheduler.DEFAULT_GROUP, PollJob.class); ct = new CronTrigger(sj.getJobTrigger(), scheduler.DEFAULT_GROUP, "0 20 * * * ?"); scheduler.scheduleJob(jd, ct); I have to hardcode PollJob.class to run the ...

Cast string data type to Int in SQL QUery for MS Access

I am trying to write a query in access that will pull results that are in the database in a text Acually,I have RECEIPTNO Column whose datatype is TEXT in Table Membership, & I want to pull all the results from RECEIPTNO column where RECEIPTNO is BETWEEN 1 AND 10 And I tried Below Code. SELECT Cint(RECEIPTNO) FROM MEMBERSHIP where Cint...

[C++] Cast int16_t memory to float

Hi Stackoverflow, I have a function from an external source that returns an array of 2 uint16_t elements (which I cast to int). I have already been able to cast these to one "big" int ((i1 << 16) + i2) Now I need to be able to cast this to float, keeping the point value as is in memory. Can anyone suggest a way or point me in the rig...

Cast IEnumerable<T> to ObservableCollection<T> without constructor injection the IEnumerable<T>

How can I do that? thats a no go: ObservableCollection obsCol = new ObservableCollection(myIEnumerable); scenario: var query = from c in customers select new Customer() { Products = from p in products where p.Id = c.Id ...

casting to Arrays in Python ctypes

I'm trying to convert a 16 byte blob of data returned by socket.inet_pton into a ctypes array of unsigned bytes. My data structure looks like this: class in6_addr(ctypes.Structure): _fields_ = (("Byte", ctypes.c_ubyte * 16),) And the blob is just: data = socket.inet_pton(socket.AF_INET6, "2001::3") However, these attempts get...

uint64_t to int

I'm writing a java binding for a C code and I'm not really familiar with C. I have a uint64_t and need to cast it to a int. Does anyone know how to do that? (My binding returns then a jint...) ...

Problem with cast convert and view all in TSQL

Dear Board, I have a view called vw_FormatTable1 which contains Convert( CHAR ( <SIZE> ), Coalesce (Convert (VarChar, [<FIELD>],120),'')) AS [<FIELD>] where <SIZE> is the width of the field to be output and <FIELD> is the field name And this basic block is repeated for all approx 600 fields in my base table creating a view of over 5...

Why is this Sql Server CAST(..) rounding a Decimal to a VarChar ?

Hi folks, I'm trying convert some decimals to varchar, but they are getting rounded. Can someone tell me why? declare @UpperLeftLatitude DECIMAL, @UpperLeftLongitude DECIMAL, @BottomRightLatitude DECIMAL, @BottomRightLongitude DECIMAL SET @UpperLeftLatitude = 38.663 SET @UpperLeftLongitude = -122.857 SET @BottomRightLatit...