Created
February 1, 2012 15:00
-
-
Save mrcaron/1717425 to your computer and use it in GitHub Desktop.
VCPP STD::Map-backed Property Macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _UNICODE | |
#define _map_property(_type, _name, _map) \ | |
_type Get##_name() { ASSERT( K_##_name > -1 ); return _map[K_##_name]; } \ | |
void Set##_name( _type val ) { ASSERT( K_##_name > -1); _map[K_##_name] = val; } \ | |
__declspec(property(get=Get##_name, put=Set##_name)) _type _name | |
typedef std::map<int, wstring> wstrmap; | |
class myClass | |
{ | |
private: | |
enum keys | |
{ | |
K_prop1, | |
K_prop2 | |
}; | |
wstrmap map1; | |
public: | |
_map_property(wstring, prop1, map1); | |
_map_property(wstring, prop2, map1); | |
wstrmap* getMap() { return &map1; } | |
}; | |
/* usage example | |
* | |
* myClass inst; | |
* inst.prop1 = _T("hello"); | |
* inst.prop2 = _T("world"); | |
* wstrmap::iterator end = inst.getMap()->end(); | |
* for( wstrmap::iterator it = inst.getMap()->begin(); it != end; it++) | |
* { | |
* wcout << it->second; | |
* } | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment