From ac0e6dbc8d1ea8fd24712dd03fea154cea6a7135 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 6 Feb 2016 09:55:15 +0100 Subject: fixed line breaks --- libskindesignerapi/pluginstructure.c | 184 +++++------ libskindesignerapi/pluginstructure.h | 112 +++---- libskindesignerapi/tokencontainer.c | 610 +++++++++++++++++------------------ libskindesignerapi/tokencontainer.h | 136 ++++---- 4 files changed, 521 insertions(+), 521 deletions(-) (limited to 'libskindesignerapi') diff --git a/libskindesignerapi/pluginstructure.c b/libskindesignerapi/pluginstructure.c index 2d5d4f3..d846d7e 100644 --- a/libskindesignerapi/pluginstructure.c +++ b/libskindesignerapi/pluginstructure.c @@ -1,92 +1,92 @@ -#include "pluginstructure.h" - -skindesignerapi::cPluginStructure::cPluginStructure(void) { - name = ""; - libskindesignerAPIVersion = "undefined"; - id = -1; - rootview = ""; -}; - -skindesignerapi::cPluginStructure::~cPluginStructure(void) { - for (map::iterator it = menus.begin(); it != menus.end(); it++) { - delete (it->second).tokenContainer; - } -}; - -void skindesignerapi::cPluginStructure::RegisterMenu(int key, int type, string tpl, skindesignerapi::cTokenContainer *tk) { - tk->CreateContainers(); - sPlugMenu s; - s.type = type; - s.tplname = tpl; - s.tokenContainer = tk; - menus.insert(pair(key, s)); -} - -skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetMenuTokenContainer(int key) { - map::iterator hit = menus.find(key); - if (hit == menus.end()) - return NULL; - return hit->second.tokenContainer; -} - -void skindesignerapi::cPluginStructure::RegisterRootView(string templateName) { - rootview = templateName; -} - -void skindesignerapi::cPluginStructure::RegisterSubView(int subView, string templateName) { - subviews.insert(pair(subView, templateName)); -} - -void skindesignerapi::cPluginStructure::RegisterViewElement(int view, int viewElement, string name, skindesignerapi::cTokenContainer *tk) { - tk->CreateContainers(); - sPlugViewElement ve; - ve.id = viewElement; - ve.viewId = view; - ve.name = name; - ve.tokenContainer = tk; - viewelements.insert(pair(view, ve)); -} - -void skindesignerapi::cPluginStructure::RegisterViewGrid(int view, int viewGrid, string name, skindesignerapi::cTokenContainer *tk) { - tk->CreateContainers(); - sPlugViewGrid vg; - vg.id = viewGrid; - vg.viewId = view; - vg.name = name; - vg.tokenContainer = tk; - viewgrids.insert(pair(view, vg)); -} - -void skindesignerapi::cPluginStructure::RegisterViewTab(int view, skindesignerapi::cTokenContainer *tk) { - tk->CreateContainers(); - viewtabs.insert(pair(view, tk)); -} - -skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetTokenContainerVE(int viewId, int veId) { - pair::iterator, multimap::iterator> range; - range = viewelements.equal_range(viewId); - for (multimap::iterator it=range.first; it!=range.second; ++it) { - sPlugViewElement *ve = &it->second; - if (ve->id == veId) - return ve->tokenContainer; - } - return NULL; -} - -skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetTokenContainerGE(int viewId, int geId) { - pair::iterator, multimap::iterator> range; - range = viewgrids.equal_range(viewId); - for (multimap::iterator it=range.first; it!=range.second; ++it) { - sPlugViewGrid *ge = &it->second; - if (ge->id == geId) - return ge->tokenContainer; - } - return NULL; -} - -skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetTokenContainerTab(int viewId) { - map::iterator hit = viewtabs.find(viewId); - if (hit == viewtabs.end()) - return NULL; - return hit->second; -} +#include "pluginstructure.h" + +skindesignerapi::cPluginStructure::cPluginStructure(void) { + name = ""; + libskindesignerAPIVersion = "undefined"; + id = -1; + rootview = ""; +}; + +skindesignerapi::cPluginStructure::~cPluginStructure(void) { + for (map::iterator it = menus.begin(); it != menus.end(); it++) { + delete (it->second).tokenContainer; + } +}; + +void skindesignerapi::cPluginStructure::RegisterMenu(int key, int type, string tpl, skindesignerapi::cTokenContainer *tk) { + tk->CreateContainers(); + sPlugMenu s; + s.type = type; + s.tplname = tpl; + s.tokenContainer = tk; + menus.insert(pair(key, s)); +} + +skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetMenuTokenContainer(int key) { + map::iterator hit = menus.find(key); + if (hit == menus.end()) + return NULL; + return hit->second.tokenContainer; +} + +void skindesignerapi::cPluginStructure::RegisterRootView(string templateName) { + rootview = templateName; +} + +void skindesignerapi::cPluginStructure::RegisterSubView(int subView, string templateName) { + subviews.insert(pair(subView, templateName)); +} + +void skindesignerapi::cPluginStructure::RegisterViewElement(int view, int viewElement, string name, skindesignerapi::cTokenContainer *tk) { + tk->CreateContainers(); + sPlugViewElement ve; + ve.id = viewElement; + ve.viewId = view; + ve.name = name; + ve.tokenContainer = tk; + viewelements.insert(pair(view, ve)); +} + +void skindesignerapi::cPluginStructure::RegisterViewGrid(int view, int viewGrid, string name, skindesignerapi::cTokenContainer *tk) { + tk->CreateContainers(); + sPlugViewGrid vg; + vg.id = viewGrid; + vg.viewId = view; + vg.name = name; + vg.tokenContainer = tk; + viewgrids.insert(pair(view, vg)); +} + +void skindesignerapi::cPluginStructure::RegisterViewTab(int view, skindesignerapi::cTokenContainer *tk) { + tk->CreateContainers(); + viewtabs.insert(pair(view, tk)); +} + +skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetTokenContainerVE(int viewId, int veId) { + pair::iterator, multimap::iterator> range; + range = viewelements.equal_range(viewId); + for (multimap::iterator it=range.first; it!=range.second; ++it) { + sPlugViewElement *ve = &it->second; + if (ve->id == veId) + return ve->tokenContainer; + } + return NULL; +} + +skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetTokenContainerGE(int viewId, int geId) { + pair::iterator, multimap::iterator> range; + range = viewgrids.equal_range(viewId); + for (multimap::iterator it=range.first; it!=range.second; ++it) { + sPlugViewGrid *ge = &it->second; + if (ge->id == geId) + return ge->tokenContainer; + } + return NULL; +} + +skindesignerapi::cTokenContainer *skindesignerapi::cPluginStructure::GetTokenContainerTab(int viewId) { + map::iterator hit = viewtabs.find(viewId); + if (hit == viewtabs.end()) + return NULL; + return hit->second; +} diff --git a/libskindesignerapi/pluginstructure.h b/libskindesignerapi/pluginstructure.h index f4ba281..17a6971 100644 --- a/libskindesignerapi/pluginstructure.h +++ b/libskindesignerapi/pluginstructure.h @@ -1,57 +1,57 @@ -#ifndef __PLUGINSTRUCTURE_H -#define __PLUGINSTRUCTURE_H - -#include "tokencontainer.h" - -namespace skindesignerapi { - -struct sPlugMenu { - int type; - string tplname; - cTokenContainer *tokenContainer; -}; - -struct sPlugViewElement { - int id; - int viewId; - string name; - cTokenContainer *tokenContainer; -}; - -struct sPlugViewGrid { - int id; - int viewId; - string name; - cTokenContainer *tokenContainer; -}; - -class cPluginStructure { -public: - cPluginStructure(void); - ~cPluginStructure(void); - void RegisterMenu(int key, int type, string tpl, cTokenContainer *tk); - cTokenContainer *GetMenuTokenContainer(int key); - void RegisterRootView(string templateName); - void RegisterSubView(int subView, string templateName); - void RegisterViewElement(int view, int viewElement, string name, cTokenContainer *tk); - void RegisterViewGrid(int view, int viewGrid, string name, cTokenContainer *tk); - void RegisterViewTab(int view, cTokenContainer *tk); - cTokenContainer *GetTokenContainerVE(int viewId, int veId); - cTokenContainer *GetTokenContainerGE(int viewId, int geId); - cTokenContainer *GetTokenContainerTab(int viewId); - string name; //name of plugin - string libskindesignerAPIVersion; //skindesigner API Version plugin is using - int id; //id of plugin in skindesigner - //basic plugin interface - map< int, sPlugMenu > menus; //menus as key -> sPlugMenu struct hashmap - //advanced plugin interface - string rootview; //template name of root view - map< int, string > subviews; //subviews as subviewid -> template name map - multimap< int, sPlugViewElement > viewelements; //viewelements as viewid -> sPlugViewElement struct multimap - multimap< int, sPlugViewGrid > viewgrids; //viewgrids as viewid -> sPlugViewGrid struct hashmap - map< int, cTokenContainer* > viewtabs; //viewtabs as viewid -> tokencontainer hashmap -}; - - -} +#ifndef __PLUGINSTRUCTURE_H +#define __PLUGINSTRUCTURE_H + +#include "tokencontainer.h" + +namespace skindesignerapi { + +struct sPlugMenu { + int type; + string tplname; + cTokenContainer *tokenContainer; +}; + +struct sPlugViewElement { + int id; + int viewId; + string name; + cTokenContainer *tokenContainer; +}; + +struct sPlugViewGrid { + int id; + int viewId; + string name; + cTokenContainer *tokenContainer; +}; + +class cPluginStructure { +public: + cPluginStructure(void); + ~cPluginStructure(void); + void RegisterMenu(int key, int type, string tpl, cTokenContainer *tk); + cTokenContainer *GetMenuTokenContainer(int key); + void RegisterRootView(string templateName); + void RegisterSubView(int subView, string templateName); + void RegisterViewElement(int view, int viewElement, string name, cTokenContainer *tk); + void RegisterViewGrid(int view, int viewGrid, string name, cTokenContainer *tk); + void RegisterViewTab(int view, cTokenContainer *tk); + cTokenContainer *GetTokenContainerVE(int viewId, int veId); + cTokenContainer *GetTokenContainerGE(int viewId, int geId); + cTokenContainer *GetTokenContainerTab(int viewId); + string name; //name of plugin + string libskindesignerAPIVersion; //skindesigner API Version plugin is using + int id; //id of plugin in skindesigner + //basic plugin interface + map< int, sPlugMenu > menus; //menus as key -> sPlugMenu struct hashmap + //advanced plugin interface + string rootview; //template name of root view + map< int, string > subviews; //subviews as subviewid -> template name map + multimap< int, sPlugViewElement > viewelements; //viewelements as viewid -> sPlugViewElement struct multimap + multimap< int, sPlugViewGrid > viewgrids; //viewgrids as viewid -> sPlugViewGrid struct hashmap + map< int, cTokenContainer* > viewtabs; //viewtabs as viewid -> tokencontainer hashmap +}; + + +} #endif //__PLUGINSTRUCTURE_H \ No newline at end of file diff --git a/libskindesignerapi/tokencontainer.c b/libskindesignerapi/tokencontainer.c index 00df1f2..257d0a4 100644 --- a/libskindesignerapi/tokencontainer.c +++ b/libskindesignerapi/tokencontainer.c @@ -1,305 +1,305 @@ -#include "tokencontainer.h" - -skindesignerapi::cTokenContainer::cTokenContainer(void) { - numIntTokens = 0; - numStringTokens = 0; - stringTokens = NULL; - intTokens = NULL; - stNames = NULL; - itNames = NULL; -} - -skindesignerapi::cTokenContainer::cTokenContainer(const cTokenContainer &other) { - numIntTokens = 0; - numStringTokens = 0; - stringTokens = NULL; - intTokens = NULL; - stNames = NULL; - itNames = NULL; - stringTokenNames = other.stringTokenNames; - intTokenNames = other.intTokenNames; - loopTokenNames = other.loopTokenNames; - loopNameMapping = other.loopNameMapping; -} - -skindesignerapi::cTokenContainer::~cTokenContainer(void) { - Clear(); - delete[] intTokens; - delete[] stringTokens; - delete[] stNames; - delete[] itNames; -} - -void skindesignerapi::cTokenContainer::CreateContainers(void) { - numIntTokens = intTokenNames.size(); - if (numIntTokens) { - intTokens = new int[numIntTokens]; - itNames = new string[numIntTokens]; - for (int i=0; i < numIntTokens; i++) { - intTokens[i] = -1; - itNames[i] = GetIntTokenName(i); - } - } - numStringTokens = stringTokenNames.size(); - if (numStringTokens) { - stringTokens = new char*[numStringTokens]; - stNames = new string[numStringTokens]; - for (int i=0; i < numStringTokens; i++) { - stringTokens[i] = NULL; - stNames[i] = GetStringTokenName(i); - } - } - - int numLoops = loopTokenNames.size(); - for (int i = 0; i < numLoops; ++i) { - vector loopToken; - int numLoopTokens = loopTokenNames[i].size(); - for (int j = 0; j < numLoopTokens; ++j) { - string tokenName = GetLoopTokenName(i, j); - loopToken.push_back(tokenName); - } - ltNames.push_back(loopToken); - } -} - -void skindesignerapi::cTokenContainer::CreateLoopTokenContainer(vector *loopInfo) { - int numLoops = loopInfo->size(); - for (int i = 0; i < numLoops; ++i) { - numLoopTokens.push_back(loopInfo->at(i)); - int rows = loopInfo->at(i); - char*** loopToks = new char**[rows]; - for (int j = 0; j < rows ; ++j) { - int numLoopTokens = loopTokenNames[i].size(); - loopToks[j] = new char*[numLoopTokens]; - for (int k = 0; k < numLoopTokens; ++k) { - loopToks[j][k] = NULL; - } - } - loopTokens.push_back(loopToks); - } -} - -void skindesignerapi::cTokenContainer::DeleteLoopTokenContainer(void) { - int i = 0; - for (vector::iterator it = loopTokens.begin(); it != loopTokens.end(); it++) { - char*** loopToks = *it; - for (int j = 0; j < numLoopTokens[i] ; j++) { - int numToks = loopTokenNames[i].size(); - for (int k = 0; k < numToks; ++k) { - free(loopToks[j][k]); - } - delete[] loopToks[j]; - } - delete[] loopToks; - ++i; - } - loopTokens.clear(); - numLoopTokens.clear(); -} - -void skindesignerapi::cTokenContainer::DefineStringToken(string name, int index) { - stringTokenNames.insert(pair(name, index)); -} - -void skindesignerapi::cTokenContainer::DefineIntToken(string name, int index) { - intTokenNames.insert(pair(name, index)); -} - -void skindesignerapi::cTokenContainer::DefineLoopToken(string name, int index) { - string loopName = LoopName(name); - int loopIndex = LoopIndex(loopName, true); - if ((int)loopTokenNames.size() < loopIndex+1) { - map newloop; - newloop.insert(pair(name, index)); - loopTokenNames.push_back(newloop); - return; - } - loopTokenNames[loopIndex].insert(pair(name, index)); -} - -int skindesignerapi::cTokenContainer::GetNumDefinedIntTokens(void) { - return intTokenNames.size(); -} - -int skindesignerapi::cTokenContainer::LoopIndex(string name, bool createNew) { - map::iterator hit = loopNameMapping.find(name); - if (hit != loopNameMapping.end()) - return hit->second; - if (!createNew) - return -1; - int index = loopNameMapping.size(); - loopNameMapping.insert(pair(name, index)); - return index; -} - -int skindesignerapi::cTokenContainer::StringTokenIndex(string name) { - map::iterator hit = stringTokenNames.find(name); - if (hit == stringTokenNames.end()) - return -1; - return hit->second; -} - -int skindesignerapi::cTokenContainer::IntTokenIndex(string name) { - map::iterator hit = intTokenNames.find(name); - if (hit == intTokenNames.end()) - return -1; - return hit->second; -} - -int skindesignerapi::cTokenContainer::LoopTokenIndex(string name) { - string loopName = LoopName(name); - int loopIndex = LoopIndex(loopName); - if (loopIndex > -1 && loopIndex < (int)loopTokenNames.size()) { - map::iterator hit = loopTokenNames[loopIndex].find(name); - if (hit == loopTokenNames[loopIndex].end()) - return -1; - return hit->second; - } - return -1; -} - -void skindesignerapi::cTokenContainer::AddIntToken(int index, int value) { - intTokens[index] = value; -} - -void skindesignerapi::cTokenContainer::AddStringToken(int index, const char *value) { - if (value) - stringTokens[index] = strdup(value); -} - -void skindesignerapi::cTokenContainer::AddLoopToken(int loopIndex, int row, int index, const char *value) { - if (value) { - loopTokens[loopIndex][row][index] = strdup(value); - } -} - -int skindesignerapi::cTokenContainer::NumLoops(int loopIndex) { - int numLT = numLoopTokens.size(); - if (loopIndex >= 0 && loopIndex < numLT) - return numLoopTokens[loopIndex]; - return 0; -} - -void skindesignerapi::cTokenContainer::SetTokens(cTokenContainer *other) { - //Set Int and String Tokens - if (numIntTokens) { - for (int i=0; i < numIntTokens; i++) { - AddIntToken(i, other->IntToken(i)); - } - } - if (numStringTokens) { - for (int i=0; i < numStringTokens; i++) { - AddStringToken(i, other->StringToken(i)); - } - } - //Set Looptoken Container - set loopIndices; - for (map::iterator it = loopNameMapping.begin(); it != loopNameMapping.end(); it++) { - loopIndices.insert(it->second); - } - vector loopInfo; - for (set::iterator it = loopIndices.begin(); it != loopIndices.end(); it++) { - loopInfo.push_back(other->NumLoops(*it)); - } - CreateLoopTokenContainer(&loopInfo); - //Set Loop Tokens - int i = 0; - for (vector::iterator it = loopInfo.begin(); it != loopInfo.end(); it++) { - int numRows = *it; - int numCols = loopTokenNames[i].size(); - for (int j = 0; j < numRows; j++) { - for (int k = 0; k < numCols; k++) { - AddLoopToken(i, j, k, other->LoopToken(i, j, k)); - } - } - i++; - } -} - -void skindesignerapi::cTokenContainer::Clear(void) { - if (numIntTokens) { - for (int i=0; i < numIntTokens; i++) { - intTokens[i] = -1; - } - } - if (numStringTokens) { - for (int i=0; i < numStringTokens; i++) { - free(stringTokens[i]); - stringTokens[i] = NULL; - } - } - DeleteLoopTokenContainer(); -} - -void skindesignerapi::cTokenContainer::Debug(void) { - /* - esyslog("skindesigner: TokenContainer defined string tokens"); - for (map::iterator it = stringTokenNames.begin(); it != stringTokenNames.end(); it++) { - esyslog("skindesigner: name %s id %d", (it->first).c_str(), it->second); - } - esyslog("skindesigner: TokenContainer defined int tokens"); - for (map::iterator it = intTokenNames.begin(); it != intTokenNames.end(); it++) { - esyslog("skindesigner: name %s id %d", (it->first).c_str(), it->second); - } - */ - esyslog("skindesigner: TokenContainer content"); - for (int i=0; i < numStringTokens; i++) { - if (stringTokens[i]) - esyslog("skindesigner: stringtoken %d. %s: \"%s\"", i, stNames[i].c_str(), stringTokens[i]); - else - esyslog("skindesigner: stringtoken %d. %s: empty", i, stNames[i].c_str()); - } - for (int i=0; i < numIntTokens; i++) { - if (intTokens[i] >= 0) - esyslog("skindesigner: inttoken %d. %s: %d", i, itNames[i].c_str(), intTokens[i]); - else - esyslog("skindesigner: inttoken %d. %s: empty", i, itNames[i].c_str()); - } - - for (size_t i=0; i < loopTokens.size(); i++) { - for (int j = 0; j < numLoopTokens[i]; j++) { - esyslog("skindesigner: row %d", j); - for (size_t k = 0; k < loopTokenNames[i].size(); k++) { - if (loopTokens[i][j][k]) - esyslog("skindesigner: looptoken %d. %s: \"%s\"", (int)k, ltNames[i][k].c_str(), loopTokens[i][j][k]); - else - esyslog("skindesigner: looptoken %d. %s: empty", (int)k, ltNames[i][k].c_str()); - } - } - } -} - - -string skindesignerapi::cTokenContainer::GetStringTokenName(int id) { - for (map::iterator it = stringTokenNames.begin(); it != stringTokenNames.end(); it++) { - if (it->second == id) - return it->first; - } - return ""; -} -string skindesignerapi::cTokenContainer::GetIntTokenName(int id) { - for (map::iterator it = intTokenNames.begin(); it != intTokenNames.end(); it++) { - if (it->second == id) - return it->first; - } - return ""; -} - -string skindesignerapi::cTokenContainer::GetLoopTokenName(int loop, int id) { - for (map::iterator it = loopTokenNames[loop].begin(); it != loopTokenNames[loop].end(); it++) { - if (it->second == id) - return it->first; - } - return ""; -} - -//Get name of loop from a loop token name -string skindesignerapi::cTokenContainer::LoopName(string &loopToken) { - size_t hit = loopToken.find('{'); - if (hit != 0) - return ""; - hit = loopToken.find('['); - if (hit == string::npos) - return ""; - return loopToken.substr(1, hit-1); -} +#include "tokencontainer.h" + +skindesignerapi::cTokenContainer::cTokenContainer(void) { + numIntTokens = 0; + numStringTokens = 0; + stringTokens = NULL; + intTokens = NULL; + stNames = NULL; + itNames = NULL; +} + +skindesignerapi::cTokenContainer::cTokenContainer(const cTokenContainer &other) { + numIntTokens = 0; + numStringTokens = 0; + stringTokens = NULL; + intTokens = NULL; + stNames = NULL; + itNames = NULL; + stringTokenNames = other.stringTokenNames; + intTokenNames = other.intTokenNames; + loopTokenNames = other.loopTokenNames; + loopNameMapping = other.loopNameMapping; +} + +skindesignerapi::cTokenContainer::~cTokenContainer(void) { + Clear(); + delete[] intTokens; + delete[] stringTokens; + delete[] stNames; + delete[] itNames; +} + +void skindesignerapi::cTokenContainer::CreateContainers(void) { + numIntTokens = intTokenNames.size(); + if (numIntTokens) { + intTokens = new int[numIntTokens]; + itNames = new string[numIntTokens]; + for (int i=0; i < numIntTokens; i++) { + intTokens[i] = -1; + itNames[i] = GetIntTokenName(i); + } + } + numStringTokens = stringTokenNames.size(); + if (numStringTokens) { + stringTokens = new char*[numStringTokens]; + stNames = new string[numStringTokens]; + for (int i=0; i < numStringTokens; i++) { + stringTokens[i] = NULL; + stNames[i] = GetStringTokenName(i); + } + } + + int numLoops = loopTokenNames.size(); + for (int i = 0; i < numLoops; ++i) { + vector loopToken; + int numLoopTokens = loopTokenNames[i].size(); + for (int j = 0; j < numLoopTokens; ++j) { + string tokenName = GetLoopTokenName(i, j); + loopToken.push_back(tokenName); + } + ltNames.push_back(loopToken); + } +} + +void skindesignerapi::cTokenContainer::CreateLoopTokenContainer(vector *loopInfo) { + int numLoops = loopInfo->size(); + for (int i = 0; i < numLoops; ++i) { + numLoopTokens.push_back(loopInfo->at(i)); + int rows = loopInfo->at(i); + char*** loopToks = new char**[rows]; + for (int j = 0; j < rows ; ++j) { + int numLoopTokens = loopTokenNames[i].size(); + loopToks[j] = new char*[numLoopTokens]; + for (int k = 0; k < numLoopTokens; ++k) { + loopToks[j][k] = NULL; + } + } + loopTokens.push_back(loopToks); + } +} + +void skindesignerapi::cTokenContainer::DeleteLoopTokenContainer(void) { + int i = 0; + for (vector::iterator it = loopTokens.begin(); it != loopTokens.end(); it++) { + char*** loopToks = *it; + for (int j = 0; j < numLoopTokens[i] ; j++) { + int numToks = loopTokenNames[i].size(); + for (int k = 0; k < numToks; ++k) { + free(loopToks[j][k]); + } + delete[] loopToks[j]; + } + delete[] loopToks; + ++i; + } + loopTokens.clear(); + numLoopTokens.clear(); +} + +void skindesignerapi::cTokenContainer::DefineStringToken(string name, int index) { + stringTokenNames.insert(pair(name, index)); +} + +void skindesignerapi::cTokenContainer::DefineIntToken(string name, int index) { + intTokenNames.insert(pair(name, index)); +} + +void skindesignerapi::cTokenContainer::DefineLoopToken(string name, int index) { + string loopName = LoopName(name); + int loopIndex = LoopIndex(loopName, true); + if ((int)loopTokenNames.size() < loopIndex+1) { + map newloop; + newloop.insert(pair(name, index)); + loopTokenNames.push_back(newloop); + return; + } + loopTokenNames[loopIndex].insert(pair(name, index)); +} + +int skindesignerapi::cTokenContainer::GetNumDefinedIntTokens(void) { + return intTokenNames.size(); +} + +int skindesignerapi::cTokenContainer::LoopIndex(string name, bool createNew) { + map::iterator hit = loopNameMapping.find(name); + if (hit != loopNameMapping.end()) + return hit->second; + if (!createNew) + return -1; + int index = loopNameMapping.size(); + loopNameMapping.insert(pair(name, index)); + return index; +} + +int skindesignerapi::cTokenContainer::StringTokenIndex(string name) { + map::iterator hit = stringTokenNames.find(name); + if (hit == stringTokenNames.end()) + return -1; + return hit->second; +} + +int skindesignerapi::cTokenContainer::IntTokenIndex(string name) { + map::iterator hit = intTokenNames.find(name); + if (hit == intTokenNames.end()) + return -1; + return hit->second; +} + +int skindesignerapi::cTokenContainer::LoopTokenIndex(string name) { + string loopName = LoopName(name); + int loopIndex = LoopIndex(loopName); + if (loopIndex > -1 && loopIndex < (int)loopTokenNames.size()) { + map::iterator hit = loopTokenNames[loopIndex].find(name); + if (hit == loopTokenNames[loopIndex].end()) + return -1; + return hit->second; + } + return -1; +} + +void skindesignerapi::cTokenContainer::AddIntToken(int index, int value) { + intTokens[index] = value; +} + +void skindesignerapi::cTokenContainer::AddStringToken(int index, const char *value) { + if (value) + stringTokens[index] = strdup(value); +} + +void skindesignerapi::cTokenContainer::AddLoopToken(int loopIndex, int row, int index, const char *value) { + if (value) { + loopTokens[loopIndex][row][index] = strdup(value); + } +} + +int skindesignerapi::cTokenContainer::NumLoops(int loopIndex) { + int numLT = numLoopTokens.size(); + if (loopIndex >= 0 && loopIndex < numLT) + return numLoopTokens[loopIndex]; + return 0; +} + +void skindesignerapi::cTokenContainer::SetTokens(cTokenContainer *other) { + //Set Int and String Tokens + if (numIntTokens) { + for (int i=0; i < numIntTokens; i++) { + AddIntToken(i, other->IntToken(i)); + } + } + if (numStringTokens) { + for (int i=0; i < numStringTokens; i++) { + AddStringToken(i, other->StringToken(i)); + } + } + //Set Looptoken Container + set loopIndices; + for (map::iterator it = loopNameMapping.begin(); it != loopNameMapping.end(); it++) { + loopIndices.insert(it->second); + } + vector loopInfo; + for (set::iterator it = loopIndices.begin(); it != loopIndices.end(); it++) { + loopInfo.push_back(other->NumLoops(*it)); + } + CreateLoopTokenContainer(&loopInfo); + //Set Loop Tokens + int i = 0; + for (vector::iterator it = loopInfo.begin(); it != loopInfo.end(); it++) { + int numRows = *it; + int numCols = loopTokenNames[i].size(); + for (int j = 0; j < numRows; j++) { + for (int k = 0; k < numCols; k++) { + AddLoopToken(i, j, k, other->LoopToken(i, j, k)); + } + } + i++; + } +} + +void skindesignerapi::cTokenContainer::Clear(void) { + if (numIntTokens) { + for (int i=0; i < numIntTokens; i++) { + intTokens[i] = -1; + } + } + if (numStringTokens) { + for (int i=0; i < numStringTokens; i++) { + free(stringTokens[i]); + stringTokens[i] = NULL; + } + } + DeleteLoopTokenContainer(); +} + +void skindesignerapi::cTokenContainer::Debug(void) { + /* + esyslog("skindesigner: TokenContainer defined string tokens"); + for (map::iterator it = stringTokenNames.begin(); it != stringTokenNames.end(); it++) { + esyslog("skindesigner: name %s id %d", (it->first).c_str(), it->second); + } + esyslog("skindesigner: TokenContainer defined int tokens"); + for (map::iterator it = intTokenNames.begin(); it != intTokenNames.end(); it++) { + esyslog("skindesigner: name %s id %d", (it->first).c_str(), it->second); + } + */ + esyslog("skindesigner: TokenContainer content"); + for (int i=0; i < numStringTokens; i++) { + if (stringTokens[i]) + esyslog("skindesigner: stringtoken %d. %s: \"%s\"", i, stNames[i].c_str(), stringTokens[i]); + else + esyslog("skindesigner: stringtoken %d. %s: empty", i, stNames[i].c_str()); + } + for (int i=0; i < numIntTokens; i++) { + if (intTokens[i] >= 0) + esyslog("skindesigner: inttoken %d. %s: %d", i, itNames[i].c_str(), intTokens[i]); + else + esyslog("skindesigner: inttoken %d. %s: empty", i, itNames[i].c_str()); + } + + for (size_t i=0; i < loopTokens.size(); i++) { + for (int j = 0; j < numLoopTokens[i]; j++) { + esyslog("skindesigner: row %d", j); + for (size_t k = 0; k < loopTokenNames[i].size(); k++) { + if (loopTokens[i][j][k]) + esyslog("skindesigner: looptoken %d. %s: \"%s\"", (int)k, ltNames[i][k].c_str(), loopTokens[i][j][k]); + else + esyslog("skindesigner: looptoken %d. %s: empty", (int)k, ltNames[i][k].c_str()); + } + } + } +} + + +string skindesignerapi::cTokenContainer::GetStringTokenName(int id) { + for (map::iterator it = stringTokenNames.begin(); it != stringTokenNames.end(); it++) { + if (it->second == id) + return it->first; + } + return ""; +} +string skindesignerapi::cTokenContainer::GetIntTokenName(int id) { + for (map::iterator it = intTokenNames.begin(); it != intTokenNames.end(); it++) { + if (it->second == id) + return it->first; + } + return ""; +} + +string skindesignerapi::cTokenContainer::GetLoopTokenName(int loop, int id) { + for (map::iterator it = loopTokenNames[loop].begin(); it != loopTokenNames[loop].end(); it++) { + if (it->second == id) + return it->first; + } + return ""; +} + +//Get name of loop from a loop token name +string skindesignerapi::cTokenContainer::LoopName(string &loopToken) { + size_t hit = loopToken.find('{'); + if (hit != 0) + return ""; + hit = loopToken.find('['); + if (hit == string::npos) + return ""; + return loopToken.substr(1, hit-1); +} diff --git a/libskindesignerapi/tokencontainer.h b/libskindesignerapi/tokencontainer.h index 86d8652..b832da6 100644 --- a/libskindesignerapi/tokencontainer.h +++ b/libskindesignerapi/tokencontainer.h @@ -1,69 +1,69 @@ -#ifndef __TOKENCONTAINER_H -#define __TOKENCONTAINER_H - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -namespace skindesignerapi { - -class cTokenContainer { -private: - int numIntTokens; - int numStringTokens; - vector numLoopTokens; - //token containers - char **stringTokens; - int *intTokens; - vectorloopTokens; - //mapping id --> name - string *stNames; - string *itNames; - vector< vector > ltNames; - //mapping name --> id - map stringTokenNames; - map intTokenNames; - vector< map > loopTokenNames; - //get token name from id - string GetStringTokenName(int id); - string GetIntTokenName(int id); - string GetLoopTokenName(int loop, int id); - //looptoken management - string LoopName(string &loopToken); - map loopNameMapping; - void DeleteLoopTokenContainer(void); -public: - cTokenContainer(void); - cTokenContainer(const cTokenContainer &other); - ~cTokenContainer(void); - void CreateContainers(void); - void CreateLoopTokenContainer(vector *loopInfo); - void DefineStringToken (string name, int index); - void DefineIntToken (string name, int index); - void DefineLoopToken (string name, int index); - int GetNumDefinedIntTokens(void); - int LoopIndex (string name, bool createNew = false); - int StringTokenIndex (string name); - int IntTokenIndex (string name); - int LoopTokenIndex (string name); - void AddIntToken (int index, int value); - void AddStringToken (int index, const char *value); - void AddLoopToken (int loopIndex, int row, int index, const char *value); - char *StringToken (int index) { return stringTokens[index]; }; - int IntToken (int index) { return intTokens[index]; }; - char *LoopToken (int i, int j, int k) { return loopTokens[i][j][k]; }; - int NumLoops (int loopIndex); - void SetTokens (cTokenContainer *other); - void Clear(void); - void Debug(void); -}; - -} +#ifndef __TOKENCONTAINER_H +#define __TOKENCONTAINER_H + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace skindesignerapi { + +class cTokenContainer { +private: + int numIntTokens; + int numStringTokens; + vector numLoopTokens; + //token containers + char **stringTokens; + int *intTokens; + vectorloopTokens; + //mapping id --> name + string *stNames; + string *itNames; + vector< vector > ltNames; + //mapping name --> id + map stringTokenNames; + map intTokenNames; + vector< map > loopTokenNames; + //get token name from id + string GetStringTokenName(int id); + string GetIntTokenName(int id); + string GetLoopTokenName(int loop, int id); + //looptoken management + string LoopName(string &loopToken); + map loopNameMapping; + void DeleteLoopTokenContainer(void); +public: + cTokenContainer(void); + cTokenContainer(const cTokenContainer &other); + ~cTokenContainer(void); + void CreateContainers(void); + void CreateLoopTokenContainer(vector *loopInfo); + void DefineStringToken (string name, int index); + void DefineIntToken (string name, int index); + void DefineLoopToken (string name, int index); + int GetNumDefinedIntTokens(void); + int LoopIndex (string name, bool createNew = false); + int StringTokenIndex (string name); + int IntTokenIndex (string name); + int LoopTokenIndex (string name); + void AddIntToken (int index, int value); + void AddStringToken (int index, const char *value); + void AddLoopToken (int loopIndex, int row, int index, const char *value); + char *StringToken (int index) { return stringTokens[index]; }; + int IntToken (int index) { return intTokens[index]; }; + char *LoopToken (int i, int j, int k) { return loopTokens[i][j][k]; }; + int NumLoops (int loopIndex); + void SetTokens (cTokenContainer *other); + void Clear(void); + void Debug(void); +}; + +} #endif //__TOKENCONTAINER_H \ No newline at end of file -- cgit v1.2.3