SOSpin is hosted by Hepforge, IPPP Durham
SOSpin  1.0.0
index.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // SOSpin Library
3 // Copyright (C) 2015 SOSpin Project
4 //
5 // Authors:
6 //
7 // Nuno Cardoso (nuno.cardoso@tecnico.ulisboa.pt)
8 // David Emmanuel-Costa (david.costa@tecnico.ulisboa.pt)
9 // Nuno Gonçalves (nunogon@deec.uc.pt)
10 // Catarina Simoes (csimoes@ulg.ac.be)
11 //
12 // ----------------------------------------------------------------------------
13 // This file is part of SOSpin Library.
14 //
15 // SOSpin Library is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or any
18 // later version.
19 //
20 // SOSpin Library is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with SOSpin Library. If not, see <http://www.gnu.org/licenses/>.
27 // ----------------------------------------------------------------------------
28 
29 // index.cpp created on 27/02/2015
30 //
31 // This file contains the functions necessary to do things
32 // in the SOSpin Library.
33 //
34 // Revision 1.1 28/02/2015 23:19:29 david
35 // License updated
36 //
37 
44 #include "index.h"
45 #include <iostream>
46 
47 
48 
49 using namespace std;
50 
51 
52 
53 
54 namespace sospin {
55 
59 vector<string> tabids;
61 
62 int Idx_size(){
63  return tabids.size();
64 }
65 
66 
67 string makeId(string a, int id){
68 
69  newId(a+ToString<int>(id));
70  return a+ToString<int>(id);
71 }
72 
73 void printIDX(){
74  cout << "================================================================" << endl;
75  for(int j=0; j < tabids.size(); j++){
76  cout << tabids.at(j);
77  if(j < tabids.size()-1) cout << ",";
78  }
79  cout << "\n================================================================" << endl;
80 }
81 
82 
86 int newIdx(int i){
87  //tabids.push_back( ToString<int>(i) );
88  //return tabids.size()-1;
89  string addidx = ToString<int>(i);
90  int pos=-1;
91  for(int j=0; j < tabids.size(); j++){
92  if(addidx==tabids.at(j)){
93  pos = j;
94  break;
95  }
96  }
97  if(pos==-1){
98  tabids.push_back( addidx );
99  pos = tabids.size()-1;
100  }
101  return pos;
102 }
106 int newIdx(string i){
107  //tabids.push_back(i);
108  //return tabids.size()-1;
109  int pos=-1;
110  for(int j=0; j < tabids.size(); j++){
111  if(i==tabids.at(j)){
112  pos = j;
113  break;
114  }
115  }
116  if(pos==-1){
117  tabids.push_back( i );
118  pos = tabids.size()-1;
119  }
120  return pos;
121 }
125 void newId(string i){
126  //tabids.push_back(i);
127  int pos=-1;
128  for(int j=0; j < tabids.size(); j++){
129  if(i==tabids.at(j)){
130  pos = j;
131  break;
132  }
133  }
134  if(pos==-1)
135  tabids.push_back( i );
136 }
142 string getIdx(int i){
143  return tabids.at(i);
144 }
145 
150 string IndexList(){
151  vector<string> indexlist;
152  indexlist = tabids;
153  vector<string>::iterator it;
154  sort (indexlist.begin(), indexlist.end());
155  it = unique (indexlist.begin(), indexlist.end());
156  indexlist.resize( it - indexlist.begin() );
157 
158  //string idx="Indices ";
159  string idx="";
160  for(int i=0; i<indexlist.size(); i++){
161  //check for numeric indexes and remove them...
162  std::istringstream iss(indexlist.at(i));
163  int num = 0;
164  if (!(iss >> num).fail()) continue;
165  idx += indexlist.at(i);
166  if(i!=indexlist.size()-1)
167  idx += ", ";
168  else
169  idx += ";";
170  }
171  indexlist.clear();
172  return idx;
173 }
174 
178 template<class T>
179 string ToString(T number)
180 {
181  stringstream ss;//create a stringstream
182  ss << number;//add number to the stream
183  return ss.str();//return a string with the contents of the stream
184 }
185 
186 template string ToString<int>(int number);
187 template string ToString<unsigned int>(unsigned int number);
188 template string ToString<float>(float number);
189 template string ToString<double>(double number);
190 
191 }
int newIdx(string i)
Store new index of type "string".
Definition: index.cpp:106
Functions and cointainer for indices.
template string ToString< double >(double number)
template string ToString< int >(int number)
string ToString(T number)
convert to string
Definition: index.cpp:179
string getIdx(int i)
Get index.
Definition: index.cpp:142
string makeId(string a, int id)
return in string format "a+id"
Definition: index.cpp:67
vector< string > tabids
Vector container of the indexes.
Definition: index.cpp:59
void newId(string i)
Store new index of type "string".
Definition: index.cpp:125
void printIDX()
print index list.
Definition: index.cpp:73
template string ToString< float >(float number)
int Idx_size()
Return index list size.
Definition: index.cpp:62
string IndexList()
Index list.
Definition: index.cpp:150
template string ToString< unsigned int >(unsigned int number)