I am unable to translate correctly this piece of C++ code to PB,
because of my lack of undesrtanding of the syntax being use in:
"map class", the ".end" method, the "vertices.begin"/"vertices.end", and the "make_pair".
Note: In my PB translation m_vertexCache() is a global array of long,
and to retrieve the iter value, i am using the PB syntax "ARRAY SCAN gnm_vertexCache(), = nHash, TO nIter"
Any help would be much appreciated.
because of my lack of undesrtanding of the syntax being use in:
"map class", the ".end" method, the "vertices.begin"/"vertices.end", and the "make_pair".
Note: In my PB translation m_vertexCache() is a global array of long,
and to retrieve the iter value, i am using the PB syntax "ARRAY SCAN gnm_vertexCache(), = nHash, TO nIter"
Any help would be much appreciated.
Code:
int ModelOBJ::addVertex(int hash, const Vertex *pVertex) { int index = -1; std::map<int, std::vector<int> >::const_iterator iter = m_vertexCache.find(hash); if (iter == m_vertexCache.end()) { // Vertex hash doesn't exist in the cache. index = static_cast<int>(m_vertexBuffer.size()); m_vertexBuffer.push_back(*pVertex); m_vertexCache.insert(std::make_pair(hash, std::vector<int>(1, index))); } else { // One or more vertices have been hashed to this entry in the cache. const std::vector<int> &vertices = iter->second; const Vertex *pCachedVertex = 0; bool found = false; for (std::vector<int>::const_iterator i = vertices.begin(); i != vertices.end(); ++i) { index = *i; pCachedVertex = &m_vertexBuffer[index]; if (memcmp(pCachedVertex, pVertex, sizeof(Vertex)) == 0) { found = true; break; } } if (!found) { index = static_cast<int>(m_vertexBuffer.size()); m_vertexBuffer.push_back(*pVertex); m_vertexCache[hash].push_back(index); } } return index; }
Comment