mfc >> Data Type Conversion

by TWFjY2E » Wed, 02 Feb 2005 19:29:07 GMT

Hi,

I am looking for a data type, method that allows me to store mixed data
types, eg CString,int,double etc.

At the moment i am converting my mixed data types them into CStrings and
storing them in a CString Vector,

vector<CString> m_tEvents.

Now when i want access to the variables i then have to convert them from
CString back to their original data type. I would like to get rid of this
conversion to CString then conversion back to data type as i think it's
inefficient and unnecessary.

Does anyone know a method or data type that will stop me from having to do
these conversions?

Thanks In Advance
Macca


mfc >> Data Type Conversion

by Jeff F » Wed, 02 Feb 2005 21:02:08 GMT





Why do you need such a heterogeneous container? You'd be better off
abstracting a class heirarchy with appropriate virtual functions and place
(safe)pointers in the container. Then you would travers the container and
call the virtual function. If you 'must' have this heterogeneous container,
then see boost.any and boost.variant libraries at www.boost.org.

Jeff





mfc >> Data Type Conversion

by Dan Bloomquist » Thu, 03 Feb 2005 01:54:55 GMT





How about COleVariant?


Best, Dan.

--
http://lakeweb.net
http://ReserveAnalyst.com
No EXTRA stuff for email.
What can you see if you can't see it all...



Similar Threads

1. Data type conversion-Help

Hi Guys

I am tired of finding solution to this..
Help me when u find time

How to convert from


int[] to byte[] //right now i do by a for loop
byte[] to int[] //right now i do by a for loop
int[] to string  //I donno how to do this
string to int[]  //I donno how to do this

Regards
Badri


2. About data type conversion

3. problems with data type conversion (maybe)

i'm writing a program that executes some calculations on a bitmap loaded in
memory.
these calculation ends up with pixel wth values far over 255, but i need
them to be between 0 and 255 since i got to write them in a bmp file (in
which RGB values are limited to 8 bits per channel). so i need to have them
scaled down.

first of all i find the highest and lowest of those values:(keep in mind
that max, min, bmp[], ptr are ulong and w, h are uint):

// FIND HIGHEST/LOWEST VALUES TO BE USED IN 0-255 NORMALIZATION
max = 0; min = 0-1;
for (int ptr=0; ptr<w*h*3; ptr++) {
if (max < bmp[ptr]) {
max = bmp[ptr];
} else if (min > bmp[ptr]) {
min = bmp[ptr];
}
}

then i normalize everything to 255:

// NORMALIZE VALUES
for (int ptr=0; ptr<w*h*3; ptr++) {
bmp[ptr] = (unsigned long)((float)(bmp[ptr] - min) / (float)max *
(float)255);
}

at this point, everything is alright. if i write in a bmp file the contents
of the array i get what i expected.
but as soon as i denormalize and apply the inverse of the calculations i did
before (i tested them separately: without normalization/denormalization they
work fine)

//DENORMALIZE VALUES
for (int ptr=0; ptr<w*h*3; ptr++) {
bmp[ptr] = (unsigned long)((float)bmp[ptr] / (float)255 * (float)max) + min;
}

then i write down the content of the array:

// OUTPUTTING LOOPs
// COPY SOURCE IMAGE BMP HEADER - WORKING
fseek(fp1, 0, SEEK_SET);
for (int i=0; i<54; i++) {
fputc(fgetc(fp1),fp2);
}
// WRITE DATA CONTAINED IN THE BMP ARRAY IN THE SAME ORDER THEY WERE READ -
WORKING
for (int ptr=0; ptr<w*h*3; ptr++) {
fputc ((unsigned int)bmp[ptr], fp2);
}

but the bitmap i end up with it's a mess of random pixels.
i think i'm doing something wrong in the data type conversion of the
denormalization loop. anyone knows why? i do thank you in advance.

p.s. if you want the full source of the program go to
sourceforge.net/projects/simplify. the function you got to point at is void
test ()


4. Data source controls and parameter type conversion - CSharp/C#

5. proper type conversion between PTRDIFF and a type where I can see the type

I know this is a c++ message board rather than a windows one, but my
issue may be more related to type conversion (which is probably closer
to c++). I'm trying to convert/cast for example, dpwszFamilyName
member of IFIMETRICS structure from PTRDIFF type into a type where I
can read and process the type. How would you suggest me to go about on
achieving this objective?

6. C# data type keywords v. .Net data types - CSharp/C#

7. Type Conversion to Original Type

I have a class library, lets call it ClassLib, which contains an abstract 
class, lets call it Entity,  that acts as sort of a marker.

I have a web service that consumes the ClassLib to make use of the Entity 
abstract class. The web service has a class, lets call it MyEntity that 
inherits from ClassLib.Entity and a method called GetEntitites that returns 
an array of MyEntity classes.

Next I have a web application that consumes the web service. Of course the 
reference to the web services makes a proxy classes called Entity and 
MyEntity. The problem is that these types are NOT the same types as the web 
service referenced therefore when the GetEntities method is called it returns 
the array of MyEntity objects as defined by the proxy. 

This is all well and expected. I understand all of what I just explained. 
Now here comes my question...

How can I convert each of the MyEntity objects returned from the web service 
into the original type that the web serviced used from the ClassLib? 

NOTE: I do not want to change anything in the references.cs file of the 
reference to the web service. 

I looked at the System.ComponentModel.TypeConverter class but that just 
doesn't work. Casting doesn't work as well. Any ideas?

-- 
-Demetri

8. How to do type conversion to unknown type? - CSharp/C#