Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
filemanager.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
20 //=============================================================================
21 // File manager adapter
22 //=============================================================================
23 
24 #include "filemanager.h"
25 #include "../system/eptexception.h"
26 #include "../system/log.h"
27 
34 
35 std::unique_ptr<FileManager> FileManager::mSingleton;
36 
37 
38 //-----------------------------------------------------------------------------
39 // Get a reference to the singleton
40 //-----------------------------------------------------------------------------
41 
46 
48 {
49  EptAssert(mSingleton,"FileManager should have a singleton pointer");
50  return *mSingleton.get();
51 }
52 
53 
54 //-----------------------------------------------------------------------------
55 // Open an input stream
56 //-----------------------------------------------------------------------------
57 
70 
71 bool FileManager::open(std::ifstream &stream,
72  const std::string &absolute,
73  std::ios_base::openmode mode)
74 {
75  stream.open(absolute, mode);
76  if (not stream)
77  {
78  LogW("Stream at '%s' could not be opened.", absolute.c_str());
79  return false;
80  }
81  else
82  {
83  LogI("Stream at '%s' is open.", absolute.c_str());
84  return true;
85  }
86 }
87 
88 
89 //-----------------------------------------------------------------------------
90 // Open an output stream
91 //-----------------------------------------------------------------------------
92 
105 
106 bool FileManager::open(std::ofstream &stream,
107  const std::string &absolute,
108  std::ios_base::openmode mode)
109 {
110  stream.open(absolute, mode);
111  if (not stream)
112  {
113  LogW("Stream at '%s' could not be opened.", absolute.c_str());
114  return false;
115  }
116  else
117  {
118  LogI("Stream at '%s' is open.", absolute.c_str());
119  return true;
120  }
121 }
#define LogW(...)
Definition: log.h:56
static FileManager & getSingleton()
FileManager::getSingleton: Get a reference to the singleton.
Definition: filemanager.cpp:47
static std::unique_ptr< FileManager > mSingleton
Singleton unique pointer.
Definition: filemanager.h:90
#define LogI(...)
Definition: log.h:50
#define EptAssert(a, b)
Definition: eptexception.h:47
virtual bool open(std::ifstream &stream, const std::string &absolute, std::ios_base::openmode mode=std::ios_base::in)
Open an input stream.
Definition: filemanager.cpp:71
Abstract singleton adapter for opening files.
Definition: filemanager.h:43