@@ -8,32 +8,34 @@ using namespace std;
88
99#pragma region CTORs and DTORs
1010 CSFParser::CSFParser () {}
11- CSFParser::CSFParser (const string& filePath) {Parse (filePath);}
12- CSFParser::CSFParser (const char * filePath) {Parse (filePath);}
13- CSFParser::CSFParser (const QString& filePath) {Parse (filePath);}
11+ CSFParser::CSFParser (const wstring& filePath) { Parse (filePath); }
12+ CSFParser::CSFParser (const string& filePath) { Parse (filePath); }
13+ CSFParser::CSFParser (const char * filePath) { Parse (filePath); }
14+ CSFParser::CSFParser (const QString& filePath) { Parse (filePath); }
1415#pragma endregion
1516
1617#pragma region Parsing
1718 void CSFParser::Parse (const char * strFilePath)
1819 {
19- Path = QString{ strFilePath}. toStdString ();
20- ifstream csfFile (Path, ios::binary | ios::in);
21- LOGMSG (" Attempt to read binary file \" " + Path + " \" ..." );
20+ Path = QString ( strFilePath). toStdWString ();
21+ ifstream csfFile (Path. c_str () , ios::binary | ios::in);
22+ LOGMSG (" Attempt to read binary file \" " + Path. c_str () + " \" ..." );
2223
2324 if (csfFile.is_open ())
2425 {
2526 ReadHeader (&csfFile);
2627 ReadBody (&csfFile);
2728
28- LOGMSG (" File \" " + Path + " \" has been parsed; strings count : " + Table.size ());
29+ LOGMSG (" File \" " + Path. c_str () + " \" has been parsed; strings count : " + Table.size ());
2930 }
3031 else
3132 {
32- throw Exception (" Bad file name; unable to open file \" " + Path + " \" " );
33+ throw Exception (QString ( " " ) + " Bad file name; unable to open file \" " + Path + " \" " );
3334 }
3435 }
35- void CSFParser::Parse (const std::string& strFilePath) {Parse (strFilePath.c_str ());}
36- void CSFParser::Parse (const QString& strFilePath) {Parse (strFilePath.toStdString ().c_str ());}
36+ void CSFParser::Parse (const wstring& filePath) { Parse (filePath.c_str ()); }
37+ void CSFParser::Parse (const std::string& strFilePath) { Parse (strFilePath.c_str ()); }
38+ void CSFParser::Parse (const QString& strFilePath) { Parse (strFilePath.toStdString ().c_str ()); }
3739
3840 void CSFParser::ReadHeader (ifstream* csfFile)
3941 {
@@ -132,42 +134,31 @@ using namespace std;
132134 }
133135 }
134136
135- void CSFParser::Save (const string& strFileName)
137+ void CSFParser::Save (const char * strFileName) { wstring tmp = Path; Path = QString (strFileName).toStdWString (); Save (); Path = tmp; }
138+ void CSFParser::Save (const wstring& strFileName) { wstring tmp = Path; Path = strFileName; Save (); Path = tmp; }
139+ void CSFParser::Save (const string& strFileName) { wstring tmp = Path; Path = QString::fromStdString (strFileName).toStdWString (); Save (); Path = tmp; }
140+ void CSFParser::Save (const QString& strFileName) { wstring tmp = Path; Path = strFileName.toStdWString (); Save (); Path = tmp; }
141+ void CSFParser::Save ()
136142 {
137- ofstream csfFile{strFileName , ios::binary | ios::out};
143+ ofstream csfFile{Path. c_str () , ios::binary | ios::out};
138144
139145 if (csfFile.is_open ())
140146 {
141- LOGSTM << " Attempt to write binary file \" " << strFileName << " \" " << endl;
147+ LOGSTM << ( " Attempt to write binary file \" " + Path + " \" " ). toStdString () << endl;
142148
143149 CSFParser::WriteHeader (&csfFile);
144150 CSFParser::WriteBody (&csfFile);
145151
146- LOGSTM << " File saved as \" " << strFileName << " \" " << endl;
152+ LOGSTM << ( " File saved as \" " + Path + " \" " ). toStdString () << endl;
147153 }
148154 else
149155 {
150- LOGSTM << " Could not open file \" " << strFileName << " \" to save" << endl;
156+ LOGSTM << ( " Could not open file \" " + Path + " \" to save" ). toStdString () << endl;
151157 }
152158
153159 csfFile.close ();
154160 }
155161
156- void CSFParser::Save (const char * strFileName)
157- {
158- Save (string{strFileName});
159- }
160-
161- void CSFParser::Save (const QString& strFileName)
162- {
163- Save (strFileName.toStdString ());
164- }
165-
166- void CSFParser::Save ()
167- {
168- Save (Path);
169- }
170-
171162 void CSFParser::WriteHeader (ofstream* csfFile)
172163 {
173164 // Struct Header has the same length as the original file
@@ -454,7 +445,33 @@ using namespace std;
454445 }
455446#pragma endregion
456447
457- #pragma region Support methods
448+ #pragma region Checkers
449+
450+ const bool CSFParser::ExistString (const std::string value) const
451+ {
452+ for (const auto & elem : Table)
453+ if (elem.Name == value)
454+ return true ;
455+
456+ return false ;
457+ }
458+ const bool CSFParser::ExistString (const QString& value) const { return ExistString (value.toStdString ()); }
459+ const bool CSFParser::ExistString (const char * value) const { return ExistString (std::string (value)); }
460+
461+ const bool CSFParser::ExistCategory (const std::string value) const
462+ {
463+ for (const auto & elem : Table)
464+ if (elem.Name .substr (0 , elem.Name .find_first_of (' :' , 0 ) ) == value)
465+ return true ;;
466+
467+ return false ;
468+ }
469+ const bool CSFParser::ExistCategory (const QString& value) const { return ExistCategory (value.toStdString ()); }
470+ const bool CSFParser::ExistCategory (const char * value) const { return ExistCategory (QString (value)); }
471+
472+ #pragma endregion
473+
474+ #pragma region Internal methods
458475 string CSFParser::CharArrayToString (const size_t & arrayLength, const char * pArray) const
459476 {
460477 stringstream ss;
0 commit comments