aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
O3prm.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Implementation for the AST of the O3PRM language.
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  * @author Lionel TORTI
28  */
29 
30 #include <agrum/PRM/o3prm/O3prm.h>
31 
32 namespace gum {
33  namespace prm {
34  namespace o3prm {
35 
38  }
39 
40  O3Position::O3Position(const std::string& file, int line, int column) :
43  }
44 
48  }
49 
54  }
55 
57 
59  if (this == &src) { return *this; }
60  file__ = src.file__;
61  line__ = src.line__;
63  return *this;
64  }
65 
67  if (this == &src) { return *this; }
68  file__ = std::move(src.file__);
69  line__ = std::move(src.line__);
71  return *this;
72  }
73 
74  std::string& O3Position::file() { return file__; }
75  const std::string& O3Position::file() const { return file__; }
76 
77  int& O3Position::line() { return line__; }
78  int O3Position::line() const { return line__; }
79 
80  int& O3Position::column() { return column__; }
81  int O3Position::column() const { return column__; }
82 
84 
86  pos__(pos), value__(value) {
88  }
89 
93  }
94 
98  }
99 
101 
103  if (this == &src) { return *this; }
104  pos__ = src.pos__;
105  value__ = src.value__;
106  return *this;
107  }
108 
110  if (this == &src) { return *this; }
111  pos__ = std::move(src.pos__);
112  value__ = std::move(src.value__);
113  return *this;
114  }
115 
116  const O3Position& O3Integer::position() const { return pos__; }
118 
119  int O3Integer::value() const { return value__; }
120  int& O3Integer::value() { return value__; }
121 
123 
124  O3Float::O3Float(const O3Position& pos, float value) :
125  pos__(pos), value__(value) {
127  }
128 
132  }
133 
137  }
138 
140 
142  if (this == &src) { return *this; }
143  pos__ = src.pos__;
144  value__ = src.value__;
145  return *this;
146  }
147 
149  if (this == &src) { return *this; }
150  pos__ = std::move(src.pos__);
151  value__ = std::move(src.value__);
152  return *this;
153  }
154 
155  const O3Position& O3Float::position() const { return pos__; }
157 
158  float O3Float::value() const { return value__; }
159  float& O3Float::value() { return value__; }
160 
162  pos__(), formula__(std::unique_ptr< Formula >(new Formula(""))) {
164  }
165 
169  }
170 
172  pos__(src.pos__),
175  }
176 
180  }
181 
183 
185  if (this == &src) { return *this; }
186  pos__ = src.pos__;
188  return *this;
189  }
190 
192  if (this == &src) { return *this; }
193  pos__ = std::move(src.pos__);
195  return *this;
196  }
197 
198  const O3Position& O3Formula::position() const { return pos__; }
200 
201  const Formula& O3Formula::formula() const { return *formula__; }
203 
205 
207  pos__(pos), label__(label) {
209  }
210 
214  }
215 
219  }
220 
222 
224  if (this == &src) { return *this; }
225  pos__ = src.pos__;
226  label__ = src.label__;
227  return *this;
228  }
229 
231  if (this == &src) { return *this; }
232  pos__ = std::move(src.pos__);
233  label__ = std::move(src.label__);
234  return *this;
235  }
236 
237  const O3Position& O3Label::position() const { return pos__; }
239 
240  const std::string& O3Label::label() const { return label__; }
241  std::string& O3Label::label() { return label__; }
242 
244 
245  O3Type::O3Type(const O3Type& src) :
249  }
250 
257  }
258 
260 
262  if (this == &src) { return *this; }
263  pos__ = src.pos__;
264  name__ = src.name__;
268  return *this;
269  }
270 
272  if (this == &src) { return *this; }
273  pos__ = std::move(src.pos__);
274  name__ = std::move(src.name__);
278  return *this;
279  }
280 
281  O3Label& O3Type::name() { return name__; }
282  const O3Label& O3Type::name() const { return name__; }
283 
285  const O3Label& O3Type::superLabel() const { return superLabel__; }
286 
288  const O3Type::LabelMap& O3Type::labels() const { return labels__; }
289 
290  O3Position& O3Type::position() { return pos__; }
291  const O3Position& O3Type::position() const { return pos__; }
292 
293  bool& O3Type::deprecated() { return dep_flag__; }
294  const bool& O3Type::deprecated() const { return dep_flag__; }
295 
297 
302  }
303 
309  }
310 
312 
314  if (this == &src) { return *this; }
315  pos__ = src.pos__;
316  name__ = src.name__;
317  start__ = src.start__;
318  end__ = src.end__;
320  return *this;
321  }
322 
324  if (this == &src) { return *this; }
325  pos__ = std::move(src.pos__);
326  name__ = std::move(src.name__);
327  start__ = std::move(src.start__);
328  end__ = std::move(src.end__);
330  return *this;
331  }
332 
333  O3Label& O3IntType::name() { return name__; }
334  const O3Label& O3IntType::name() const { return name__; }
335 
337  const O3Integer& O3IntType::start() const { return start__; }
338 
339  O3Integer& O3IntType::end() { return end__; }
340  const O3Integer& O3IntType::end() const { return end__; }
341 
343  const O3Position& O3IntType::position() const { return pos__; }
344 
345  bool& O3IntType::deprecated() { return dep_flag__; }
346  const bool& O3IntType::deprecated() const { return dep_flag__; }
347 
349 
354  }
355 
361  }
362 
364 
366  if (this == &src) { return *this; }
367 
368  pos__ = src.pos__;
369  name__ = src.name__;
372  return *this;
373  }
374 
376  if (this == &src) { return *this; }
377 
378  pos__ = std::move(src.pos__);
379  name__ = std::move(src.name__);
382  return *this;
383  }
384 
386  const O3Position& O3RealType::position() const { return pos__; }
387 
388  O3Label& O3RealType::name() { return name__; }
389  const O3Label& O3RealType::name() const { return name__; }
390 
392  const std::vector< O3Float >& O3RealType::values() const { return values__; }
393 
394  bool& O3RealType::deprecated() { return dep_flag__; }
395  const bool& O3RealType::deprecated() const { return dep_flag__; }
396 
399  // Creating the boolean type
400  auto name = O3Label(O3Position(), "boolean");
401  auto f = O3Label(O3Position(), "false");
402  auto t = O3Label(O3Position(), "true");
403  auto labels = O3Type::LabelMap();
406  auto boolean = std::unique_ptr< O3Type >(new O3Type());
407  boolean->name() = std::move(name);
408  boolean->labels() = std::move(labels);
410  }
411 
412  O3PRM::O3PRM(const O3PRM& src) {
414  for (const auto& t: src.types__) {
415  types__.emplace_back(new O3Type(*t));
416  }
417  for (const auto& t: src.int_types__) {
419  }
420  for (const auto& t: src.real_types__) {
422  }
423  for (const auto& i: src.interfaces__) {
425  }
426  for (const auto& c: src.classes__) {
428  }
429  for (const auto& s: src.systems__) {
431  }
432  for (const auto& i: src.imports__) {
434  }
435  }
436 
444  }
445 
447 
448  O3PRM& O3PRM::operator=(const O3PRM& src) {
449  if (this == &src) { return *this; }
450  for (const auto& t: src.types__) {
451  types__.emplace_back(new O3Type(*t));
452  }
453  for (const auto& t: src.int_types__) {
455  }
456  for (const auto& t: src.real_types__) {
458  }
459  for (const auto& i: src.interfaces__) {
461  }
462  for (const auto& c: src.classes__) {
464  }
465  for (const auto& s: src.systems__) {
467  }
468  for (const auto& i: src.imports__) {
470  }
471  return *this;
472  }
473 
475  if (this == &src) { return *this; }
476  types__ = std::move(src.types__);
483  return *this;
484  }
485 
486  O3PRM::O3TypeList& O3PRM::types() { return types__; }
487  const O3PRM::O3TypeList& O3PRM::types() const { return types__; }
488 
490  const O3PRM::O3IntTypeList& O3PRM::int_types() const { return int_types__; }
491 
494  return real_types__;
495  }
496 
499  return interfaces__;
500  }
501 
503 
504  const O3PRM::O3ClassList& O3PRM::classes() const { return classes__; }
505 
507 
508  const O3PRM::O3SystemList& O3PRM::systems() const { return systems__; }
509 
511 
512  const O3PRM::O3ImportList& O3PRM::imports() const { return imports__; }
513 
516  }
517 
519  const O3Label& name,
520  bool isArray) :
521  type__(type),
524  }
525 
529  }
530 
535  }
536 
539  }
540 
543  if (this == &src) { return *this; }
544  type__ = src.type__;
545  name__ = src.name__;
547  return *this;
548  }
549 
551  if (this == &src) { return *this; }
552  type__ = std::move(src.type__);
553  name__ = std::move(src.name__);
555  return *this;
556  }
557 
559  const O3Label& O3InterfaceElement::type() const { return type__; }
560 
562  const O3Label& O3InterfaceElement::name() const { return name__; }
563 
564  bool& O3InterfaceElement::isArray() { return isArray__; }
565  bool O3InterfaceElement::isArray() const { return isArray__; }
566 
569  }
570 
574  auto copy = new O3InterfaceElementList(src.elements());
576  }
577 
581  elts__(std::move(src.elts__)) {
583  }
584 
586 
588  if (this == &src) { return *this; }
589  pos__ = src.pos__;
590  name__ = src.name__;
592  auto copy = new O3InterfaceElementList(src.elements());
594  return *this;
595  }
596 
598  if (this == &src) { return *this; }
599  pos__ = std::move(src.pos__);
600  name__ = std::move(src.name__);
602  elts__ = std::move(src.elts__);
603  return *this;
604  }
605 
607  const O3Position& O3Interface::position() const { return pos__; }
608 
609  O3Label& O3Interface::name() { return name__; }
610  const O3Label& O3Interface::name() const { return name__; }
611 
613  const O3Label& O3Interface::superLabel() const { return superLabel__; }
614 
616  return *elts__;
617  }
619  return *elts__;
620  }
621 
623 
625  const O3Label& name,
626  const O3LabelList& parents) :
627  type__(type),
630  }
631 
635  }
636 
641  }
642 
644 
646  if (this == &src) { return *this; }
647  type__ = src.type__;
648  name__ = src.name__;
650  return *this;
651  }
652 
654  if (this == &src) { return *this; }
655  type__ = std::move(src.type__);
656  name__ = std::move(src.name__);
658  return *this;
659  }
660 
661  O3Label& O3Attribute::type() { return type__; }
662  const O3Label& O3Attribute::type() const { return type__; }
663 
664  O3Label& O3Attribute::name() { return name__; }
665  const O3Label& O3Attribute::name() const { return name__; }
666 
669  return parents__;
670  }
671 
674  }
675 
677  const O3Label& name,
678  const O3LabelList& parents,
679  const O3FormulaList& values) :
682  auto copy = new O3FormulaList(values);
684  }
685 
688  auto copy = new O3FormulaList(*(src.values__));
690  }
691 
695  }
696 
698 
700  if (this == &src) { return *this; }
702  auto copy = new O3FormulaList(*(src.values__));
704  return *this;
705  }
706 
708  if (this == &src) { return *this; }
711  return *this;
712  }
713 
715 
716  const O3RawCPT::O3FormulaList& O3RawCPT::values() const { return *values__; }
717 
719  auto copy = new O3RawCPT(*this);
720  return std::unique_ptr< O3Attribute >(copy);
721  }
722 
725  }
726 
728  const O3Label& name,
730  O3RuleList&& rules) :
734  }
735 
737  O3Attribute(src),
740  }
741 
745  }
746 
748 
750  if (this == &src) { return *this; }
751 
754  return *this;
755  }
756 
758  if (this == &src) { return *this; }
759 
761  rules__ = std::move(src.rules__);
762  return *this;
763  }
764 
766  const O3RuleCPT::O3RuleList& O3RuleCPT::rules() const { return *rules__; }
767 
769  auto copy = new O3RuleCPT(*this);
770  return std::unique_ptr< O3Attribute >(copy);
771  }
772 
775 
776  auto i = new O3LabelList();
778 
779  auto p = new O3ParameterList();
781 
782  auto r = new O3ReferenceSlotList();
784 
785  auto e = new O3AttributeList();
787 
788  auto a = new O3AggregateList();
790  }
791 
795  auto i = new O3LabelList(src.interfaces());
797 
798  auto p = new O3ParameterList(src.parameters());
800 
801  auto r = new O3ReferenceSlotList(src.referenceSlots());
803 
804  auto e = new O3AttributeList();
806  for (const auto& elt: src.attributes()) {
807  attrs__->push_back(elt->copy());
808  }
809 
810  auto a = new O3AggregateList(src.aggregates());
812  }
813 
821  }
822 
824 
826  if (this == &src) { return *this; }
827  pos__ = src.pos__;
828  name__ = src.name__;
830 
831  auto i = new O3LabelList(src.interfaces());
833 
834  auto p = new O3ParameterList(src.parameters());
836 
837  auto r = new O3ReferenceSlotList(src.referenceSlots());
839 
840  auto e = new O3AttributeList();
842  for (const auto& elt: src.attributes()) {
843  attrs__->push_back(elt->copy());
844  }
845 
846  auto a = new O3AggregateList(src.aggregates());
848  return *this;
849  }
850 
852  if (this == &src) { return *this; }
853  pos__ = std::move(src.pos__);
854  name__ = std::move(src.name__);
858  refs__ = std::move(src.refs__);
859  attrs__ = std::move(src.attrs__);
860  aggs__ = std::move(src.aggs__);
861  return *this;
862  }
863 
864  const O3Position& O3Class::position() const { return pos__; }
866 
867  const O3Label& O3Class::name() const { return name__; }
868  O3Label& O3Class::name() { return name__; }
869 
870  const O3Label& O3Class::superLabel() const { return superLabel__; }
872 
874  return *interfaces__;
875  }
877 
879  return *params__;
880  }
882 
884  return *refs__;
885  }
887 
889 
891  return *attrs__;
892  }
893 
896  return *aggs__;
897  }
898 
901  }
902 
904  const O3Label& name,
905  const O3Integer& value) :
907  pos__(pos), name__(name),
908  value__(O3Float(value.position(), (float)value.value())) {
910  }
911 
913  const O3Label& name,
914  const O3Float& value) :
918  }
919 
922  value__(src.value__) {
924  }
925 
930  }
931 
933 
935  if (this == &src) { return *this; }
936  type__ = src.type__;
937  pos__ = src.pos__;
938  name__ = src.name__;
939  value__ = src.value__;
940  return *this;
941  }
942 
944  if (this == &src) { return *this; }
945  type__ = std::move(src.type__);
946  pos__ = std::move(src.pos__);
947  name__ = std::move(src.name__);
948  value__ = std::move(src.value__);
949  return *this;
950  }
951 
953  O3Parameter::PRMType O3Parameter::type() const { return type__; }
954 
956  const O3Position& O3Parameter::position() const { return pos__; }
957 
958  O3Label& O3Parameter::name() { return name__; }
959  const O3Label& O3Parameter::name() const { return name__; }
960 
962  const O3Float& O3Parameter::value() const { return value__; }
963 
965 
967  const O3Label& name,
968  bool isArray) :
969  type__(type),
972  }
973 
977  }
978 
983  }
984 
986 
988  if (this == &src) { return *this; }
989  type__ = src.type__;
990  name__ = src.name__;
992  return *this;
993  }
994 
996  if (this == &src) { return *this; }
997  type__ = std::move(src.type__);
998  name__ = std::move(src.name__);
1000  return *this;
1001  }
1002 
1004  const O3Label& O3ReferenceSlot::type() const { return type__; }
1005 
1007  const O3Label& O3ReferenceSlot::name() const { return name__; }
1008 
1009  bool& O3ReferenceSlot::isArray() { return isArray__; }
1010  bool O3ReferenceSlot::isArray() const { return isArray__; }
1011 
1014  parameters__() {
1016  }
1017 
1023  }
1024 
1031  }
1032 
1034 
1036  if (this == &src) { return *this; }
1039  name__ = src.name__;
1042  return *this;
1043  }
1044 
1046  if (this == &src) { return *this; }
1049  name__ = std::move(src.name__);
1052  return *this;
1053  }
1054 
1056 
1057  const O3Label& O3Aggregate::variableType() const { return variableType__; }
1058 
1060 
1061  const O3Label& O3Aggregate::aggregateType() const { return aggregateType__; }
1062 
1063  O3Label& O3Aggregate::name() { return name__; }
1064 
1065  const O3Label& O3Aggregate::name() const { return name__; }
1066 
1068 
1070  return parents__;
1071  }
1072 
1074 
1076  return parameters__;
1077  }
1078 
1080 
1086  }
1087 
1095  }
1096 
1098 
1100  if (this == &src) { return *this; }
1106  return *this;
1107  }
1108 
1110  if (this == &src) { return *this; }
1116  return *this;
1117  }
1118 
1119  const O3Label& O3Assignment::leftInstance() const { return leftInstance__; }
1120 
1122 
1123  const O3Integer& O3Assignment::leftIndex() const { return leftIndex__; }
1124 
1126 
1128  return leftReference__;
1129  }
1130 
1132 
1134  return rightInstance__;
1135  }
1136 
1138 
1140 
1141  const O3Integer& O3Assignment::rightIndex() const { return rightIndex__; }
1142 
1144 
1150  }
1151 
1159  }
1160 
1162 
1164  if (this == &src) { return *this; }
1170  return *this;
1171  }
1172 
1174  if (this == &src) { return *this; }
1180  return *this;
1181  }
1182 
1183  const O3Label& O3Increment::leftInstance() const { return leftInstance__; }
1184 
1186 
1187  const O3Integer& O3Increment::leftIndex() const { return leftIndex__; }
1188 
1190 
1191  const O3Label& O3Increment::leftReference() const { return leftReference__; }
1192 
1194 
1195  const O3Label& O3Increment::rightInstance() const { return rightInstance__; }
1196 
1198  const O3Integer& O3Increment::rightIndex() const { return rightIndex__; }
1199 
1201 
1203 
1208  }
1209 
1212  size__(std::move(src.size__)),
1215  }
1216 
1218 
1220  if (this == &src) { return *this; }
1221  type__ = src.type__;
1222  name__ = src.name__;
1223  size__ = src.size__;
1225  return *this;
1226  }
1227 
1229  if (this == &src) { return *this; }
1230  type__ = std::move(src.type__);
1231  name__ = std::move(src.name__);
1232  size__ = std::move(src.size__);
1234  return *this;
1235  }
1236 
1237  const O3Label& O3Instance::type() const { return type__; }
1238 
1239  O3Label& O3Instance::type() { return type__; }
1240 
1241  const O3Label& O3Instance::name() const { return name__; }
1242 
1243  O3Label& O3Instance::name() { return name__; }
1244 
1245  const O3Integer& O3Instance::size() const { return size__; }
1246 
1248 
1250  return parameters__;
1251  }
1252 
1254  return parameters__;
1255  }
1256 
1258 
1263  }
1264 
1270  }
1271 
1273 
1275  if (this == &src) { return *this; }
1276  name__ = src.name__;
1280  return *this;
1281  }
1282 
1284  if (this == &src) { return *this; }
1285  name__ = std::move(src.name__);
1289  return *this;
1290  }
1291 
1292  const O3Label& O3System::name() const { return name__; }
1293 
1294  O3Label& O3System::name() { return name__; }
1295 
1297  return instances__;
1298  }
1299 
1301 
1303  return assigments__;
1304  }
1305 
1307 
1309  return increments__;
1310  }
1311 
1313 
1315  o << src.label();
1316  return o;
1317  }
1318 
1321  }
1322 
1326  }
1327 
1332  }
1333 
1336  }
1337 
1340  if (this == &src) { return *this; }
1341  name__ = src.name__;
1342  value__ = src.value__;
1344  return *this;
1345  }
1346 
1349  if (this == &src) { return *this; }
1350  name__ = std::move(src.name__);
1351  value__ = std::move(src.value__);
1353  return *this;
1354  }
1355 
1356  const O3Label& O3InstanceParameter::name() const { return name__; }
1357 
1359 
1360  const O3Float& O3InstanceParameter::value() const { return value__; }
1361 
1363 
1364  bool O3InstanceParameter::isInteger() const { return isInteger__; }
1365 
1367 
1369 
1372  }
1373 
1376  }
1377 
1379 
1381  if (this == &src) { return *this; }
1382  import__ = src.import__;
1383  return *this;
1384  }
1385 
1387  if (this == &src) { return *this; }
1389  return *this;
1390  }
1391 
1392  const O3Label& O3Import::import() const { return import__; }
1393 
1395 
1396  } // namespace o3prm
1397  } // namespace prm
1398 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
std::ostream & operator<<(std::ostream &o, const O3Label &src)
Definition: O3prm.cpp:1314
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)