Skip to content

Instantly share code, notes, and snippets.

@mchinen
Created June 6, 2013 05:21
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 mchinen/5719480 to your computer and use it in GitHub Desktop.
Save mchinen/5719480 to your computer and use it in GitHub Desktop.
cococs2d-x macro to help with load save common cases for CCUserDefaults
//
// RSCCMacros.h
// doghouse
//
// Created by Michael Chinen on 13/05/17.
//
//
#ifndef doghouse_RSCCMacros_h
#define doghouse_RSCCMacros_h
// use this to ensure you don't fuck up the keys with copy pasta
#define LOADINTKEY(db, baseKey, varName, keyName) \
{\
char szKey[64] = {0};\
snprintf(szKey, 63, "%s%s", baseKey, keyName);\
varName = db->getIntegerForKey(szKey, varName);\
}
#define LOADINT(db, baseKey, varName) \
LOADINTKEY(db, baseKey, varName, #varName)
#define SAVEINTKEY(db, baseKey, varName, keyName) \
{\
char szKey[64] = {0};\
snprintf(szKey, 63, "%s%s", baseKey, keyName);\
db->setIntegerForKey(szKey, varName);\
}
#define SAVEINT(db, baseKey, varName) \
SAVEINTKEY(db, baseKey, varName, #varName)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment