| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2010-2015 Dmitry Tsarkov and The University of Manchester |
| 3 | Copyright (C) 2015-2017 Dmitry Tsarkov |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifndef TDLEXPRESSION_H |
| 21 | #define TDLEXPRESSION_H |
| 22 | |
| 23 | #include <vector> |
| 24 | #include <string> |
| 25 | |
| 26 | #include "eFaCTPlusPlus.h" |
| 27 | #include "fpp_assert.h" |
| 28 | #include "tNameSet.h" |
| 29 | |
| 30 | // forward declaration for all expression classes: necessary for the visitor pattern |
| 31 | class TDLExpression; |
| 32 | |
| 33 | class TDLConceptExpression; |
| 34 | class TDLConceptTop; |
| 35 | class TDLConceptBottom; |
| 36 | class TDLConceptName; |
| 37 | class TDLConceptNot; |
| 38 | class TDLConceptAnd; |
| 39 | class TDLConceptOr; |
| 40 | class TDLConceptOneOf; |
| 41 | class TDLConceptObjectRoleExpression; |
| 42 | class TDLConceptObjectSelf; |
| 43 | class TDLConceptObjectValue; |
| 44 | class TDLConceptObjectRCExpression; |
| 45 | class TDLConceptObjectExists; |
| 46 | class TDLConceptObjectForall; |
| 47 | class TDLConceptObjectCardinalityExpression; |
| 48 | class TDLConceptObjectMinCardinality; |
| 49 | class TDLConceptObjectMaxCardinality; |
| 50 | class TDLConceptObjectExactCardinality; |
| 51 | class TDLConceptDataRoleExpression; |
| 52 | class TDLConceptDataValue; |
| 53 | class TDLConceptDataRVExpression; |
| 54 | class TDLConceptDataExists; |
| 55 | class TDLConceptDataForall; |
| 56 | class TDLConceptDataCardinalityExpression; |
| 57 | class TDLConceptDataMinCardinality; |
| 58 | class TDLConceptDataMaxCardinality; |
| 59 | class TDLConceptDataExactCardinality; |
| 60 | |
| 61 | class TDLIndividualExpression; |
| 62 | class TDLIndividualName; |
| 63 | |
| 64 | class TDLRoleExpression; |
| 65 | class TDLObjectRoleComplexExpression; |
| 66 | class TDLObjectRoleExpression; |
| 67 | class TDLObjectRoleTop; |
| 68 | class TDLObjectRoleBottom; |
| 69 | class TDLObjectRoleName; |
| 70 | class TDLObjectRoleInverse; |
| 71 | class TDLObjectRoleChain; |
| 72 | class TDLObjectRoleProjectionFrom; |
| 73 | class TDLObjectRoleProjectionInto; |
| 74 | |
| 75 | class TDLDataRoleExpression; |
| 76 | class TDLDataRoleTop; |
| 77 | class TDLDataRoleBottom; |
| 78 | class TDLDataRoleName; |
| 79 | |
| 80 | class TDLDataExpression; |
| 81 | class TDLDataTop; |
| 82 | class TDLDataBottom; |
| 83 | class TDLDataTypeExpression; |
| 84 | class TDLDataTypeName; |
| 85 | class TDLDataTypeRestriction; |
| 86 | class TDLDataValue; |
| 87 | class TDLDataNot; |
| 88 | class TDLDataAnd; |
| 89 | class TDLDataOr; |
| 90 | class TDLDataOneOf; |
| 91 | class TDLFacetExpression; |
| 92 | class TDLFacetMinInclusive; |
| 93 | class TDLFacetMinExclusive; |
| 94 | class TDLFacetMaxInclusive; |
| 95 | class TDLFacetMaxExclusive; |
| 96 | //class TDLFacetLength; |
| 97 | //class TDLFacetMinLength; |
| 98 | //class TDLFacetMaxLength; |
| 99 | //class TDLFacetPattern; |
| 100 | //class TDLFacetLangRange; |
| 101 | |
| 102 | /// general visitor for DL expressions |
| 103 | class DLExpressionVisitor |
| 104 | { |
| 105 | public: // visitor interface |
| 106 | // concept expressions |
| 107 | virtual void visit ( const TDLConceptTop& expr ) = 0; |
| 108 | virtual void visit ( const TDLConceptBottom& expr ) = 0; |
| 109 | virtual void visit ( const TDLConceptName& expr ) = 0; |
| 110 | virtual void visit ( const TDLConceptNot& expr ) = 0; |
| 111 | virtual void visit ( const TDLConceptAnd& expr ) = 0; |
| 112 | virtual void visit ( const TDLConceptOr& expr ) = 0; |
| 113 | virtual void visit ( const TDLConceptOneOf& expr ) = 0; |
| 114 | virtual void visit ( const TDLConceptObjectSelf& expr ) = 0; |
| 115 | virtual void visit ( const TDLConceptObjectValue& expr ) = 0; |
| 116 | virtual void visit ( const TDLConceptObjectExists& expr ) = 0; |
| 117 | virtual void visit ( const TDLConceptObjectForall& expr ) = 0; |
| 118 | virtual void visit ( const TDLConceptObjectMinCardinality& expr ) = 0; |
| 119 | virtual void visit ( const TDLConceptObjectMaxCardinality& expr ) = 0; |
| 120 | virtual void visit ( const TDLConceptObjectExactCardinality& expr ) = 0; |
| 121 | virtual void visit ( const TDLConceptDataValue& expr ) = 0; |
| 122 | virtual void visit ( const TDLConceptDataExists& expr ) = 0; |
| 123 | virtual void visit ( const TDLConceptDataForall& expr ) = 0; |
| 124 | virtual void visit ( const TDLConceptDataMinCardinality& expr ) = 0; |
| 125 | virtual void visit ( const TDLConceptDataMaxCardinality& expr ) = 0; |
| 126 | virtual void visit ( const TDLConceptDataExactCardinality& expr ) = 0; |
| 127 | |
| 128 | // individual expressions |
| 129 | virtual void visit ( const TDLIndividualName& expr ) = 0; |
| 130 | |
| 131 | // object role expressions |
| 132 | virtual void visit ( const TDLObjectRoleTop& expr ) = 0; |
| 133 | virtual void visit ( const TDLObjectRoleBottom& expr ) = 0; |
| 134 | virtual void visit ( const TDLObjectRoleName& expr ) = 0; |
| 135 | virtual void visit ( const TDLObjectRoleInverse& expr ) = 0; |
| 136 | virtual void visit ( const TDLObjectRoleChain& expr ) = 0; |
| 137 | virtual void visit ( const TDLObjectRoleProjectionFrom& expr ) = 0; |
| 138 | virtual void visit ( const TDLObjectRoleProjectionInto& expr ) = 0; |
| 139 | |
| 140 | // data role expressions |
| 141 | virtual void visit ( const TDLDataRoleTop& expr ) = 0; |
| 142 | virtual void visit ( const TDLDataRoleBottom& expr ) = 0; |
| 143 | virtual void visit ( const TDLDataRoleName& expr ) = 0; |
| 144 | |
| 145 | // data expressions |
| 146 | virtual void visit ( const TDLDataTop& expr ) = 0; |
| 147 | virtual void visit ( const TDLDataBottom& expr ) = 0; |
| 148 | virtual void visit ( const TDLDataTypeName& expr ) = 0; |
| 149 | virtual void visit ( const TDLDataTypeRestriction& expr ) = 0; |
| 150 | virtual void visit ( const TDLDataValue& expr ) = 0; |
| 151 | virtual void visit ( const TDLDataNot& expr ) = 0; |
| 152 | virtual void visit ( const TDLDataAnd& expr ) = 0; |
| 153 | virtual void visit ( const TDLDataOr& expr ) = 0; |
| 154 | virtual void visit ( const TDLDataOneOf& expr ) = 0; |
| 155 | |
| 156 | // facets |
| 157 | virtual void visit ( const TDLFacetMinInclusive& expr ) = 0; |
| 158 | virtual void visit ( const TDLFacetMinExclusive& expr ) = 0; |
| 159 | virtual void visit ( const TDLFacetMaxInclusive& expr ) = 0; |
| 160 | virtual void visit ( const TDLFacetMaxExclusive& expr ) = 0; |
| 161 | |
| 162 | // other methods |
| 163 | virtual ~DLExpressionVisitor() = default; |
| 164 | }; // DLExpressionVisitor |
| 165 | |
| 166 | /// empty visitor for DL expressions implementation |
| 167 | class DLExpressionVisitorEmpty: public DLExpressionVisitor |
| 168 | { |
| 169 | public: // visitor interface |
| 170 | // concept expressions |
| 171 | void visit ( const TDLConceptTop& ) override {} |
| 172 | void visit ( const TDLConceptBottom& ) override {} |
| 173 | void visit ( const TDLConceptName& ) override {} |
| 174 | void visit ( const TDLConceptNot& ) override {} |
| 175 | void visit ( const TDLConceptAnd& ) override {} |
| 176 | void visit ( const TDLConceptOr& ) override {} |
| 177 | void visit ( const TDLConceptOneOf& ) override {} |
| 178 | void visit ( const TDLConceptObjectSelf& ) override {} |
| 179 | void visit ( const TDLConceptObjectValue& ) override {} |
| 180 | void visit ( const TDLConceptObjectExists& ) override {} |
| 181 | void visit ( const TDLConceptObjectForall& ) override {} |
| 182 | void visit ( const TDLConceptObjectMinCardinality& ) override {} |
| 183 | void visit ( const TDLConceptObjectMaxCardinality& ) override {} |
| 184 | void visit ( const TDLConceptObjectExactCardinality& ) override {} |
| 185 | void visit ( const TDLConceptDataValue& ) override {} |
| 186 | void visit ( const TDLConceptDataExists& ) override {} |
| 187 | void visit ( const TDLConceptDataForall& ) override {} |
| 188 | void visit ( const TDLConceptDataMinCardinality& ) override {} |
| 189 | void visit ( const TDLConceptDataMaxCardinality& ) override {} |
| 190 | void visit ( const TDLConceptDataExactCardinality& ) override {} |
| 191 | |
| 192 | // individual expressions |
| 193 | void visit ( const TDLIndividualName& ) override {} |
| 194 | |
| 195 | // object role expressions |
| 196 | void visit ( const TDLObjectRoleTop& ) override {} |
| 197 | void visit ( const TDLObjectRoleBottom& ) override {} |
| 198 | void visit ( const TDLObjectRoleName& ) override {} |
| 199 | void visit ( const TDLObjectRoleInverse& ) override {} |
| 200 | void visit ( const TDLObjectRoleChain& ) override {} |
| 201 | void visit ( const TDLObjectRoleProjectionFrom& ) override {} |
| 202 | void visit ( const TDLObjectRoleProjectionInto& ) override {} |
| 203 | |
| 204 | // data role expressions |
| 205 | void visit ( const TDLDataRoleTop& ) override {} |
| 206 | void visit ( const TDLDataRoleBottom& ) override {} |
| 207 | void visit ( const TDLDataRoleName& ) override {} |
| 208 | |
| 209 | // data expressions |
| 210 | void visit ( const TDLDataTop& ) override {} |
| 211 | void visit ( const TDLDataBottom& ) override {} |
| 212 | void visit ( const TDLDataTypeName& ) override {} |
| 213 | void visit ( const TDLDataTypeRestriction& ) override {} |
| 214 | void visit ( const TDLDataValue& ) override {} |
| 215 | void visit ( const TDLDataNot& ) override {} |
| 216 | void visit ( const TDLDataAnd& ) override {} |
| 217 | void visit ( const TDLDataOr& ) override {} |
| 218 | void visit ( const TDLDataOneOf& ) override {} |
| 219 | |
| 220 | // facets |
| 221 | void visit ( const TDLFacetMinInclusive& ) override {} |
| 222 | void visit ( const TDLFacetMinExclusive& ) override {} |
| 223 | void visit ( const TDLFacetMaxInclusive& ) override {} |
| 224 | void visit ( const TDLFacetMaxExclusive& ) override {} |
| 225 | }; // DLExpressionVisitorEmpty |
| 226 | |
| 227 | |
| 228 | /// base class for the DL expression, which include concept-, (data)role-, individual-, and data ones |
| 229 | class TDLExpression |
| 230 | { |
| 231 | public: // interface |
| 232 | /// empty c'tor |
| 233 | TDLExpression() = default; |
| 234 | /// empty d'tor: note that no deep delete is necessary as all the elements are RO |
| 235 | virtual ~TDLExpression() = default; |
| 236 | |
| 237 | /// accept method for the visitor pattern |
| 238 | virtual void accept ( DLExpressionVisitor& visitor ) const = 0; |
| 239 | }; // TDLExpression |
| 240 | |
| 241 | |
| 242 | //------------------------------------------------------------------ |
| 243 | // helper classes |
| 244 | //------------------------------------------------------------------ |
| 245 | |
| 246 | class TNamedEntry; |
| 247 | |
| 248 | //------------------------------------------------------------------ |
| 249 | /// named entity |
| 250 | //------------------------------------------------------------------ |
| 251 | class TNamedEntity |
| 252 | { |
| 253 | protected: // members |
| 254 | /// name of the entity |
| 255 | std::string Name; |
| 256 | /// translated version of it |
| 257 | TNamedEntry* entry = nullptr; |
| 258 | |
| 259 | public: // interface |
| 260 | /// c'tor: initialise name |
| 261 | explicit TNamedEntity ( const std::string& name ) : Name(name) {} |
| 262 | /// empty d'tor |
| 263 | virtual ~TNamedEntity() = default; |
| 264 | |
| 265 | /// get access to the name |
| 266 | const char* getName ( void ) const { return Name.c_str(); } |
| 267 | /// get access to the element itself |
| 268 | const TNamedEntity* getEntity ( void ) const { return this; } |
| 269 | |
| 270 | /// set entry |
| 271 | void setEntry ( TNamedEntry* e ) { entry = e; } |
| 272 | /// get entry |
| 273 | TNamedEntry* getEntry ( void ) const { return entry; } |
| 274 | }; // TNamedEntity |
| 275 | |
| 276 | //------------------------------------------------------------------ |
| 277 | /// concept argument |
| 278 | //------------------------------------------------------------------ |
| 279 | class TConceptArg |
| 280 | { |
| 281 | protected: // members |
| 282 | /// concept argument |
| 283 | const TDLConceptExpression* C; |
| 284 | |
| 285 | public: // interface |
| 286 | /// init c'tor |
| 287 | explicit TConceptArg ( const TDLConceptExpression* c ) : C(c) {} |
| 288 | /// empty d'tor |
| 289 | virtual ~TConceptArg() = default; |
| 290 | |
| 291 | /// get access to the argument |
| 292 | const TDLConceptExpression* getC ( void ) const { return C; } |
| 293 | }; // TConceptArg |
| 294 | |
| 295 | //------------------------------------------------------------------ |
| 296 | /// individual argument |
| 297 | //------------------------------------------------------------------ |
| 298 | class TIndividualArg |
| 299 | { |
| 300 | protected: // members |
| 301 | /// individual argument |
| 302 | const TDLIndividualExpression* I; |
| 303 | |
| 304 | public: // interface |
| 305 | /// init c'tor |
| 306 | explicit TIndividualArg ( const TDLIndividualExpression* i ) : I(i) {} |
| 307 | /// empty d'tor |
| 308 | virtual ~TIndividualArg() = default; |
| 309 | |
| 310 | /// get access to the argument |
| 311 | const TDLIndividualExpression* getI ( void ) const { return I; } |
| 312 | }; // TIndividualArg |
| 313 | |
| 314 | //------------------------------------------------------------------ |
| 315 | /// numerical argument |
| 316 | //------------------------------------------------------------------ |
| 317 | class TNumberArg |
| 318 | { |
| 319 | protected: // members |
| 320 | /// number argument |
| 321 | unsigned int N; |
| 322 | |
| 323 | public: // interface |
| 324 | /// init c'tor |
| 325 | explicit TNumberArg ( unsigned int n ) : N(n) {} |
| 326 | /// empty d'tor |
| 327 | virtual ~TNumberArg() = default; |
| 328 | |
| 329 | /// get access to the argument |
| 330 | unsigned int getNumber ( void ) const { return N; } |
| 331 | }; // TNumberArg |
| 332 | |
| 333 | //------------------------------------------------------------------ |
| 334 | /// object role argument |
| 335 | //------------------------------------------------------------------ |
| 336 | class TObjectRoleArg |
| 337 | { |
| 338 | protected: // members |
| 339 | /// object role argument |
| 340 | const TDLObjectRoleExpression* OR; |
| 341 | |
| 342 | public: // interface |
| 343 | /// init c'tor |
| 344 | explicit TObjectRoleArg ( const TDLObjectRoleExpression* oR ) : OR(oR) {} |
| 345 | /// empty d'tor |
| 346 | virtual ~TObjectRoleArg() = default; |
| 347 | |
| 348 | /// get access to the argument |
| 349 | const TDLObjectRoleExpression* getOR ( void ) const { return OR; } |
| 350 | }; // TObjectRoleArg |
| 351 | |
| 352 | //------------------------------------------------------------------ |
| 353 | /// data role argument |
| 354 | //------------------------------------------------------------------ |
| 355 | class TDataRoleArg |
| 356 | { |
| 357 | protected: // members |
| 358 | /// data role argument |
| 359 | const TDLDataRoleExpression* DR; |
| 360 | |
| 361 | public: // interface |
| 362 | /// init c'tor |
| 363 | explicit TDataRoleArg ( const TDLDataRoleExpression* dR ) : DR(dR) {} |
| 364 | /// empty d'tor |
| 365 | virtual ~TDataRoleArg() = default; |
| 366 | |
| 367 | /// get access to the argument |
| 368 | const TDLDataRoleExpression* getDR ( void ) const { return DR; } |
| 369 | }; // TDataRoleArg |
| 370 | |
| 371 | //------------------------------------------------------------------ |
| 372 | /// data expression argument (parameterised with the exact type) |
| 373 | //------------------------------------------------------------------ |
| 374 | template <typename TExpression> |
| 375 | class TDataExpressionArg |
| 376 | { |
| 377 | protected: // members |
| 378 | /// data expression argument |
| 379 | const TExpression* Expr; |
| 380 | |
| 381 | public: // interface |
| 382 | /// init c'tor |
| 383 | explicit TDataExpressionArg ( const TExpression* expr ) : Expr(expr) {} |
| 384 | /// empty d'tor |
| 385 | virtual ~TDataExpressionArg() = default; |
| 386 | |
| 387 | /// get access to the argument |
| 388 | const TExpression* getExpr ( void ) const { return Expr; } |
| 389 | }; // TDataExpressionArg |
| 390 | |
| 391 | //------------------------------------------------------------------ |
| 392 | /// general n-argument expression |
| 393 | //------------------------------------------------------------------ |
| 394 | template <typename Argument> |
| 395 | class TDLNAryExpression |
| 396 | { |
| 397 | public: // types |
| 398 | /// base type |
| 399 | typedef std::vector<const Argument*> ArgumentArray; |
| 400 | /// RW iterator over base type |
| 401 | typedef typename ArgumentArray::const_iterator iterator; |
| 402 | /// input array type |
| 403 | typedef std::vector<const TDLExpression*> ExpressionArray; |
| 404 | /// RW input iterator |
| 405 | typedef ExpressionArray::const_iterator i_iterator; |
| 406 | |
| 407 | protected: // members |
| 408 | /// set of equivalent concept descriptions |
| 409 | ArgumentArray Base; |
| 410 | /// name for exception depending on class name and direction |
| 411 | std::string EString; |
| 412 | |
| 413 | protected: // methods |
| 414 | /// transform general expression into the argument one |
| 415 | const Argument* transform ( const TDLExpression* arg ) const |
| 416 | { |
| 417 | const Argument* p = dynamic_cast<const Argument*>(arg); |
| 418 | if ( p == nullptr ) |
| 419 | throw EFaCTPlusPlus(EString.c_str()); |
| 420 | return p; |
| 421 | } |
| 422 | |
| 423 | public: // interface |
| 424 | /// c'tor: build an error string |
| 425 | TDLNAryExpression ( const char* typeName, const char* className ) |
| 426 | { |
| 427 | EString = "Expected "; |
| 428 | EString += typeName; |
| 429 | EString += " argument in the '"; |
| 430 | EString += className; |
| 431 | EString += "' expression"; |
| 432 | } |
| 433 | /// empty d'tor |
| 434 | virtual ~TDLNAryExpression() = default; |
| 435 | |
| 436 | /// @return true iff the expression has no elements |
| 437 | bool empty ( void ) const { return Base.empty(); } |
| 438 | /// @return number of elements |
| 439 | size_t size ( void ) const { return Base.size(); } |
| 440 | |
| 441 | // add elements to the array |
| 442 | |
| 443 | /// add a single element to the array |
| 444 | void add ( const TDLExpression* p ) { Base.push_back(transform(p)); } |
| 445 | /// add a range to the array |
| 446 | void add ( i_iterator b, i_iterator e ) |
| 447 | { |
| 448 | for ( ; b != e; ++b ) |
| 449 | add(*b); |
| 450 | } |
| 451 | /// add a vector |
| 452 | void add ( const ExpressionArray& v ) { add ( v.begin(), v.end() ); } |
| 453 | |
| 454 | // access to members |
| 455 | |
| 456 | /// RW begin iterator for array |
| 457 | iterator begin ( void ) const { return Base.begin(); } |
| 458 | /// RW end iterator for array |
| 459 | iterator end ( void ) const { return Base.end(); } |
| 460 | }; // TDLNAryExpression |
| 461 | |
| 462 | |
| 463 | //------------------------------------------------------------------ |
| 464 | // concept expressions |
| 465 | //------------------------------------------------------------------ |
| 466 | |
| 467 | |
| 468 | //------------------------------------------------------------------ |
| 469 | /// general concept expression |
| 470 | //------------------------------------------------------------------ |
| 471 | class TDLConceptExpression: public TDLExpression |
| 472 | { |
| 473 | public: // interface |
| 474 | /// accept method for the visitor pattern |
| 475 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 476 | }; // TDLConceptExpression |
| 477 | |
| 478 | //------------------------------------------------------------------ |
| 479 | /// concept TOP expression |
| 480 | //------------------------------------------------------------------ |
| 481 | class TDLConceptTop: public TDLConceptExpression |
| 482 | { |
| 483 | public: // interface |
| 484 | /// accept method for the visitor pattern |
| 485 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 486 | }; // TDLConceptTop |
| 487 | |
| 488 | //------------------------------------------------------------------ |
| 489 | /// concept BOTTOM expression |
| 490 | //------------------------------------------------------------------ |
| 491 | class TDLConceptBottom: public TDLConceptExpression |
| 492 | { |
| 493 | public: // interface |
| 494 | /// accept method for the visitor pattern |
| 495 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 496 | }; // TDLConceptBottom |
| 497 | |
| 498 | //------------------------------------------------------------------ |
| 499 | /// named concept expression |
| 500 | //------------------------------------------------------------------ |
| 501 | class TDLConceptName: public TDLConceptExpression, public TNamedEntity |
| 502 | { |
| 503 | public: // interface |
| 504 | /// init c'tor |
| 505 | explicit TDLConceptName ( const std::string& name ) : TDLConceptExpression(), TNamedEntity(name) {} |
| 506 | |
| 507 | /// accept method for the visitor pattern |
| 508 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 509 | }; // TDLConceptName |
| 510 | |
| 511 | //------------------------------------------------------------------ |
| 512 | /// concept NOT expression |
| 513 | //------------------------------------------------------------------ |
| 514 | class TDLConceptNot: public TDLConceptExpression, public TConceptArg |
| 515 | { |
| 516 | public: // interface |
| 517 | /// init c'tor |
| 518 | explicit TDLConceptNot ( const TDLConceptExpression* C ) |
| 519 | : TDLConceptExpression() |
| 520 | , TConceptArg(C) |
| 521 | {} |
| 522 | |
| 523 | /// accept method for the visitor pattern |
| 524 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 525 | }; // TDLConceptNot |
| 526 | |
| 527 | //------------------------------------------------------------------ |
| 528 | /// concept AND expression |
| 529 | //------------------------------------------------------------------ |
| 530 | class TDLConceptAnd: public TDLConceptExpression, public TDLNAryExpression<TDLConceptExpression> |
| 531 | { |
| 532 | public: // interface |
| 533 | /// init c'tor: create AND of expressions from the given array |
| 534 | explicit TDLConceptAnd ( const ExpressionArray& v ) |
| 535 | : TDLConceptExpression() |
| 536 | , TDLNAryExpression<TDLConceptExpression>("concept expression","AND") |
| 537 | { |
| 538 | add(v); |
| 539 | } |
| 540 | |
| 541 | /// comparison for AND |
| 542 | bool operator == ( const TDLConceptAnd& expr ) const |
| 543 | { |
| 544 | if ( size() != expr.size() ) |
| 545 | return false; |
| 546 | for ( iterator p = begin(), q = expr.begin(), p_end = end(); p != p_end; ++p, ++q ) |
| 547 | if ( *p != *q ) |
| 548 | return false; |
| 549 | return true; |
| 550 | } |
| 551 | /// accept method for the visitor pattern |
| 552 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 553 | }; // TDLConceptAnd |
| 554 | |
| 555 | //------------------------------------------------------------------ |
| 556 | /// concept OR expression |
| 557 | //------------------------------------------------------------------ |
| 558 | class TDLConceptOr: public TDLConceptExpression, public TDLNAryExpression<TDLConceptExpression> |
| 559 | { |
| 560 | public: // interface |
| 561 | /// init c'tor: create OR of expressions from the given array |
| 562 | explicit TDLConceptOr ( const ExpressionArray& v ) |
| 563 | : TDLConceptExpression() |
| 564 | , TDLNAryExpression<TDLConceptExpression>("concept expression","OR") |
| 565 | { |
| 566 | add(v); |
| 567 | } |
| 568 | |
| 569 | /// accept method for the visitor pattern |
| 570 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 571 | }; // TDLConceptOr |
| 572 | |
| 573 | //------------------------------------------------------------------ |
| 574 | /// concept one-of expression |
| 575 | //------------------------------------------------------------------ |
| 576 | class TDLConceptOneOf: public TDLConceptExpression, public TDLNAryExpression<TDLIndividualName> |
| 577 | { |
| 578 | public: // interface |
| 579 | /// init c'tor: create one-of from individuals in the given array |
| 580 | explicit TDLConceptOneOf ( const ExpressionArray& v ) |
| 581 | : TDLConceptExpression() |
| 582 | , TDLNAryExpression<TDLIndividualName>("individual name","OneOf") |
| 583 | { |
| 584 | add(v); |
| 585 | } |
| 586 | |
| 587 | /// accept method for the visitor pattern |
| 588 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 589 | }; // TDLConceptOneOf |
| 590 | |
| 591 | //------------------------------------------------------------------ |
| 592 | /// general concept expression that contains an object role |
| 593 | //------------------------------------------------------------------ |
| 594 | class TDLConceptObjectRoleExpression: public TDLConceptExpression, public TObjectRoleArg |
| 595 | { |
| 596 | public: // interface |
| 597 | /// init c'tor |
| 598 | explicit TDLConceptObjectRoleExpression ( const TDLObjectRoleExpression* R ) |
| 599 | : TDLConceptExpression() |
| 600 | , TObjectRoleArg(R) |
| 601 | {} |
| 602 | |
| 603 | /// accept method for the visitor pattern |
| 604 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 605 | }; // TDLConceptObjectRoleExpression |
| 606 | |
| 607 | //------------------------------------------------------------------ |
| 608 | /// concept self-ref expression |
| 609 | //------------------------------------------------------------------ |
| 610 | class TDLConceptObjectSelf: public TDLConceptObjectRoleExpression |
| 611 | { |
| 612 | public: // interface |
| 613 | /// init c'tor |
| 614 | explicit TDLConceptObjectSelf ( const TDLObjectRoleExpression* R ) |
| 615 | : TDLConceptObjectRoleExpression(R) |
| 616 | {} |
| 617 | |
| 618 | /// accept method for the visitor pattern |
| 619 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 620 | }; // TDLConceptObjectSelf |
| 621 | |
| 622 | //------------------------------------------------------------------ |
| 623 | /// concept some value restriction expression |
| 624 | //------------------------------------------------------------------ |
| 625 | class TDLConceptObjectValue: public TDLConceptObjectRoleExpression, public TIndividualArg |
| 626 | { |
| 627 | public: // interface |
| 628 | /// init c'tor |
| 629 | TDLConceptObjectValue ( const TDLObjectRoleExpression* R, const TDLIndividualExpression* I ) |
| 630 | : TDLConceptObjectRoleExpression(R) |
| 631 | , TIndividualArg(I) |
| 632 | {} |
| 633 | |
| 634 | /// accept method for the visitor pattern |
| 635 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 636 | }; // TDLConceptObjectValue |
| 637 | |
| 638 | //------------------------------------------------------------------ |
| 639 | /// general concept expression that contains an object role and a class expression |
| 640 | //------------------------------------------------------------------ |
| 641 | class TDLConceptObjectRCExpression: public TDLConceptObjectRoleExpression, public TConceptArg |
| 642 | { |
| 643 | public: // interface |
| 644 | /// init c'tor |
| 645 | TDLConceptObjectRCExpression ( const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 646 | : TDLConceptObjectRoleExpression(R) |
| 647 | , TConceptArg(C) |
| 648 | {} |
| 649 | |
| 650 | /// accept method for the visitor pattern |
| 651 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 652 | }; // TDLConceptObjectRCExpression |
| 653 | |
| 654 | //------------------------------------------------------------------ |
| 655 | /// concept object existential restriction expression |
| 656 | //------------------------------------------------------------------ |
| 657 | class TDLConceptObjectExists: public TDLConceptObjectRCExpression |
| 658 | { |
| 659 | public: // interface |
| 660 | /// init c'tor |
| 661 | TDLConceptObjectExists ( const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 662 | : TDLConceptObjectRCExpression(R,C) |
| 663 | {} |
| 664 | |
| 665 | /// accept method for the visitor pattern |
| 666 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 667 | }; // TDLConceptObjectExists |
| 668 | |
| 669 | //------------------------------------------------------------------ |
| 670 | /// concept object universal restriction expression |
| 671 | //------------------------------------------------------------------ |
| 672 | class TDLConceptObjectForall: public TDLConceptObjectRCExpression |
| 673 | { |
| 674 | public: // interface |
| 675 | /// init c'tor |
| 676 | TDLConceptObjectForall ( const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 677 | : TDLConceptObjectRCExpression(R,C) |
| 678 | {} |
| 679 | |
| 680 | /// accept method for the visitor pattern |
| 681 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 682 | }; // TDLConceptObjectForall |
| 683 | |
| 684 | //------------------------------------------------------------------ |
| 685 | /// general object role cardinality expression |
| 686 | //------------------------------------------------------------------ |
| 687 | class TDLConceptObjectCardinalityExpression: public TDLConceptObjectRCExpression, public TNumberArg |
| 688 | { |
| 689 | public: // interface |
| 690 | /// init c'tor |
| 691 | TDLConceptObjectCardinalityExpression ( unsigned int n, const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 692 | : TDLConceptObjectRCExpression(R,C) |
| 693 | , TNumberArg(n) |
| 694 | {} |
| 695 | |
| 696 | /// accept method for the visitor pattern |
| 697 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 698 | }; // TDLConceptObjectCardinalityExpression |
| 699 | |
| 700 | //------------------------------------------------------------------ |
| 701 | /// concept object min cardinality expression |
| 702 | //------------------------------------------------------------------ |
| 703 | class TDLConceptObjectMinCardinality: public TDLConceptObjectCardinalityExpression |
| 704 | { |
| 705 | public: // interface |
| 706 | /// init c'tor |
| 707 | TDLConceptObjectMinCardinality ( unsigned int n, const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 708 | : TDLConceptObjectCardinalityExpression(n,R,C) |
| 709 | {} |
| 710 | |
| 711 | /// accept method for the visitor pattern |
| 712 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 713 | }; // TDLConceptObjectMinCardinality |
| 714 | |
| 715 | //------------------------------------------------------------------ |
| 716 | /// concept object max cardinality expression |
| 717 | //------------------------------------------------------------------ |
| 718 | class TDLConceptObjectMaxCardinality: public TDLConceptObjectCardinalityExpression |
| 719 | { |
| 720 | public: // interface |
| 721 | /// init c'tor |
| 722 | TDLConceptObjectMaxCardinality ( unsigned int n, const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 723 | : TDLConceptObjectCardinalityExpression(n,R,C) |
| 724 | {} |
| 725 | |
| 726 | /// accept method for the visitor pattern |
| 727 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 728 | }; // TDLConceptObjectMaxCardinality |
| 729 | |
| 730 | //------------------------------------------------------------------ |
| 731 | /// concept object exact cardinality expression |
| 732 | //------------------------------------------------------------------ |
| 733 | class TDLConceptObjectExactCardinality: public TDLConceptObjectCardinalityExpression |
| 734 | { |
| 735 | public: // interface |
| 736 | /// init c'tor |
| 737 | TDLConceptObjectExactCardinality ( unsigned int n, const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 738 | : TDLConceptObjectCardinalityExpression(n,R,C) |
| 739 | {} |
| 740 | |
| 741 | /// accept method for the visitor pattern |
| 742 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 743 | }; // TDLConceptObjectExactCardinality |
| 744 | |
| 745 | //------------------------------------------------------------------ |
| 746 | /// general concept expression that contains an data role |
| 747 | //------------------------------------------------------------------ |
| 748 | class TDLConceptDataRoleExpression: public TDLConceptExpression, public TDataRoleArg |
| 749 | { |
| 750 | public: // interface |
| 751 | /// init c'tor |
| 752 | explicit TDLConceptDataRoleExpression ( const TDLDataRoleExpression* R ) |
| 753 | : TDLConceptExpression() |
| 754 | , TDataRoleArg(R) |
| 755 | {} |
| 756 | |
| 757 | /// accept method for the visitor pattern |
| 758 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 759 | }; // TDLConceptDataRoleExpression |
| 760 | |
| 761 | //------------------------------------------------------------------ |
| 762 | /// concept some value restriction expression |
| 763 | //------------------------------------------------------------------ |
| 764 | class TDLConceptDataValue: public TDLConceptDataRoleExpression, public TDataExpressionArg<TDLDataValue> |
| 765 | { |
| 766 | public: // interface |
| 767 | /// init c'tor |
| 768 | TDLConceptDataValue ( const TDLDataRoleExpression* R, const TDLDataValue* V ) |
| 769 | : TDLConceptDataRoleExpression(R) |
| 770 | , TDataExpressionArg<TDLDataValue>(V) |
| 771 | {} |
| 772 | |
| 773 | /// accept method for the visitor pattern |
| 774 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 775 | }; // TDLConceptDataValue |
| 776 | |
| 777 | //------------------------------------------------------------------ |
| 778 | /// general concept expression that contains an data role and a data expression |
| 779 | //------------------------------------------------------------------ |
| 780 | class TDLConceptDataRVExpression: public TDLConceptDataRoleExpression, public TDataExpressionArg<TDLDataExpression> |
| 781 | { |
| 782 | public: // interface |
| 783 | /// init c'tor |
| 784 | TDLConceptDataRVExpression ( const TDLDataRoleExpression* R, const TDLDataExpression* E ) |
| 785 | : TDLConceptDataRoleExpression(R) |
| 786 | , TDataExpressionArg<TDLDataExpression>(E) |
| 787 | {} |
| 788 | |
| 789 | /// accept method for the visitor pattern |
| 790 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 791 | }; // TDLConceptDataRVExpression |
| 792 | |
| 793 | //------------------------------------------------------------------ |
| 794 | /// concept data existential restriction expression |
| 795 | //------------------------------------------------------------------ |
| 796 | class TDLConceptDataExists: public TDLConceptDataRVExpression |
| 797 | { |
| 798 | public: // interface |
| 799 | /// init c'tor |
| 800 | TDLConceptDataExists ( const TDLDataRoleExpression* R, const TDLDataExpression* E ) |
| 801 | : TDLConceptDataRVExpression(R,E) |
| 802 | {} |
| 803 | |
| 804 | /// accept method for the visitor pattern |
| 805 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 806 | }; // TDLConceptDataExists |
| 807 | |
| 808 | //------------------------------------------------------------------ |
| 809 | /// concept data universal restriction expression |
| 810 | //------------------------------------------------------------------ |
| 811 | class TDLConceptDataForall: public TDLConceptDataRVExpression |
| 812 | { |
| 813 | public: // interface |
| 814 | /// init c'tor |
| 815 | TDLConceptDataForall ( const TDLDataRoleExpression* R, const TDLDataExpression* E ) |
| 816 | : TDLConceptDataRVExpression(R,E) |
| 817 | {} |
| 818 | |
| 819 | /// accept method for the visitor pattern |
| 820 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 821 | }; // TDLConceptDataForall |
| 822 | |
| 823 | //------------------------------------------------------------------ |
| 824 | /// general data role cardinality expression |
| 825 | //------------------------------------------------------------------ |
| 826 | class TDLConceptDataCardinalityExpression: public TDLConceptDataRVExpression, public TNumberArg |
| 827 | { |
| 828 | public: // interface |
| 829 | /// init c'tor |
| 830 | TDLConceptDataCardinalityExpression ( unsigned int n, const TDLDataRoleExpression* R, const TDLDataExpression* E ) |
| 831 | : TDLConceptDataRVExpression(R,E) |
| 832 | , TNumberArg(n) |
| 833 | {} |
| 834 | |
| 835 | /// accept method for the visitor pattern |
| 836 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 837 | }; // TDLConceptDataCardinalityExpression |
| 838 | |
| 839 | //------------------------------------------------------------------ |
| 840 | /// concept data min cardinality expression |
| 841 | //------------------------------------------------------------------ |
| 842 | class TDLConceptDataMinCardinality: public TDLConceptDataCardinalityExpression |
| 843 | { |
| 844 | public: // interface |
| 845 | /// init c'tor |
| 846 | TDLConceptDataMinCardinality ( unsigned int n, const TDLDataRoleExpression* R, const TDLDataExpression* E ) |
| 847 | : TDLConceptDataCardinalityExpression(n,R,E) |
| 848 | {} |
| 849 | |
| 850 | /// accept method for the visitor pattern |
| 851 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 852 | }; // TDLConceptDataMinCardinality |
| 853 | |
| 854 | //------------------------------------------------------------------ |
| 855 | /// concept data max cardinality expression |
| 856 | //------------------------------------------------------------------ |
| 857 | class TDLConceptDataMaxCardinality: public TDLConceptDataCardinalityExpression |
| 858 | { |
| 859 | public: // interface |
| 860 | /// init c'tor |
| 861 | TDLConceptDataMaxCardinality ( unsigned int n, const TDLDataRoleExpression* R, const TDLDataExpression* E ) |
| 862 | : TDLConceptDataCardinalityExpression(n,R,E) |
| 863 | {} |
| 864 | |
| 865 | /// accept method for the visitor pattern |
| 866 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 867 | }; // TDLConceptDataMaxCardinality |
| 868 | |
| 869 | //------------------------------------------------------------------ |
| 870 | /// concept data exact cardinality expression |
| 871 | //------------------------------------------------------------------ |
| 872 | class TDLConceptDataExactCardinality: public TDLConceptDataCardinalityExpression |
| 873 | { |
| 874 | public: // interface |
| 875 | /// init c'tor |
| 876 | TDLConceptDataExactCardinality ( unsigned int n, const TDLDataRoleExpression* R, const TDLDataExpression* E ) |
| 877 | : TDLConceptDataCardinalityExpression(n,R,E) |
| 878 | {} |
| 879 | |
| 880 | /// accept method for the visitor pattern |
| 881 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 882 | }; // TDLConceptDataExactCardinality |
| 883 | |
| 884 | |
| 885 | //------------------------------------------------------------------ |
| 886 | // individual expressions |
| 887 | //------------------------------------------------------------------ |
| 888 | |
| 889 | |
| 890 | //------------------------------------------------------------------ |
| 891 | /// general individual expression |
| 892 | //------------------------------------------------------------------ |
| 893 | class TDLIndividualExpression: public TDLExpression |
| 894 | { |
| 895 | public: // interface |
| 896 | /// accept method for the visitor pattern |
| 897 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 898 | }; // TDLIndividualExpression |
| 899 | |
| 900 | //------------------------------------------------------------------ |
| 901 | /// named individual expression |
| 902 | //------------------------------------------------------------------ |
| 903 | class TDLIndividualName: public TDLIndividualExpression, public TNamedEntity |
| 904 | { |
| 905 | public: // interface |
| 906 | /// init c'tor |
| 907 | explicit TDLIndividualName ( const std::string& name ) : TDLIndividualExpression(), TNamedEntity(name) {} |
| 908 | |
| 909 | /// accept method for the visitor pattern |
| 910 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 911 | }; // TDLIndividualName |
| 912 | |
| 913 | |
| 914 | //------------------------------------------------------------------ |
| 915 | // role expressions |
| 916 | //------------------------------------------------------------------ |
| 917 | |
| 918 | |
| 919 | //------------------------------------------------------------------ |
| 920 | /// general role expression |
| 921 | //------------------------------------------------------------------ |
| 922 | class TDLRoleExpression: public TDLExpression |
| 923 | { |
| 924 | public: // interface |
| 925 | /// accept method for the visitor pattern |
| 926 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 927 | }; // TDLRoleExpression |
| 928 | |
| 929 | |
| 930 | //------------------------------------------------------------------ |
| 931 | // object role expressions |
| 932 | //------------------------------------------------------------------ |
| 933 | |
| 934 | |
| 935 | //------------------------------------------------------------------ |
| 936 | /// complex object role expression (general expression, role chain or projection) |
| 937 | //------------------------------------------------------------------ |
| 938 | class TDLObjectRoleComplexExpression: public TDLRoleExpression |
| 939 | { |
| 940 | public: // interface |
| 941 | /// accept method for the visitor pattern |
| 942 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 943 | }; // TDLObjectRoleComplexExpression |
| 944 | |
| 945 | //------------------------------------------------------------------ |
| 946 | /// general object role expression |
| 947 | //------------------------------------------------------------------ |
| 948 | class TDLObjectRoleExpression: public TDLObjectRoleComplexExpression |
| 949 | { |
| 950 | public: // interface |
| 951 | /// accept method for the visitor pattern |
| 952 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 953 | }; // TDLObjectRoleExpression |
| 954 | |
| 955 | //------------------------------------------------------------------ |
| 956 | /// object role TOP expression |
| 957 | //------------------------------------------------------------------ |
| 958 | class TDLObjectRoleTop: public TDLObjectRoleExpression |
| 959 | { |
| 960 | public: // interface |
| 961 | /// accept method for the visitor pattern |
| 962 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 963 | }; // TDLObjectRoleTop |
| 964 | |
| 965 | //------------------------------------------------------------------ |
| 966 | /// object role BOTTOM expression |
| 967 | //------------------------------------------------------------------ |
| 968 | class TDLObjectRoleBottom: public TDLObjectRoleExpression |
| 969 | { |
| 970 | public: // interface |
| 971 | /// accept method for the visitor pattern |
| 972 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 973 | }; // TDLObjectRoleBottom |
| 974 | |
| 975 | //------------------------------------------------------------------ |
| 976 | /// named object role expression |
| 977 | //------------------------------------------------------------------ |
| 978 | class TDLObjectRoleName: public TDLObjectRoleExpression, public TNamedEntity |
| 979 | { |
| 980 | public: // interface |
| 981 | /// init c'tor |
| 982 | explicit TDLObjectRoleName ( const std::string& name ) : TDLObjectRoleExpression(), TNamedEntity(name) {} |
| 983 | |
| 984 | /// accept method for the visitor pattern |
| 985 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 986 | }; // TDLObjectRoleName |
| 987 | |
| 988 | //------------------------------------------------------------------ |
| 989 | /// inverse object role expression |
| 990 | //------------------------------------------------------------------ |
| 991 | class TDLObjectRoleInverse: public TDLObjectRoleExpression, public TObjectRoleArg |
| 992 | { |
| 993 | public: // interface |
| 994 | /// init c'tor |
| 995 | explicit TDLObjectRoleInverse ( const TDLObjectRoleExpression* R ) |
| 996 | : TDLObjectRoleExpression() |
| 997 | , TObjectRoleArg(R) |
| 998 | {} |
| 999 | |
| 1000 | /// accept method for the visitor pattern |
| 1001 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1002 | }; // TDLObjectRoleInverse |
| 1003 | |
| 1004 | //------------------------------------------------------------------ |
| 1005 | /// object role chain expression |
| 1006 | //------------------------------------------------------------------ |
| 1007 | class TDLObjectRoleChain: public TDLObjectRoleComplexExpression, public TDLNAryExpression<TDLObjectRoleExpression> |
| 1008 | { |
| 1009 | public: // interface |
| 1010 | /// init c'tor: create role chain from given array |
| 1011 | explicit TDLObjectRoleChain ( const ExpressionArray& v ) |
| 1012 | : TDLObjectRoleComplexExpression() |
| 1013 | , TDLNAryExpression<TDLObjectRoleExpression>("object role expression","role chain") |
| 1014 | { |
| 1015 | add(v); |
| 1016 | } |
| 1017 | |
| 1018 | /// accept method for the visitor pattern |
| 1019 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1020 | }; // TDLObjectRoleChain |
| 1021 | |
| 1022 | //------------------------------------------------------------------ |
| 1023 | /// object role projection from expression |
| 1024 | //------------------------------------------------------------------ |
| 1025 | class TDLObjectRoleProjectionFrom |
| 1026 | : public TDLObjectRoleComplexExpression |
| 1027 | , public TObjectRoleArg |
| 1028 | , public TConceptArg |
| 1029 | { |
| 1030 | public: // interface |
| 1031 | /// init c'tor |
| 1032 | TDLObjectRoleProjectionFrom ( const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 1033 | : TDLObjectRoleComplexExpression() |
| 1034 | , TObjectRoleArg(R) |
| 1035 | , TConceptArg(C) |
| 1036 | {} |
| 1037 | |
| 1038 | /// accept method for the visitor pattern |
| 1039 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1040 | }; // TDLObjectRoleProjectionFrom |
| 1041 | |
| 1042 | //------------------------------------------------------------------ |
| 1043 | /// object role projection from expression |
| 1044 | //------------------------------------------------------------------ |
| 1045 | class TDLObjectRoleProjectionInto |
| 1046 | : public TDLObjectRoleComplexExpression |
| 1047 | , public TObjectRoleArg |
| 1048 | , public TConceptArg |
| 1049 | { |
| 1050 | public: // interface |
| 1051 | /// init c'tor |
| 1052 | TDLObjectRoleProjectionInto ( const TDLObjectRoleExpression* R, const TDLConceptExpression* C ) |
| 1053 | : TDLObjectRoleComplexExpression() |
| 1054 | , TObjectRoleArg(R) |
| 1055 | , TConceptArg(C) |
| 1056 | {} |
| 1057 | |
| 1058 | /// accept method for the visitor pattern |
| 1059 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1060 | }; // TDLObjectRoleProjectionInto |
| 1061 | |
| 1062 | |
| 1063 | //------------------------------------------------------------------ |
| 1064 | // data role expressions |
| 1065 | //------------------------------------------------------------------ |
| 1066 | |
| 1067 | |
| 1068 | //------------------------------------------------------------------ |
| 1069 | /// general data role expression |
| 1070 | //------------------------------------------------------------------ |
| 1071 | class TDLDataRoleExpression: public TDLRoleExpression |
| 1072 | { |
| 1073 | public: // interface |
| 1074 | /// accept method for the visitor pattern |
| 1075 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 1076 | }; // TDLDataRoleExpression |
| 1077 | |
| 1078 | //------------------------------------------------------------------ |
| 1079 | /// data role TOP expression |
| 1080 | //------------------------------------------------------------------ |
| 1081 | class TDLDataRoleTop: public TDLDataRoleExpression |
| 1082 | { |
| 1083 | public: // interface |
| 1084 | /// accept method for the visitor pattern |
| 1085 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1086 | }; // TDLDataRoleTop |
| 1087 | |
| 1088 | //------------------------------------------------------------------ |
| 1089 | /// data role BOTTOM expression |
| 1090 | //------------------------------------------------------------------ |
| 1091 | class TDLDataRoleBottom: public TDLDataRoleExpression |
| 1092 | { |
| 1093 | public: // interface |
| 1094 | /// accept method for the visitor pattern |
| 1095 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1096 | }; // TDLDataRoleBottom |
| 1097 | |
| 1098 | //------------------------------------------------------------------ |
| 1099 | /// named data role expression |
| 1100 | //------------------------------------------------------------------ |
| 1101 | class TDLDataRoleName: public TDLDataRoleExpression, public TNamedEntity |
| 1102 | { |
| 1103 | public: // interface |
| 1104 | /// init c'tor |
| 1105 | explicit TDLDataRoleName ( const std::string& name ) : TDLDataRoleExpression(), TNamedEntity(name) {} |
| 1106 | |
| 1107 | /// accept method for the visitor pattern |
| 1108 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1109 | }; // TDLDataRoleName |
| 1110 | |
| 1111 | |
| 1112 | //------------------------------------------------------------------ |
| 1113 | // data expressions |
| 1114 | //------------------------------------------------------------------ |
| 1115 | |
| 1116 | |
| 1117 | //------------------------------------------------------------------ |
| 1118 | /// general data expression |
| 1119 | //------------------------------------------------------------------ |
| 1120 | class TDLDataExpression: public TDLExpression |
| 1121 | { |
| 1122 | public: // interface |
| 1123 | /// accept method for the visitor pattern |
| 1124 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 1125 | }; // TDLDataExpression |
| 1126 | |
| 1127 | //------------------------------------------------------------------ |
| 1128 | /// data TOP expression |
| 1129 | //------------------------------------------------------------------ |
| 1130 | class TDLDataTop: public TDLDataExpression |
| 1131 | { |
| 1132 | public: // interface |
| 1133 | /// accept method for the visitor pattern |
| 1134 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1135 | }; // TDLDataTop |
| 1136 | |
| 1137 | //------------------------------------------------------------------ |
| 1138 | /// data BOTTOM expression |
| 1139 | //------------------------------------------------------------------ |
| 1140 | class TDLDataBottom: public TDLDataExpression |
| 1141 | { |
| 1142 | public: // interface |
| 1143 | /// accept method for the visitor pattern |
| 1144 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1145 | }; // TDLDataBottom |
| 1146 | |
| 1147 | //------------------------------------------------------------------ |
| 1148 | /// general data type expression |
| 1149 | //------------------------------------------------------------------ |
| 1150 | class TDLDataTypeExpression: public TDLDataExpression |
| 1151 | { |
| 1152 | public: // interface |
| 1153 | /// accept method for the visitor pattern |
| 1154 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 1155 | }; // TDLDataTypeExpression |
| 1156 | |
| 1157 | //------------------------------------------------------------------ |
| 1158 | /// restricted data type expression |
| 1159 | //------------------------------------------------------------------ |
| 1160 | class TDLDataTypeRestriction: public TDLDataTypeExpression, public TDataExpressionArg<TDLDataTypeName>, public TDLNAryExpression<TDLFacetExpression> |
| 1161 | { |
| 1162 | public: // interface |
| 1163 | /// init c'tor |
| 1164 | explicit TDLDataTypeRestriction ( const TDLDataTypeName* T ) |
| 1165 | : TDLDataTypeExpression() |
| 1166 | , TDataExpressionArg<TDLDataTypeName>(T) |
| 1167 | , TDLNAryExpression<TDLFacetExpression>("facet expression","Datatype restriction") |
| 1168 | {} |
| 1169 | |
| 1170 | /// accept method for the visitor pattern |
| 1171 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1172 | }; // TDLDataTypeRestriction |
| 1173 | |
| 1174 | //------------------------------------------------------------------ |
| 1175 | /// data value expression |
| 1176 | //------------------------------------------------------------------ |
| 1177 | class TDLDataValue: public TDLDataExpression, public TNamedEntity, public TDataExpressionArg<TDLDataTypeExpression> |
| 1178 | { |
| 1179 | public: // interface |
| 1180 | /// fake c'tor (to make TNameSet happy); shouldn't be called |
| 1181 | explicit TDLDataValue ( const std::string& value ) |
| 1182 | : TDLDataExpression() |
| 1183 | , TNamedEntity(value) |
| 1184 | , TDataExpressionArg<TDLDataTypeExpression>(nullptr) |
| 1185 | { fpp_unreachable(); } |
| 1186 | /// init c'tor |
| 1187 | TDLDataValue ( const std::string& value, const TDLDataTypeExpression* T ) |
| 1188 | : TDLDataExpression() |
| 1189 | , TNamedEntity(value) |
| 1190 | , TDataExpressionArg<TDLDataTypeExpression>(T) |
| 1191 | {} |
| 1192 | |
| 1193 | /// accept method for the visitor pattern |
| 1194 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1195 | }; // TDLDataValue |
| 1196 | |
| 1197 | //------------------------------------------------------------------ |
| 1198 | /// data NOT expression |
| 1199 | //------------------------------------------------------------------ |
| 1200 | class TDLDataNot: public TDLDataExpression, public TDataExpressionArg<TDLDataExpression> |
| 1201 | { |
| 1202 | public: // interface |
| 1203 | /// init c'tor |
| 1204 | explicit TDLDataNot ( const TDLDataExpression* E ) |
| 1205 | : TDLDataExpression() |
| 1206 | , TDataExpressionArg<TDLDataExpression>(E) |
| 1207 | {} |
| 1208 | |
| 1209 | /// accept method for the visitor pattern |
| 1210 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1211 | }; // TDLDataNot |
| 1212 | |
| 1213 | //------------------------------------------------------------------ |
| 1214 | /// data AND expression |
| 1215 | //------------------------------------------------------------------ |
| 1216 | class TDLDataAnd: public TDLDataExpression, public TDLNAryExpression<TDLDataExpression> |
| 1217 | { |
| 1218 | public: // interface |
| 1219 | /// init c'tor: create AND of expressions from the given array |
| 1220 | explicit TDLDataAnd ( const ExpressionArray& v ) |
| 1221 | : TDLDataExpression() |
| 1222 | , TDLNAryExpression<TDLDataExpression>("data expression","data AND") |
| 1223 | { |
| 1224 | add(v); |
| 1225 | } |
| 1226 | |
| 1227 | /// accept method for the visitor pattern |
| 1228 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1229 | }; // TDLDataAnd |
| 1230 | |
| 1231 | //------------------------------------------------------------------ |
| 1232 | /// data OR expression |
| 1233 | //------------------------------------------------------------------ |
| 1234 | class TDLDataOr: public TDLDataExpression, public TDLNAryExpression<TDLDataExpression> |
| 1235 | { |
| 1236 | public: // interface |
| 1237 | /// init c'tor: create OR of expressions from the given array |
| 1238 | explicit TDLDataOr ( const ExpressionArray& v ) |
| 1239 | : TDLDataExpression() |
| 1240 | , TDLNAryExpression<TDLDataExpression>("data expression","data OR") |
| 1241 | { |
| 1242 | add(v); |
| 1243 | } |
| 1244 | |
| 1245 | /// accept method for the visitor pattern |
| 1246 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1247 | }; // TDLDataOr |
| 1248 | |
| 1249 | //------------------------------------------------------------------ |
| 1250 | /// data one-of expression |
| 1251 | //------------------------------------------------------------------ |
| 1252 | class TDLDataOneOf: public TDLDataExpression, public TDLNAryExpression<TDLDataValue> |
| 1253 | { |
| 1254 | public: // interface |
| 1255 | /// init c'tor: create one-of from individuals in the given array |
| 1256 | explicit TDLDataOneOf ( const ExpressionArray& v ) |
| 1257 | : TDLDataExpression() |
| 1258 | , TDLNAryExpression<TDLDataValue>("data value","data OneOf") |
| 1259 | { |
| 1260 | add(v); |
| 1261 | } |
| 1262 | |
| 1263 | /// accept method for the visitor pattern |
| 1264 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1265 | }; // TDLDataOneOf |
| 1266 | |
| 1267 | //------------------------------------------------------------------ |
| 1268 | /// general data facet expression |
| 1269 | //------------------------------------------------------------------ |
| 1270 | class TDLFacetExpression: public TDLDataExpression, public TDataExpressionArg<TDLDataValue> |
| 1271 | { |
| 1272 | public: // interface |
| 1273 | /// init c'tor: create facet from a given value V |
| 1274 | explicit TDLFacetExpression ( const TDLDataValue* V ) |
| 1275 | : TDLDataExpression() |
| 1276 | , TDataExpressionArg<TDLDataValue>(V) |
| 1277 | {} |
| 1278 | |
| 1279 | /// accept method for the visitor pattern |
| 1280 | void accept ( DLExpressionVisitor& visitor ) const override = 0; |
| 1281 | }; // TDLFacetExpression |
| 1282 | |
| 1283 | //------------------------------------------------------------------ |
| 1284 | /// min-inclusive facet expression |
| 1285 | //------------------------------------------------------------------ |
| 1286 | class TDLFacetMinInclusive: public TDLFacetExpression |
| 1287 | { |
| 1288 | public: // interface |
| 1289 | /// init c'tor |
| 1290 | explicit TDLFacetMinInclusive ( const TDLDataValue* V ) : TDLFacetExpression(V) {} |
| 1291 | |
| 1292 | /// accept method for the visitor pattern |
| 1293 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1294 | }; // TDLFacetMinInclusive |
| 1295 | |
| 1296 | //------------------------------------------------------------------ |
| 1297 | /// min-exclusive facet expression |
| 1298 | //------------------------------------------------------------------ |
| 1299 | class TDLFacetMinExclusive: public TDLFacetExpression |
| 1300 | { |
| 1301 | public: // interface |
| 1302 | /// init c'tor |
| 1303 | explicit TDLFacetMinExclusive ( const TDLDataValue* V ) : TDLFacetExpression(V) {} |
| 1304 | |
| 1305 | /// accept method for the visitor pattern |
| 1306 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1307 | }; // TDLFacetMinExclusive |
| 1308 | |
| 1309 | //------------------------------------------------------------------ |
| 1310 | /// max-inclusive facet expression |
| 1311 | //------------------------------------------------------------------ |
| 1312 | class TDLFacetMaxInclusive: public TDLFacetExpression |
| 1313 | { |
| 1314 | public: // interface |
| 1315 | /// init c'tor |
| 1316 | explicit TDLFacetMaxInclusive ( const TDLDataValue* V ) : TDLFacetExpression(V) {} |
| 1317 | |
| 1318 | /// accept method for the visitor pattern |
| 1319 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1320 | }; // TDLFacetMaxInclusive |
| 1321 | |
| 1322 | //------------------------------------------------------------------ |
| 1323 | /// max-exclusive facet expression |
| 1324 | //------------------------------------------------------------------ |
| 1325 | class TDLFacetMaxExclusive: public TDLFacetExpression |
| 1326 | { |
| 1327 | public: // interface |
| 1328 | /// init c'tor |
| 1329 | explicit TDLFacetMaxExclusive ( const TDLDataValue* V ) : TDLFacetExpression(V) {} |
| 1330 | |
| 1331 | /// accept method for the visitor pattern |
| 1332 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1333 | }; // TDLFacetMaxExclusive |
| 1334 | |
| 1335 | |
| 1336 | // data type is defined here as they are more complex than the rest |
| 1337 | |
| 1338 | //------------------------------------------------------------------ |
| 1339 | /// data type implementation for the DL expressions |
| 1340 | //------------------------------------------------------------------ |
| 1341 | class TDLDataType |
| 1342 | { |
| 1343 | protected: // classes |
| 1344 | /// class to create a new entry with a given data type as a parameter |
| 1345 | class DVCreator: public TNameCreator<TDLDataValue> |
| 1346 | { |
| 1347 | protected: // members |
| 1348 | /// type for all the values |
| 1349 | const TDLDataTypeExpression* type; |
| 1350 | public: // interface |
| 1351 | /// init c'tor |
| 1352 | explicit DVCreator ( const TDLDataTypeExpression* t ) : type(t) {} |
| 1353 | /// create new value of a given type |
| 1354 | TDLDataValue* makeEntry ( const std::string& name ) const override { return new TDLDataValue(name,type); } |
| 1355 | }; // DVCreator |
| 1356 | |
| 1357 | protected: // members |
| 1358 | /// all the values of the datatype |
| 1359 | TNameSet<TDLDataValue> Values; |
| 1360 | |
| 1361 | public: // interface |
| 1362 | /// empty c'tor |
| 1363 | explicit TDLDataType ( const TDLDataTypeExpression* type ) : Values(new DVCreator(type)) {} |
| 1364 | /// empty d'tor |
| 1365 | virtual ~TDLDataType() = default; |
| 1366 | |
| 1367 | /// get new data value of the given type |
| 1368 | const TDLDataValue* getValue ( const std::string& name ) { return Values.insert(name); } |
| 1369 | }; // TDLDataType |
| 1370 | |
| 1371 | |
| 1372 | //------------------------------------------------------------------ |
| 1373 | /// named data type expression |
| 1374 | //------------------------------------------------------------------ |
| 1375 | class TDLDataTypeName: public TDLDataTypeExpression, public TDLDataType, public TNamedEntity |
| 1376 | { |
| 1377 | public: // interface |
| 1378 | /// init c'tor |
| 1379 | explicit TDLDataTypeName ( const std::string& name ) : TDLDataTypeExpression(), TDLDataType(this), TNamedEntity(name) {} |
| 1380 | |
| 1381 | /// accept method for the visitor pattern |
| 1382 | void accept ( DLExpressionVisitor& visitor ) const override { visitor.visit(*this); } |
| 1383 | }; // TDLDataTypeName |
| 1384 | |
| 1385 | /// @return named data type that is the most basic datatype underlying TYPE |
| 1386 | inline TDLDataTypeName* |
| 1387 | getBasicDataType ( TDLDataTypeExpression* type ) |
| 1388 | { |
| 1389 | TDLDataTypeName* ret = dynamic_cast<TDLDataTypeName*>(type); |
| 1390 | if ( ret == nullptr ) |
| 1391 | { |
| 1392 | TDLDataTypeRestriction* hostType = dynamic_cast<TDLDataTypeRestriction*>(type); |
| 1393 | fpp_assert ( hostType != nullptr ); |
| 1394 | ret = const_cast<TDLDataTypeName*>(hostType->getExpr()); |
| 1395 | } |
| 1396 | return ret; |
| 1397 | } |
| 1398 | |
| 1399 | #endif |