source: icGREP/icgrep-devel/icgrep/symbol_generator.cpp @ 4133

Last change on this file since 4133 was 3984, checked in by cameron, 5 years ago

Eliminate INT2STRING in favor of std::to_string

File size: 1.0 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "symbol_generator.h"
8
9SymbolGenerator::SymbolGenerator(){
10        pfxmap = new std::map<std::string, int>();
11        //std::cout << "pfxmap initialized" << std::endl;
12}
13
14std::string SymbolGenerator::gensym(std::string prefix)
15{
16
17    std::pair<std::map<std::string, int>::iterator, bool> ret = pfxmap->insert(make_pair(prefix, 0));
18    std::string sym;
19    if (ret.second)
20    {
21        //The insertion succeeded
22        sym = prefix + std::to_string(0);
23        //std::cout << sym << " created" << std::endl;
24        return sym;
25    }
26    else
27    {
28        //The insertion failed so we know that the prefix has already been added.
29        std::map<std::string, int>::iterator iter = pfxmap->find(prefix);
30        iter->second++;
31
32        sym = prefix + std::to_string(iter->second);
33        //std::cout << sym << " created" << std::endl;
34        return sym;
35       
36    }
37}
Note: See TracBrowser for help on using the repository browser.