| 1 | /* This file is part of the FaCT++ DL reasoner |
| 2 | Copyright (C) 2013-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 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 | #include <fstream> |
| 21 | |
| 22 | #include "SaveLoadManager.h" |
| 23 | #include "tNamedEntry.h" |
| 24 | |
| 25 | bool |
| 26 | SaveLoadManager :: existsContent ( void ) const |
| 27 | { |
| 28 | // context is there if a file can be opened |
| 29 | return !std::ifstream(filename).fail(); |
| 30 | } |
| 31 | |
| 32 | void |
| 33 | SaveLoadManager :: clearContent ( void ) const |
| 34 | { |
| 35 | remove(filename.c_str()); |
| 36 | } |
| 37 | |
| 38 | void |
| 39 | SaveLoadManager :: prepare ( bool input ) |
| 40 | { |
| 41 | // close all previously open streams |
| 42 | delete ip; |
| 43 | delete op; |
| 44 | ip = nullptr; |
| 45 | op = nullptr; |
| 46 | |
| 47 | // open a new one |
| 48 | if ( input ) |
| 49 | ip = new std::ifstream(filename); |
| 50 | else |
| 51 | op = new std::ofstream(filename); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | SaveLoadManager :: registerE ( const TNamedEntry* p ) |
| 56 | { |
| 57 | neMap.add(const_cast<TNamedEntry*>(p)); |
| 58 | if ( p->getEntity() != nullptr ) |
| 59 | eMap.add(const_cast<TNamedEntity*>(p->getEntity())); |
| 60 | } |
| 61 | |
| 62 | #if 0 |
| 63 | bool |
| 64 | SaveLoadManager :: clearContent ( void ) const |
| 65 | { |
| 66 | #ifdef WINDOWS |
| 67 | SHFILEOPSTRUCT file_op = { |
| 68 | nullptr, |
| 69 | FO_DELETE, |
| 70 | dirname.c_str(), // FIXME!! fully qualified name expected |
| 71 | "", |
| 72 | FOF_NOCONFIRMATION | |
| 73 | FOF_NOERRORUI | |
| 74 | FOF_SILENT, |
| 75 | false, |
| 76 | 0, |
| 77 | "" }; |
| 78 | SHFileOperation(&file_op); |
| 79 | #endif |
| 80 | } |
| 81 | #endif |