long CObjectManager::loadObjectTable() { char * path = "Data/Objects/ObjectTable.dat"; std::fstream objectTable; objectTable.open(path, std::ios::in); struct entry { long type; char* path; }; entry curEntry; std::string etype; std::string epath; while (!objectTable.eof()) { if (objectTable.get() == '{') { char* tmp = (char*)malloc(1024); objectTable.getline(tmp, 1024); int counter = 0; for (int it = 0; tmp[it] != ';' && tmp[it] != '}'; ++it) { if (tmp[it] == ' ') { continue; } etype.push_back(tmp[it]); counter = it; } for (int it = counter + 2; tmp[it] != ';' && tmp[it] != '}'; ++it) { if (tmp[it] == ' ') { continue; } epath.push_back(tmp[it]); } curEntry.type = getTypeFromString(etype.c_str()); curEntry.path = const_cast<char*>(epath.c_str()); CObject* obj; switch (curEntry.type) { case EMaterial: { CMaterial mat = loadMatFromFile(curEntry.path); obj = new CMaterial(mat.getName(), mat.getTexture(), mat.getCollision(), mat.getWalkspeed()); obj->registerObj(mat.getName()); m_ObjectMap.insert(std::pair<std::string, CObject*>(obj->getID(), obj)); }break; } etype.clear(); epath.clear(); } } objectTable.close(); return 0; }
/* Constructor for declaration syntax node. */ SyntaxNode* makeDeclaration(char *name, char *type) { SyntaxNode *newNode; newNode = make(DECLARATION); if(getsym(name) != 0) { fprintf(stderr, "Error: %s declared previously.\n", name); exit(1); } symRecord *sr; // NOTE: putsym creates the memory block for the new record DataType dataType = getTypeFromString(type); sr = putsym(name, dataType); newNode->dataType = dataType; newNode->record = sr; return newNode; }
//Note: This starts from the beginning of the string only. int ALexer::findTypeEndPos(std::string input, std::vector<int> typeWhitelist) { for (int i = 0; i < (int)input.size(); i++) { std::string curChar = input.substr(i, 1); //Check if the curChar matches anything in the whitelist. bool match = false; for (int k = 0; k < (int)typeWhitelist.size(); k++) { if (getTypeFromString(curChar) == typeWhitelist[k]) { match = true; } } if (!match) { //If it does not match, this is the endpoint. return i; } } return (int)input.size(); }
void doSet(void *target, const Ogre::String &val) { GravityAffector *self = static_cast<GravityAffector*>(target); self->setForceType(getTypeFromString(val)); }
std::vector<AToken> ALexer::tokenize(std::string input) { std::vector<AToken> tokens; AToken curToken; while (input.size() > 0) { std::string curChar = input.substr(0, 1); int curType = getTypeFromString(curChar); //Set the type of the current token if it is blank/null. if (curToken.getType() == TOKEN_NULL) { curToken.setType(curType); } //If the curToken is a number, try to find the whole number. Delimiters are any non-number token. if (curToken.getType() == TOKEN_NUMBER) { std::string sub = getSubstrOfType(input, { TOKEN_NUMBER }); curToken.setStr(sub); input.erase(0, sub.length()); tokens.push_back(curToken); curToken.reset(); } //If the curToken is a letter, try to find whether or not it is a constant, function, or a user-definable variable in that priority. Letters and numbers are included. Delimiters are everything else. else if (curToken.getType() == TOKEN_LETTER) { std::string sub = getSubstrOfType(input, { TOKEN_LETTER, TOKEN_NUMBER } ); curToken.setStr(sub); if (curToken.getType() == TOKEN_LETTER) { std::vector<std::string> constVec = stringmap[TOKEN_CONSTANT]; for (int i = 0; i < (int)constVec.size(); i++) { if (sub == constVec[i]) { curToken.setType(TOKEN_CONSTANT); break; } } } if (curToken.getType() == TOKEN_LETTER) { std::vector<std::string> funcVec = stringmap[TOKEN_FUNCTION]; for (int i = 0; i < (int)funcVec.size(); i++) { if (sub == funcVec[i]) { curToken.setType(TOKEN_FUNCTION); break; } } } if (curToken.getType() == TOKEN_LETTER) { curToken.setType(TOKEN_VARIABLE); } input.erase(0, sub.length()); tokens.push_back(curToken); curToken.reset(); } else if (curToken.getType() == TOKEN_OPERATOR || TOKEN_LEFT_PAREN || TOKEN_RIGHT_PAREN) { curToken.setStr(curChar); input.erase(0, 1); tokens.push_back(curToken); curToken.reset(); } } return tokens; }