gamssymbol.h
1/*
2  * GAMS - General Algebraic Modeling System C++ API
3  *
4  * Copyright (c) 2017-2022 GAMS Software GmbH <support@gams.com>
5  * Copyright (c) 2017-2022 GAMS Development Corp. <support@gams.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef GAMSSYMBOL_H
27 #define GAMSSYMBOL_H
28 
29 #include "gamsenum.h"
30 #include "gamssymboliter.h"
31 #include <string>
32 #include <memory>
33 #include <vector>
34 
35 namespace gams {
36 
37 class GAMSSet;
38 class GAMSVariable;
39 class GAMSSymbolRecord;
40 class GAMSDatabase;
41 class GAMSDomain;
42 class GAMSSymbolImpl;
43 class GAMSSymbolDomainViolation;
44 
48 class LIBSPEC GAMSSymbol
49 {
50 public:
52 
55 
58  GAMSSymbol(const GAMSSymbol &symbol);
59 
61  virtual ~GAMSSymbol();
62 
67 
71  bool operator!=(const GAMSSymbol& other) const;
72 
76  bool operator==(const GAMSSymbol& other) const;
77 
80  bool isValid() const;
81 
85 
89 
93  GAMSSymbolRecord addRecord(const std::vector<std::string>& keys);
94 
98 
102  GAMSSymbolRecord addRecord(const std::string& key1);
103 
108  GAMSSymbolRecord addRecord(const std::string& key1, const std::string& key2);
109 
115  GAMSSymbolRecord addRecord(const std::string& key1, const std::string& key2, const std::string& key3);
116 
120  void deleteRecord(const std::vector<std::string>& keys);
121 
122  // TODO(JM) missing overloads for ::deleteRecord
123 
126  bool clear();
127 
130  std::vector<GAMSDomain> domains();
131 
134  bool checkDomains();
135 
139  std::vector<GAMSSymbolDomainViolation> getSymbolDVs(int maxViol = 0);
140 
144  GAMSSymbolRecord firstRecord(const std::vector<std::string>& slice);
145 
149 
153  GAMSSymbolRecord firstRecord(const std::string& key1);
154 
159  GAMSSymbolRecord firstRecord(const std::string& key1, const std::string& key2);
160 
166  GAMSSymbolRecord firstRecord(const std::string& key1, const std::string& key2, const std::string& key3);
167 
171  GAMSSymbolRecord lastRecord(const std::vector<std::string>& slice);
172 
176 
180  GAMSSymbolRecord lastRecord(const std::string& key1);
181 
186  GAMSSymbolRecord lastRecord(const std::string& key1, const std::string& key2);
187 
193  GAMSSymbolRecord lastRecord(const std::string& key1, const std::string& key2, const std::string& key3);
194 
198  GAMSSymbolRecord findRecord(const std::vector<std::string>& keys);
199 
203 
207  GAMSSymbolRecord findRecord(const std::string& key1);
208 
213  GAMSSymbolRecord findRecord(const std::string& key1, const std::string& key2);
214 
220  GAMSSymbolRecord findRecord(const std::string& key1, const std::string& key2, const std::string& key3);
221 
225  GAMSSymbolRecord mergeRecord(const std::vector<std::string>& keys);
226 
230 
234  GAMSSymbolRecord mergeRecord(const std::string& key1);
235 
240  GAMSSymbolRecord mergeRecord(const std::string& key1, const std::string& key2);
241 
247  GAMSSymbolRecord mergeRecord(const std::string& key1, const std::string& key2, const std::string& key3);
248 
252  void copySymbol(const GAMSSymbol& target);
253 
256 
258  std::string text() const;
259 
261  std::string& name() const;
262 
264  int dim() const;
265 
267  int numberRecords() const;
268 
271  LogId logID();
272 
275 
276 protected:
277  friend class GAMSSymbolRecordImpl;
278  friend class GAMSModelInstanceImpl;
279  friend class GAMSDatabaseImpl;
280  friend class GAMSSymbolIter<GAMSSymbol>;
281 
282  GAMSSymbol(const std::shared_ptr<GAMSSymbolImpl> impl);
283 
284  GAMSSymbol(GAMSDatabase &database, int dim, std::string name, std::string text,
285  GAMSEnum::SymbolType symType, GAMSEnum::VarType varType, GAMSEnum::EquType equType,
286  GAMSEnum::SetType setType = GAMSEnum::SetType::Multi);
287 
288  GAMSSymbol(GAMSDatabase &database, std::string name, std::string text, GAMSEnum::SymbolType symType,
289  GAMSEnum::VarType varType, GAMSEnum::EquType equType, const std::vector<GAMSDomain>& domains,
290  GAMSEnum::SetType setType = GAMSEnum::SetType::Multi);
291 
292  GAMSSymbol(GAMSDatabase &database, void *symPtr, int dim, std::string name, std::string text,
293  GAMSEnum::SymbolType symType, GAMSEnum::VarType varType, GAMSEnum::EquType equType,
294  GAMSEnum::SetType setType = GAMSEnum::SetType::Multi);
295 
296  GAMSSymbol(const GAMSDatabase &database, void *symPtr);
297 
298  void *symPtr() const;
299 
300  std::vector<GAMSSymbolDomainViolation> getSymbolDVs(bool skipCleanup, int maxViol = 0);
301 
302 protected:
303  std::shared_ptr<GAMSSymbolImpl> mImpl;
304 };
305 
306 } // namespace gams
307 
308 #endif // GAMSSYMBOL_H
SymbolType
This enum defines the type of a symbol (The type Alias is not supported and shows as Set).
Definition: gamsenum.h:44
gams::GAMSDatabase & database() const
Get GAMSDatabase containing the GAMSSymbol.
GAMSEnum::SymbolType type() const
Get the symbol type.
GAMSSymbolRecord addRecord(const std::vector< std::string > &keys)
GAMSSymbolRecord firstRecord()
GAMSSymbolRecord lastRecord()
GAMSSymbolRecord mergeRecord(const std::string &key1, const std::string &key2)
int dim() const
Get GAMSSymbol dimension.
bool isValid() const
GAMSSymbolRecord addRecord()
GAMSSymbol(const GAMSSymbol &symbol)
GAMSSymbolRecord lastRecord(const std::string &key1)
std::string & name() const
Get GAMSSymbol name.
GAMSSymbolRecord mergeRecord(const std::string &key1, const std::string &key2, const std::string &key3)
int numberRecords() const
Retrieve the number of records of the GAMSSymbol.
virtual ~GAMSSymbol()
Destructor.
GAMSSymbol()
Standard constructor.
GAMSSymbolRecord firstRecord(const std::vector< std::string > &slice)
GAMSSymbolRecord lastRecord(const std::string &key1, const std::string &key2)
GAMSSymbolRecord firstRecord(const std::string &key1, const std::string &key2)
std::vector< GAMSDomain > domains()
Definition: gams.h:91
void deleteRecord(const std::vector< std::string > &keys)
std::vector< GAMSSymbolDomainViolation > getSymbolDVs(int maxViol=0)
GAMSSymbolRecord findRecord(const std::string &key1)
GAMSSymbolRecord mergeRecord(const std::string &key1)
VarType
Variable subtype.
Definition: gamsenum.h:83
std::string text() const
Get explanatory text of GAMSSymbol.
GAMSSymbolIter< GAMSSymbol > begin()
GAMSSymbol operator=(const GAMSSymbol &other)
GAMSSymbolRecord firstRecord(const std::string &key1)
void copySymbol(const GAMSSymbol &target)
GAMSSymbolRecord findRecord(const std::string &key1, const std::string &key2, const std::string &key3)
SetType
Set subtype.
Definition: gamsenum.h:73
bool operator!=(const GAMSSymbol &other) const
GAMSSymbolRecord addRecord(const std::string &key1, const std::string &key2, const std::string &key3)
GAMSSymbolRecord findRecord(const std::vector< std::string > &keys)
EquType
Equation subtype.
Definition: gamsenum.h:58
GAMSSymbolRecord firstRecord(const std::string &key1, const std::string &key2, const std::string &key3)
GAMSSymbolRecord lastRecord(const std::vector< std::string > &slice)
GAMSSymbolRecord findRecord()
GAMSSymbolRecord mergeRecord(const std::vector< std::string > &keys)
GAMSSymbolRecord findRecord(const std::string &key1, const std::string &key2)
GAMSSymbolRecord addRecord(const std::string &key1, const std::string &key2)
GAMSSymbolRecord mergeRecord()
bool operator==(const GAMSSymbol &other) const
GAMSSymbolIter< GAMSSymbol > end()
GAMSSymbolRecord lastRecord(const std::string &key1, const std::string &key2, const std::string &key3)
GAMSSymbolRecord addRecord(const std::string &key1)