SemOpt  0.2alpha5-SCC
SetArguments.cpp
Go to the documentation of this file.
1 
9 #include "SetArguments.h"
10 
15 {
16  this->arguments = map<string, Argument *>();
17  this->key_assoc = map<int, string>();
18 }
19 
25 {
26  this->arguments.insert(pair<string, Argument *>(arg->getName(), arg));
27  this->key_assoc.insert(pair<int, string>(arg->getNumber(), arg->getName()));
28 }
29 
35 {
36  return (int) this->arguments.size();
37 }
38 
45 {
46  return this->arguments.at(name);
47 }
48 
55 {
56  return this->arguments.at(this->key_assoc.at(num));
57 }
58 
64 {
65  return this->arguments.empty();
66 }
67 
73 {
74  return SetArgumentsIterator((this->arguments.begin()));
75 }
76 
82 {
83  return SetArgumentsIterator(this->arguments.end());
84 }
85 
92 {
93  if (this->empty() && other->empty())
94  return true;
95  if (this->empty() && !other->empty())
96  return true;
97  if (!this->empty() && other->empty())
98  return false;
99  if (this->cardinality() > other->cardinality())
100  return false;
101  for (SetArgumentsIterator it = this->begin(); it != this->end(); it++)
102  {
103  if (!other->exists((*it)))
104  return false;
105  }
106  return true;
107 }
108 
115 {
116  if ((this->cardinality() < other->cardinality()) &&
117  this->is_subset_equal(other))
118  return true;
119  else
120  return false;
121 }
122 
130 {
131  this->clone(result);
132  for (SetArgumentsIterator it = other->begin(); it != other->end(); it++)
133  {
134  if (result->exists((*it)))
135  result->remove((*it));
136  }
137 }
138 
145 {
146  return (this->arguments.find(arg->getName()) != this->arguments.end());
147 }
148 
155 {
156  this->arguments.erase(arg->getName());
157 }
158 
165 {
166  for (SetArgumentsIterator it = this->begin(); it != this->end(); it++)
167  {
168  set->add_Argument((*it));
169  }
170 }
171 
179 {
180  for (SetArgumentsIterator it = this->begin(); it != this->end(); it++)
181  {
182  for (SetArgumentsIterator inner = other->begin(); inner != other->end();
183  inner++)
184  {
185  if (*(*it) == *(*inner))
186  {
187  res->add_Argument(*it);
188  }
189  }
190  }
191 }
192 
198 bool SetArguments::operator==(const SetArguments &other) const
199 {
200  if (this->cardinality() != other.cardinality())
201  return false;
202  for(SetArgumentsIterator it = this->begin(), it2 = other.begin(); it != this->end() and it2 != other.begin(); it++, it2++)
203  {
204  if ((*it) != (*it2))
205  return false;
206  }
207  return true;
208 }
209 
210 SetArguments::~SetArguments()
211 {
212  // TODO Auto-generated destructor stub
213 }
214 
215 ostream& operator<<(ostream& out, const SetArguments& r)
216 {
217  out << "{";
218 
220  for (it = r.begin(); it != r.end();)
221  {
222  out << (*it)->getName();
223  if (++it != r.end())
224  out << " ";
225  }
226  out << "}";
227  return out;
228 }
229