Skip to content

Instantly share code, notes, and snippets.

@mrcaron
Created February 1, 2012 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcaron/1717425 to your computer and use it in GitHub Desktop.
Save mrcaron/1717425 to your computer and use it in GitHub Desktop.
VCPP STD::Map-backed Property Macros
#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