[go: up one dir, main page]

Menu

[23694a]: / src / cTS.cpp  Maximize  Restore  History

Download this file

129 lines (114 with data), 2.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* (c) Martin 'dum8d0g' Kopta <martin@kopta.eu>
* Dec, 2008
* cTS.cpp
* Tabulka symbolu (promenych, typy a id, labely)
____________________________ ________________________
|Tabulka A | | Tabulka B |
+-----------------+--------+ +---------+------------+
|string identname | int id | | int id | string typ |
+-----------------+--------+ +---------+------------+
| pi | 0 <-----> 0 | float |
| size | 1 | | 1 | int |
| delta | 2 | | 2 | float |
| ... | . | | . | ... |
| ... | . | | . | ... |
+-----------------+--------+ +---------+------------+
( std::map<string, int> ) ( std::map<int, string> )
*/
#include <iostream>
#include <map>
#include <list>
#include <utility> // make_pair
#include "cTS.h"
using namespace std;
cTS::cTS ( )
{
this->lastID = -1;
this->lastLAB = -1;
A.clear ( );
B.clear ( );
}
int cTS::getNextLab ( )
{
return ++lastLAB;
}
bool cTS::jeDeklarovan ( string identname )
{
map <string, int>::iterator iter;
iter = A.find ( identname );
return ( iter != A.end() ); // true if is declared
}
void cTS::add ( string identname, string typ )
{
int id = ++lastID;
if ( typ == "float" ) lastID++; // float potrebuje dva registry
A.insert ( make_pair ( identname , id ) ) ;
B.insert ( make_pair ( id , typ ) ) ;
}
int cTS::getID ( string identname )
{
map <string, int>::iterator iter;
iter = A.find ( identname );
if ( iter != A.end() )
{
return iter->second;
}
else
{
return -1;
}
}
string cTS::getTyp ( string identname )
{
map <string, int>::iterator iterA;
map <int, string>::iterator iterB;
iterA = A.find ( identname );
if ( iterA != A.end() )
{
int id = iterA->second;
iterB = B.find ( id );
if ( iterB != B.end() )
{
return iterB->second;
}
else
{
// FIXME -- MORE FATAL ERROR
return "";
}
}
else
{
// FIXME -- FATAL ERROR
return "";
}
}
string cTS::getIdentname ( int ID )
{
map <string, int>::iterator iterA;
// Pruchod tabulkou A
for( map<string, int>::const_iterator it = A.begin(); it != A.end(); ++it )
{
if ( it->second == ID )
{
return it->first;
}
}
return ""; // FIXME, ERROR
}
int cTS::getPocetProm ( )
{
return this->lastID;
}
list<int> cTS::getIDpromennych ( )
{
map <string, int>::iterator iterA;
list <int> IDs;
// Pruchod tabulkou A
for( map<string, int>::const_iterator it = A.begin(); it != A.end(); ++it )
{
IDs.push_back( it->second );
}
return IDs;
}
/* EOF */