| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2007-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 MODELCACHECONST_H |
| 21 | #define MODELCACHECONST_H |
| 22 | |
| 23 | #include "modelCacheInterface.h" |
| 24 | #include "BiPointer.h" |
| 25 | #include "fpp_assert.h" |
| 26 | |
| 27 | /// Model caching implementation for TOP/BOTTOM nodes. |
| 28 | class modelCacheConst: public modelCacheInterface |
| 29 | { |
| 30 | protected: // members |
| 31 | /// the const itself |
| 32 | bool isTop; |
| 33 | |
| 34 | protected: // methods |
| 35 | /// log a particular implementation of a cache entry |
| 36 | void logCacheEntryImpl ( void ) const override |
| 37 | { LL << "\nConst cache: element " << (isTop ? "TOP" : "BOTTOM"); } |
| 38 | |
| 39 | public: |
| 40 | /// c'tor: no nominals can be here |
| 41 | explicit modelCacheConst ( bool top ) |
| 42 | : modelCacheInterface{/*flagNominals=*/false} |
| 43 | , isTop{top} |
| 44 | {} |
| 45 | /// copy c'tor |
| 46 | modelCacheConst ( const modelCacheConst& m ) |
| 47 | : modelCacheInterface{m.hasNominalNode} |
| 48 | , isTop{m.isTop} |
| 49 | {} |
| 50 | |
| 51 | /// Check if the model contains clash |
| 52 | modelCacheState getState ( void ) const override { return isTop ? csValid : csInvalid; } |
| 53 | /// get the value of the constant |
| 54 | bool getConst ( void ) const { return isTop; } |
| 55 | |
| 56 | // mergeable part |
| 57 | |
| 58 | /// check whether two caches can be merged; @return state of "merged" model |
| 59 | modelCacheState canMerge ( const modelCacheInterface* cache ) const override |
| 60 | { |
| 61 | if ( auto cacheConst = dynamic_cast<const modelCacheConst*>(cache) ) |
| 62 | return isTop && cacheConst->isTop ? csValid : csInvalid; |
| 63 | else |
| 64 | return cache->canMerge(this); |
| 65 | } |
| 66 | }; // modelCacheConst |
| 67 | |
| 68 | // create const cache by BP; BP should be either bpTOP or bpBOTTOM |
| 69 | inline |
| 70 | modelCacheConst* createConstCache ( BipolarPointer bp ) |
| 71 | { |
| 72 | fpp_assert ( bp == bpTOP || bp == bpBOTTOM ); |
| 73 | return new modelCacheConst{bp==bpTOP}; |
| 74 | } |
| 75 | |
| 76 | #endif |