53 inline void addLogErrorEntry(
const std::string& text );
62 const DATA& data ) = 0;
67 inline void resetLog();
77template <
typename DATA,
bool Binary>
80 const bool SAVE_LOG_FILE ) {
83 addLogEntry(
"Filename : " + filename );
84 addLogEntry(
"Expected Format : " + fileExtension() );
85 addLogEntry(
"File Type : " +
std::string( Binary ?
"Binary" :
"Text" ) );
86 addLogEntry(
"Loading start..." );
88 filename, std::ios_base::in | ( Binary ? std::ios_base::binary : std::ios_base::in ) );
89 if ( !( status = file.
is_open() ) ) {
91 "Error occurred while opening the file. Trying to see if extension is missing..." );
92 file.
open( filename +
"." + fileExtension(),
93 std::ios_base::in | ( Binary ? std::ios_base::binary : std::ios_base::in ) );
94 if ( !( status = file.
is_open() ) ) {
95 addLogErrorEntry(
"Error occured while opening the file. HINT: FILENAME IS WRONG." );
99 addLogEntry(
"File opened successfully." );
100 addLogEntry(
"Starting to import the data." );
101 status = importData( file, data );
103 ( ( status ) ? LogEntry_Normal : LogEntry_Error ) );
105 addLogEntry(
"File closed." );
107 addLogEntry(
"Loading " + filename +
" ended." );
108 if ( SAVE_LOG_FILE ) { saveLog( filename +
"_load" ); }
112template <
typename DATA,
bool Binary>
115 const bool SAVE_LOG_FILE ) {
118 addLogEntry(
"Filename : " + filename );
119 addLogEntry(
"Exporting Format : " + fileExtension() );
120 addLogEntry(
"File Type : " +
std::string( Binary ?
"Binary" :
"Text" ) );
121 addLogEntry(
"Saving start..." );
123 std::ios_base::out | std::ios_base::trunc |
124 ( Binary ? std::ios_base::binary : std::ios_base::out ) );
125 if ( !( status = file.is_open() ) ) {
126 addLogErrorEntry(
"Error occured while opening the file." );
129 addLogEntry(
"File opened successfully." );
130 addLogEntry(
"Starting to export the data..." );
131 status = exportData( file, data );
133 ( ( status ) ? LogEntry_Normal : LogEntry_Error ) );
135 addLogEntry(
"File closed." );
137 addLogEntry(
"Saving " + filename +
" ended." );
138 if ( SAVE_LOG_FILE ) { saveLog( filename +
"_save" ); }
145template <
typename DATA,
bool Binary>
150template <
typename DATA,
bool Binary>
152 addLogEntry( text, LogEntry_Normal );
155template <
typename DATA,
bool Binary>
157 addLogEntry( text, LogEntry_Warning );
160template <
typename DATA,
bool Binary>
161inline void FileManager<DATA, Binary>::addLogErrorEntry(
const std::string& text ) {
162 addLogEntry( text, LogEntry_Error );
165template <
typename DATA,
bool Binary>
167 const LogEntryType type ) {
169 case LogEntry_Normal: {
173 case LogEntry_Warning: {
174 m_log +=
"\n--- LogEntry_Warning : " + text +
" ---\n";
177 case LogEntry_Error: {
178 m_log +=
"\n### LogEntry_Error : " + text +
" ###\n";
188template <
typename DATA,
bool Binary>
189inline void FileManager<DATA, Binary>::resetLog() {
190 m_log =
"====== FILE MANAGER LOG ======\n";
193template <
typename DATA,
bool Binary>
194inline void FileManager<DATA, Binary>::saveLog(
const std::string& filename ) {
196 if ( !file.is_open() ) {
return; }