Variant.hpp - C++ "any" type
Is this an "Any" type?
- Yes! Good eye. When converting to a from two different languages (for script-binging or serialization) a lot of the time the actual type of the data doesn't matter. For example, whether I'm reading in an integer or a string from a text file, I still want to do the same thing. I want to read in data from that file into a block of memory I've allocated in my game engine. If the "any" type knows how to read in it's data from a file, then all I have to do is say any_type.ReadYourselfInSon(). This abstraction makes working with types very easy, because they're all the same at a high enough level.
What could you improve?
- For data types less than 4 bytes, I should just store them inside of the Variant instead of having to use a pointer to access the data.
- I really need to clean-up the conversion code in VariantRef. Thanks to Treb Connell for showing me how to do these conversions.
- Yes! Good eye. When converting to a from two different languages (for script-binging or serialization) a lot of the time the actual type of the data doesn't matter. For example, whether I'm reading in an integer or a string from a text file, I still want to do the same thing. I want to read in data from that file into a block of memory I've allocated in my game engine. If the "any" type knows how to read in it's data from a file, then all I have to do is say any_type.ReadYourselfInSon(). This abstraction makes working with types very easy, because they're all the same at a high enough level.
What could you improve?
- For data types less than 4 bytes, I should just store them inside of the Variant instead of having to use a pointer to access the data.
- I really need to clean-up the conversion code in VariantRef. Thanks to Treb Connell for showing me how to do these conversions.
VariantTest.cpp
The tests for these two classes are pretty simple. I just test construction and converting between different types.