source: icGREP/icgrep-devel/icgrep/pablo/symbol_generator.cpp @ 4543

Last change on this file since 4543 was 4510, checked in by nmedfort, 5 years ago

Many memory deallocation fixes.

File size: 1.5 KB
RevLine 
[3850]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
[4210]7#include <pablo/symbol_generator.h>
[4214]8#include <pablo/pe_string.h>
[4416]9#include <pablo/pe_integer.h>
[3850]10
[4210]11namespace pablo {
[3850]12
[4197]13SymbolGenerator::SymbolGenerator()
[4214]14: mPrefixMap()
[3850]15{
[4252]16
[4197]17}
[3850]18
[4433]19String * SymbolGenerator::get(const std::string name, const bool generated) {
[4252]20    auto f = mStringMap.find(name);
21    String * result;
22    if (f == mStringMap.end()) {
[4510]23        result = new String(name, generated);
24        mStringMap.insert(std::make_pair(std::move(name), result));
[4252]25    }
26    else {
27        result = f->second;
28    }
29    return result;
30}
31
[4432]32Integer * SymbolGenerator::getInteger(const integer_t value) {
[4416]33    auto f = mIntegerMap.find(value);
34    Integer * result;
35    if (f == mIntegerMap.end()) {
36        result = new Integer(value);
[4432]37        assert (result->value() == value);
[4416]38        mIntegerMap.insert(std::make_pair(value, result));
39    }
40    else {
41        result = f->second;
42    }
43    return result;
44}
45
[4433]46String * SymbolGenerator::make(const std::string prefix, const bool generated) {
[4214]47    auto f = mPrefixMap.find(prefix);
[4197]48    unsigned count = 0;
[4214]49    if (f == mPrefixMap.end()) {
50        mPrefixMap.insert(std::make_pair(prefix, 1));
[4433]51        return get(prefix, generated);
[3850]52    }
[4197]53    else {
54        count = f->second++;
[4433]55        return get(prefix + std::to_string(count), generated);
[3850]56    }
57}
[4197]58
[4432]59SymbolGenerator::~SymbolGenerator() {
[4510]60
[4432]61}
[4214]62
63}
Note: See TracBrowser for help on using the repository browser.