aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
O3prm.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 
37 
38  O3Position::O3Position(const std::string& file, int line, int column) :
41  }
42 
46  }
47 
52  }
53 
56  ;
57  }
58 
60  if (this == &src) { return *this; }
61  _file_ = src._file_;
62  _line_ = src._line_;
64  return *this;
65  }
66 
68  if (this == &src) { return *this; }
69  _file_ = std::move(src._file_);
70  _line_ = std::move(src._line_);
72  return *this;
73  }
74 
75  std::string& O3Position::file() { return _file_; }
76  const std::string& O3Position::file() const { return _file_; }
77 
78  int& O3Position::line() { return _line_; }
79  int O3Position::line() const { return _line_; }
80 
81  int& O3Position::column() { return _column_; }
82  int O3Position::column() const { return _column_; }
83 
86  ;
87  }
88 
91  }
92 
95  }
96 
100  }
101 
104  ;
105  }
106 
108  if (this == &src) { return *this; }
109  _pos_ = src._pos_;
110  _value_ = src._value_;
111  return *this;
112  }
113 
115  if (this == &src) { return *this; }
116  _pos_ = std::move(src._pos_);
117  _value_ = std::move(src._value_);
118  return *this;
119  }
120 
121  const O3Position& O3Integer::position() const { return _pos_; }
123 
124  int O3Integer::value() const { return _value_; }
125  int& O3Integer::value() { return _value_; }
126 
129  ;
130  }
131 
134  }
135 
138  }
139 
143  }
144 
147  ;
148  }
149 
151  if (this == &src) { return *this; }
152  _pos_ = src._pos_;
153  _value_ = src._value_;
154  return *this;
155  }
156 
158  if (this == &src) { return *this; }
159  _pos_ = std::move(src._pos_);
160  _value_ = std::move(src._value_);
161  return *this;
162  }
163 
164  const O3Position& O3Float::position() const { return _pos_; }
166 
167  float O3Float::value() const { return _value_; }
168  float& O3Float::value() { return _value_; }
169 
172  }
173 
177  }
178 
182  }
183 
187  }
188 
191  ;
192  }
193 
195  if (this == &src) { return *this; }
196  _pos_ = src._pos_;
198  return *this;
199  }
200 
202  if (this == &src) { return *this; }
203  _pos_ = std::move(src._pos_);
205  return *this;
206  }
207 
208  const O3Position& O3Formula::position() const { return _pos_; }
210 
211  const Formula& O3Formula::formula() const { return *_formula_; }
213 
216  ;
217  }
218 
220  _pos_(pos), _label_(label) {
222  }
223 
226  }
227 
231  }
232 
235  ;
236  }
237 
239  if (this == &src) { return *this; }
240  _pos_ = src._pos_;
241  _label_ = src._label_;
242  return *this;
243  }
244 
246  if (this == &src) { return *this; }
247  _pos_ = std::move(src._pos_);
248  _label_ = std::move(src._label_);
249  return *this;
250  }
251 
252  const O3Position& O3Label::position() const { return _pos_; }
254 
255  const std::string& O3Label::label() const { return _label_; }
256  std::string& O3Label::label() { return _label_; }
257 
258  O3Type::O3Type() : _dep_flag_(false) {
260  ;
261  }
262 
263  O3Type::O3Type(const O3Type& src) :
267  }
268 
274  }
275 
278  ;
279  }
280 
282  if (this == &src) { return *this; }
283  _pos_ = src._pos_;
284  _name_ = src._name_;
288  return *this;
289  }
290 
292  if (this == &src) { return *this; }
293  _pos_ = std::move(src._pos_);
294  _name_ = std::move(src._name_);
298  return *this;
299  }
300 
301  O3Label& O3Type::name() { return _name_; }
302  const O3Label& O3Type::name() const { return _name_; }
303 
305  const O3Label& O3Type::superLabel() const { return _superLabel_; }
306 
308  const O3Type::LabelMap& O3Type::labels() const { return _labels_; }
309 
310  O3Position& O3Type::position() { return _pos_; }
311  const O3Position& O3Type::position() const { return _pos_; }
312 
313  bool& O3Type::deprecated() { return _dep_flag_; }
314  const bool& O3Type::deprecated() const { return _dep_flag_; }
315 
318  ;
319  }
320 
325  }
326 
332  }
333 
336  ;
337  }
338 
340  if (this == &src) { return *this; }
341  _pos_ = src._pos_;
342  _name_ = src._name_;
343  _start_ = src._start_;
344  _end_ = src._end_;
346  return *this;
347  }
348 
350  if (this == &src) { return *this; }
351  _pos_ = std::move(src._pos_);
352  _name_ = std::move(src._name_);
353  _start_ = std::move(src._start_);
354  _end_ = std::move(src._end_);
356  return *this;
357  }
358 
359  O3Label& O3IntType::name() { return _name_; }
360  const O3Label& O3IntType::name() const { return _name_; }
361 
363  const O3Integer& O3IntType::start() const { return _start_; }
364 
365  O3Integer& O3IntType::end() { return _end_; }
366  const O3Integer& O3IntType::end() const { return _end_; }
367 
369  const O3Position& O3IntType::position() const { return _pos_; }
370 
371  bool& O3IntType::deprecated() { return _dep_flag_; }
372  const bool& O3IntType::deprecated() const { return _dep_flag_; }
373 
376  ;
377  }
378 
382  }
383 
388  }
389 
392  ;
393  }
394 
396  if (this == &src) { return *this; }
397 
398  _pos_ = src._pos_;
399  _name_ = src._name_;
402  return *this;
403  }
404 
406  if (this == &src) { return *this; }
407 
408  _pos_ = std::move(src._pos_);
409  _name_ = std::move(src._name_);
412  return *this;
413  }
414 
416  const O3Position& O3RealType::position() const { return _pos_; }
417 
418  O3Label& O3RealType::name() { return _name_; }
419  const O3Label& O3RealType::name() const { return _name_; }
420 
422  const std::vector< O3Float >& O3RealType::values() const { return _values_; }
423 
424  bool& O3RealType::deprecated() { return _dep_flag_; }
425  const bool& O3RealType::deprecated() const { return _dep_flag_; }
426 
429  // Creating the boolean type
430  auto name = O3Label(O3Position(), "boolean");
431  auto f = O3Label(O3Position(), "false");
432  auto t = O3Label(O3Position(), "true");
433  auto labels = O3Type::LabelMap();
436  auto boolean = std::unique_ptr< O3Type >(new O3Type());
437  boolean->name() = std::move(name);
438  boolean->labels() = std::move(labels);
440  }
441 
442  O3PRM::O3PRM(const O3PRM& src) {
444  for (const auto& t: src._types_) {
445  _types_.emplace_back(new O3Type(*t));
446  }
447  for (const auto& t: src._int_types_) {
449  }
450  for (const auto& t: src._real_types_) {
452  }
453  for (const auto& i: src._interfaces_) {
455  }
456  for (const auto& c: src._classes_) {
458  }
459  for (const auto& s: src._systems_) {
461  }
462  for (const auto& i: src._imports_) {
464  }
465  }
466 
473  }
474 
475  O3PRM::~O3PRM() {
477  ;
478  }
479 
480  O3PRM& O3PRM::operator=(const O3PRM& src) {
481  if (this == &src) { return *this; }
482  for (const auto& t: src._types_) {
483  _types_.emplace_back(new O3Type(*t));
484  }
485  for (const auto& t: src._int_types_) {
487  }
488  for (const auto& t: src._real_types_) {
490  }
491  for (const auto& i: src._interfaces_) {
493  }
494  for (const auto& c: src._classes_) {
496  }
497  for (const auto& s: src._systems_) {
499  }
500  for (const auto& i: src._imports_) {
502  }
503  return *this;
504  }
505 
507  if (this == &src) { return *this; }
508  _types_ = std::move(src._types_);
515  return *this;
516  }
517 
518  O3PRM::O3TypeList& O3PRM::types() { return _types_; }
519  const O3PRM::O3TypeList& O3PRM::types() const { return _types_; }
520 
522  const O3PRM::O3IntTypeList& O3PRM::int_types() const { return _int_types_; }
523 
525  const O3PRM::O3RealTypeList& O3PRM::real_types() const { return _real_types_; }
526 
528  const O3PRM::O3InterfaceList& O3PRM::interfaces() const { return _interfaces_; }
529 
531 
532  const O3PRM::O3ClassList& O3PRM::classes() const { return _classes_; }
533 
535 
536  const O3PRM::O3SystemList& O3PRM::systems() const { return _systems_; }
537 
539 
540  const O3PRM::O3ImportList& O3PRM::imports() const { return _imports_; }
541 
544  }
545 
547  const O3Label& name,
548  bool isArray) :
549  _type_(type),
552  }
553 
557  }
558 
563  }
564 
566 
568  if (this == &src) { return *this; }
569  _type_ = src._type_;
570  _name_ = src._name_;
572  return *this;
573  }
574 
576  if (this == &src) { return *this; }
577  _type_ = std::move(src._type_);
578  _name_ = std::move(src._name_);
580  return *this;
581  }
582 
584  const O3Label& O3InterfaceElement::type() const { return _type_; }
585 
587  const O3Label& O3InterfaceElement::name() const { return _name_; }
588 
589  bool& O3InterfaceElement::isArray() { return _isArray_; }
590  bool O3InterfaceElement::isArray() const { return _isArray_; }
591 
594  }
595 
599  auto copy = new O3InterfaceElementList(src.elements());
601  }
602 
607  }
608 
611  ;
612  }
613 
615  if (this == &src) { return *this; }
616  _pos_ = src._pos_;
617  _name_ = src._name_;
619  auto copy = new O3InterfaceElementList(src.elements());
621  return *this;
622  }
623 
625  if (this == &src) { return *this; }
626  _pos_ = std::move(src._pos_);
627  _name_ = std::move(src._name_);
629  _elts_ = std::move(src._elts_);
630  return *this;
631  }
632 
634  const O3Position& O3Interface::position() const { return _pos_; }
635 
636  O3Label& O3Interface::name() { return _name_; }
637  const O3Label& O3Interface::name() const { return _name_; }
638 
640  const O3Label& O3Interface::superLabel() const { return _superLabel_; }
641 
644 
647  ;
648  }
649 
651  const O3Label& name,
652  const O3LabelList& parents) :
653  _type_(type),
656  }
657 
661  }
662 
667  }
668 
671  ;
672  }
673 
675  if (this == &src) { return *this; }
676  _type_ = src._type_;
677  _name_ = src._name_;
679  return *this;
680  }
681 
683  if (this == &src) { return *this; }
684  _type_ = std::move(src._type_);
685  _name_ = std::move(src._name_);
687  return *this;
688  }
689 
690  O3Label& O3Attribute::type() { return _type_; }
691  const O3Label& O3Attribute::type() const { return _type_; }
692 
693  O3Label& O3Attribute::name() { return _name_; }
694  const O3Label& O3Attribute::name() const { return _name_; }
695 
697  const O3Attribute::O3LabelList& O3Attribute::parents() const { return _parents_; }
698 
701  }
702 
704  const O3Label& name,
705  const O3LabelList& parents,
706  const O3FormulaList& values) :
709  auto copy = new O3FormulaList(values);
711  }
712 
715  auto copy = new O3FormulaList(*(src._values_));
717  }
718 
721  }
722 
725  ;
726  }
727 
729  if (this == &src) { return *this; }
731  auto copy = new O3FormulaList(*(src._values_));
733  return *this;
734  }
735 
737  if (this == &src) { return *this; }
740  return *this;
741  }
742 
744 
745  const O3RawCPT::O3FormulaList& O3RawCPT::values() const { return *_values_; }
746 
748  auto copy = new O3RawCPT(*this);
749  return std::unique_ptr< O3Attribute >(copy);
750  }
751 
754  }
755 
757  const O3Label& name,
759  O3RuleList&& rules) :
763  }
764 
768  }
769 
772  }
773 
776  ;
777  }
778 
780  if (this == &src) { return *this; }
781 
784  return *this;
785  }
786 
788  if (this == &src) { return *this; }
789 
791  _rules_ = std::move(src._rules_);
792  return *this;
793  }
794 
796  const O3RuleCPT::O3RuleList& O3RuleCPT::rules() const { return *_rules_; }
797 
799  auto copy = new O3RuleCPT(*this);
800  return std::unique_ptr< O3Attribute >(copy);
801  }
802 
805 
806  auto i = new O3LabelList();
808 
809  auto p = new O3ParameterList();
811 
812  auto r = new O3ReferenceSlotList();
814 
815  auto e = new O3AttributeList();
817 
818  auto a = new O3AggregateList();
820  }
821 
825  auto i = new O3LabelList(src.interfaces());
827 
828  auto p = new O3ParameterList(src.parameters());
830 
831  auto r = new O3ReferenceSlotList(src.referenceSlots());
833 
834  auto e = new O3AttributeList();
836  for (const auto& elt: src.attributes()) {
837  _attrs_->push_back(elt->copy());
838  }
839 
840  auto a = new O3AggregateList(src.aggregates());
842  }
843 
850  }
851 
854  ;
855  }
856 
858  if (this == &src) { return *this; }
859  _pos_ = src._pos_;
860  _name_ = src._name_;
862 
863  auto i = new O3LabelList(src.interfaces());
865 
866  auto p = new O3ParameterList(src.parameters());
868 
869  auto r = new O3ReferenceSlotList(src.referenceSlots());
871 
872  auto e = new O3AttributeList();
874  for (const auto& elt: src.attributes()) {
875  _attrs_->push_back(elt->copy());
876  }
877 
878  auto a = new O3AggregateList(src.aggregates());
880  return *this;
881  }
882 
884  if (this == &src) { return *this; }
885  _pos_ = std::move(src._pos_);
886  _name_ = std::move(src._name_);
890  _refs_ = std::move(src._refs_);
891  _attrs_ = std::move(src._attrs_);
892  _aggs_ = std::move(src._aggs_);
893  return *this;
894  }
895 
896  const O3Position& O3Class::position() const { return _pos_; }
898 
899  const O3Label& O3Class::name() const { return _name_; }
900  O3Label& O3Class::name() { return _name_; }
901 
902  const O3Label& O3Class::superLabel() const { return _superLabel_; }
904 
905  const O3Class::O3LabelList& O3Class::interfaces() const { return *_interfaces_; }
907 
908  const O3Class::O3ParameterList& O3Class::parameters() const { return *_params_; }
910 
913 
915 
916  const O3Class::O3AttributeList& O3Class::attributes() const { return *_attrs_; }
917 
919  const O3Class::O3AggregateList& O3Class::aggregates() const { return *_aggs_; }
920 
923  }
924 
927  _value_(O3Float(value.position(), (float)value.value())) {
929  }
930 
934  }
935 
939  }
940 
943  _value_(std::move(src._value_)) {
945  }
946 
949  ;
950  }
951 
953  if (this == &src) { return *this; }
954  _type_ = src._type_;
955  _pos_ = src._pos_;
956  _name_ = src._name_;
957  _value_ = src._value_;
958  return *this;
959  }
960 
962  if (this == &src) { return *this; }
963  _type_ = std::move(src._type_);
964  _pos_ = std::move(src._pos_);
965  _name_ = std::move(src._name_);
966  _value_ = std::move(src._value_);
967  return *this;
968  }
969 
971  O3Parameter::PRMType O3Parameter::type() const { return _type_; }
972 
974  const O3Position& O3Parameter::position() const { return _pos_; }
975 
976  O3Label& O3Parameter::name() { return _name_; }
977  const O3Label& O3Parameter::name() const { return _name_; }
978 
980  const O3Float& O3Parameter::value() const { return _value_; }
981 
984  ;
985  }
986 
990  }
991 
995  }
996 
1001  }
1002 
1005  ;
1006  }
1007 
1009  if (this == &src) { return *this; }
1010  _type_ = src._type_;
1011  _name_ = src._name_;
1013  return *this;
1014  }
1015 
1017  if (this == &src) { return *this; }
1018  _type_ = std::move(src._type_);
1019  _name_ = std::move(src._name_);
1021  return *this;
1022  }
1023 
1025  const O3Label& O3ReferenceSlot::type() const { return _type_; }
1026 
1028  const O3Label& O3ReferenceSlot::name() const { return _name_; }
1029 
1030  bool& O3ReferenceSlot::isArray() { return _isArray_; }
1031  bool O3ReferenceSlot::isArray() const { return _isArray_; }
1032 
1036  }
1037 
1042  }
1043 
1049  }
1050 
1053  ;
1054  }
1055 
1057  if (this == &src) { return *this; }
1060  _name_ = src._name_;
1063  return *this;
1064  }
1065 
1067  if (this == &src) { return *this; }
1070  _name_ = std::move(src._name_);
1073  return *this;
1074  }
1075 
1077 
1078  const O3Label& O3Aggregate::variableType() const { return _variableType_; }
1079 
1081 
1082  const O3Label& O3Aggregate::aggregateType() const { return _aggregateType_; }
1083 
1084  O3Label& O3Aggregate::name() { return _name_; }
1085 
1086  const O3Label& O3Aggregate::name() const { return _name_; }
1087 
1089 
1090  const O3Aggregate::O3LabelList& O3Aggregate::parents() const { return _parents_; }
1091 
1093 
1095 
1098  ;
1099  }
1100 
1106  }
1107 
1114  }
1115 
1118  ;
1119  }
1120 
1122  if (this == &src) { return *this; }
1128  return *this;
1129  }
1130 
1132  if (this == &src) { return *this; }
1138  return *this;
1139  }
1140 
1141  const O3Label& O3Assignment::leftInstance() const { return _leftInstance_; }
1142 
1144 
1145  const O3Integer& O3Assignment::leftIndex() const { return _leftIndex_; }
1146 
1148 
1150 
1152 
1154 
1156 
1158 
1159  const O3Integer& O3Assignment::rightIndex() const { return _rightIndex_; }
1160 
1163  ;
1164  }
1165 
1171  }
1172 
1179  }
1180 
1183  ;
1184  }
1185 
1187  if (this == &src) { return *this; }
1193  return *this;
1194  }
1195 
1197  if (this == &src) { return *this; }
1203  return *this;
1204  }
1205 
1206  const O3Label& O3Increment::leftInstance() const { return _leftInstance_; }
1207 
1209 
1210  const O3Integer& O3Increment::leftIndex() const { return _leftIndex_; }
1211 
1213 
1214  const O3Label& O3Increment::leftReference() const { return _leftReference_; }
1215 
1217 
1218  const O3Label& O3Increment::rightInstance() const { return _rightInstance_; }
1219 
1221  const O3Integer& O3Increment::rightIndex() const { return _rightIndex_; }
1222 
1224 
1227  ;
1228  }
1229 
1234  }
1235 
1240  }
1241 
1244  ;
1245  }
1246 
1248  if (this == &src) { return *this; }
1249  _type_ = src._type_;
1250  _name_ = src._name_;
1251  _size_ = src._size_;
1253  return *this;
1254  }
1255 
1257  if (this == &src) { return *this; }
1258  _type_ = std::move(src._type_);
1259  _name_ = std::move(src._name_);
1260  _size_ = std::move(src._size_);
1262  return *this;
1263  }
1264 
1265  const O3Label& O3Instance::type() const { return _type_; }
1266 
1267  O3Label& O3Instance::type() { return _type_; }
1268 
1269  const O3Label& O3Instance::name() const { return _name_; }
1270 
1271  O3Label& O3Instance::name() { return _name_; }
1272 
1273  const O3Integer& O3Instance::size() const { return _size_; }
1274 
1276 
1278  return _parameters_;
1279  }
1280 
1282 
1285  ;
1286  }
1287 
1292  }
1293 
1298  }
1299 
1302  ;
1303  }
1304 
1306  if (this == &src) { return *this; }
1307  _name_ = src._name_;
1311  return *this;
1312  }
1313 
1315  if (this == &src) { return *this; }
1316  _name_ = std::move(src._name_);
1320  return *this;
1321  }
1322 
1323  const O3Label& O3System::name() const { return _name_; }
1324 
1325  O3Label& O3System::name() { return _name_; }
1326 
1328 
1330 
1332 
1334 
1336 
1338 
1340  o << src.label();
1341  return o;
1342  }
1343 
1346  }
1347 
1351  }
1352 
1357  }
1358 
1360 
1362  if (this == &src) { return *this; }
1363  _name_ = src._name_;
1364  _value_ = src._value_;
1366  return *this;
1367  }
1368 
1370  if (this == &src) { return *this; }
1371  _name_ = std::move(src._name_);
1372  _value_ = std::move(src._value_);
1374  return *this;
1375  }
1376 
1377  const O3Label& O3InstanceParameter::name() const { return _name_; }
1378 
1380 
1381  const O3Float& O3InstanceParameter::value() const { return _value_; }
1382 
1384 
1385  bool O3InstanceParameter::isInteger() const { return _isInteger_; }
1386 
1388 
1391  ;
1392  }
1393 
1396  }
1397 
1400  }
1401 
1404  ;
1405  }
1406 
1408  if (this == &src) { return *this; }
1409  _import_ = src._import_;
1410  return *this;
1411  }
1412 
1414  if (this == &src) { return *this; }
1416  return *this;
1417  }
1418 
1419  const O3Label& O3Import::import() const { return _import_; }
1420 
1422 
1423  } // namespace o3prm
1424  } // namespace prm
1425 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
std::ostream & operator<<(std::ostream &o, const O3Label &src)
Definition: O3prm.cpp:1339
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)