void CEditEffectGroup::ReNameGroup(string strOld,string strNew) { EMap< EString, CEffectProp* >::iterator iter = m_EffectProps.begin(); EMap< EString, CEffectProp* > mapTemp; EString strTemp = strOld.c_str(); strTemp = strTemp + "\\"; EString strReplace = strNew.c_str(); strReplace = strReplace + "\\"; for (;iter != m_EffectProps.end();) { EString str = iter->first.c_str(); int pos = str.find(strTemp); if (pos != -1) { int linePos = str.find("\\"); linePos+=1; str = str.substr(linePos,str.size()-linePos); str.insert(pos,strReplace); mapTemp.insert(make_pair(str,iter->second)); m_EffectProps.erase(iter++); continue; } else iter++; } for (EMap< EString, CEffectProp* >::iterator iter = mapTemp.begin();iter != mapTemp.end();++iter) { m_EffectProps[iter->first] = iter->second; } }
static E from_string( const std::string &value ) { const auto iter = BINDINGS.find( value ); if( iter == BINDINGS.end() ) { // This point shall not be reached. Always call this with valid input. return BINDINGS.begin()->second; } return iter->second; }
static int index( lua_State * const L ) { // -1 is the key (funtion to call) const char * const key = lua_tostring( L, -1 ); if( key == nullptr ) { luaL_error( L, "Invalid input to __index: key is not a string." ); } const auto iter = BINDINGS.find( key ); if( iter == BINDINGS.end() ) { return luaL_error( L, "Invalid enum value." ); } lua_remove( L, -1 ); // remove key // Push the enum as string, it will be converted back to the enum later. This way, it can // be specified both ways in Lua code: either as string or via an entry here. lua_pushlstring( L, iter->first.c_str(), iter->first.length() ); return 1; }
//---------------------------------------------------------------------------- void ExtractCurveTris::MakeUnique (std::vector<Vector2f>& vertices, std::vector<EdgeKey>& edges) { int numVertices = (int)vertices.size(); if (numVertices == 0) { return; } // Use maps to generate unique storage. typedef std::map<Vector2f, int> VMap; typedef std::map<Vector2f, int>::iterator VIterator; VMap vertexMap; for (int v = 0, nextVertex = 0; v < numVertices; ++v) { std::pair<VIterator, bool> result = vertexMap.insert( std::make_pair(vertices[v], nextVertex)); if (result.second == true) { ++nextVertex; } } typedef std::map<EdgeKey, int> EMap; typedef std::map<EdgeKey, int>::iterator EIterator; EMap* edgeMap = 0; int e; VIterator vIter; int numEdges = (int)edges.size(); if (numEdges) { edgeMap = new0 EMap(); int nextEdge = 0; for (e = 0; e < numEdges; ++e) { // Replace old vertex indices by new ones. vIter = vertexMap.find(vertices[edges[e].V[0]]); assertion(vIter != vertexMap.end(), "Unexpected condition\n"); edges[e].V[0] = vIter->second; vIter = vertexMap.find(vertices[edges[e].V[1]]); assertion(vIter != vertexMap.end(), "Unexpected condition\n"); edges[e].V[1] = vIter->second; // Keep only unique edges. std::pair<EIterator, bool> result = edgeMap->insert( std::make_pair(edges[e], nextEdge)); if (result.second == true) { ++nextEdge; } } } // Pack the vertices into an array. numVertices = (int)vertexMap.size(); vertices.resize(numVertices); for (vIter = vertexMap.begin(); vIter != vertexMap.end(); ++vIter) { vertices[vIter->second] = vIter->first; } // Pack the edges into an array. if (numEdges > 0) { numEdges = (int)edgeMap->size(); edges.resize(numEdges); EIterator eIter; for (eIter = edgeMap->begin(); eIter != edgeMap->end(); ++eIter) { edges[eIter->second] = eIter->first; } delete0(edgeMap); } else { edges.clear(); } }