| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2003-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 MERGEABLELABEL_H |
| 21 | #define MERGEABLELABEL_H |
| 22 | |
| 23 | /// implementation of labels that could be compared and merged to each other |
| 24 | class mergeableLabel |
| 25 | { |
| 26 | protected: // members |
| 27 | /// sample for all equivalent labels |
| 28 | mergeableLabel* pSample; |
| 29 | |
| 30 | public: // interface |
| 31 | /// empty c'tor |
| 32 | mergeableLabel ( void ) : pSample(this) {} |
| 33 | /// copy c'tor |
| 34 | mergeableLabel ( mergeableLabel& p ) : pSample(p.resolve()) {} |
| 35 | /// assignment |
| 36 | mergeableLabel& operator = ( mergeableLabel& p ) { pSample = p.resolve(); return *this; } |
| 37 | |
| 38 | // general interface |
| 39 | |
| 40 | /// are 2 labels equal; works only for normalised labels |
| 41 | bool operator == ( const mergeableLabel& p ) const { return (pSample == p.pSample); } |
| 42 | /// are 2 labels different; works only for normalised labels |
| 43 | bool operator != ( const mergeableLabel& p ) const { return (pSample != p.pSample); } |
| 44 | /// make 2 labels equal |
| 45 | void merge ( mergeableLabel& p ) |
| 46 | { |
| 47 | mergeableLabel* sample = p.resolve(); |
| 48 | resolve(); |
| 49 | if ( pSample != sample ) |
| 50 | pSample->pSample = sample; |
| 51 | } |
| 52 | /// make label's depth <= 2; @return sample of the label |
| 53 | mergeableLabel* resolve ( void ) |
| 54 | { |
| 55 | // check if current node is itself sample |
| 56 | if ( !isSample() ) |
| 57 | pSample = pSample->resolve(); |
| 58 | |
| 59 | return pSample; |
| 60 | } |
| 61 | /// is given label a sample label |
| 62 | bool isSample ( void ) const { return (pSample == this); } |
| 63 | }; // mergeableLabel |
| 64 | |
| 65 | #endif |