00001
00002
00003
00004
00005
00006
00014
00015
00016
00017
00018
00019 #ifndef CIFFILE_H
00020 #define CIFFILE_H
00021
00022
00023 #include <string>
00024 #include <vector>
00025 #include <iostream>
00026
00027
00028 #include "CifString.h"
00029 #include "TableFile.h"
00030
00031
00043 class CifFile : public TableFile
00044 {
00045 public:
00046 static const unsigned int STD_CIF_LINE_LENGTH = 80;
00047
00048 enum eQuoting
00049 {
00050 eSINGLE = 0,
00051 eDOUBLE
00052 };
00053
00072 CifFile(const StringCompare::eCompareType caseSense =
00073 StringCompare::eCASE_SENSITIVE);
00074
00106 CifFile(const eFileMode fileMode, const string& fileName,
00107 const bool verbose = false, const StringCompare::eCompareType
00108 caseSense = StringCompare::eCASE_SENSITIVE,
00109 const unsigned int maxLineLength = STD_CIF_LINE_LENGTH,
00110 const string& nullValue = CifString::NullValue);
00111
00125 ~CifFile();
00126
00141 inline bool GetVerbose();
00142
00159 inline void SetSmartPrint(bool smartPrint = true);
00160
00175 inline bool IsSmartPrint();
00176
00192 void SetQuoting(eQuoting quoting);
00193
00208 unsigned int GetQuoting();
00209
00232 void Write(const string& cifFileName, const bool sortTables = false,
00233 const bool writeEmptyTables = false);
00234
00255 void Write(const string& cifFileName, const vector<string>& tableOrder,
00256 const bool writeEmptyTables = false);
00257
00272 int DataChecking(CifFile& dicRef);
00273
00291 static void GetItemNames(vector<string>& itemNames, ISTable& isTable);
00292
00293 protected:
00294 static const unsigned int STD_PRINT_SPACING = 3;
00295 static const unsigned int SMART_PRINT_SPACING = 1;
00296 static const unsigned int HEADER_SPACING = 40;
00297
00298 enum eIdentType
00299 {
00300 eNONE = 0,
00301 eLEFT,
00302 eRIGHT
00303 };
00304
00305 unsigned int _maxCifLineLength;
00306 string _nullValue;
00307 bool _verbose;
00308 bool _smartPrint;
00309 string _quotes;
00310
00311 int _IsQuotableText(const string& itemValue);
00312 eIdentType _FindPrintType(const vector<string>& values);
00313
00314 void _PrintItemIdent(ostream& cifo, unsigned int& linePos);
00315 void _PrintItemName(ostream& cifo, const string& category,
00316 const string& itemName, unsigned int& linePos);
00317 void _PrintPostItemSeparator(ostream& cifo, unsigned int& linePos,
00318 const bool ident = false, const unsigned int numSpaces = 1);
00319
00320 int _PrintItemValue(ostream& cifo, const string& itemValue,
00321 unsigned int& linePos, const eIdentType identType = eNONE,
00322 const unsigned int width = 0);
00323
00324 int _PrintItemNameInHeader(ostream& cifo, const string& itemValue,
00325 unsigned int& linePos, const eIdentType identType = eNONE,
00326 const unsigned int width = 0);
00327
00328 void _PrintHeaderedItems(ostream& cifo, const vector<string>& colNames,
00329 const vector<unsigned int>& colWidths,
00330 const vector<eIdentType> colPrintType);
00331
00332 void Write(ostream& cifo, const bool sortTables = false,
00333 const bool writeEmptyTables = false);
00334 void Write(ostream& cifo, const vector<string>& catOrder,
00335 const bool writeEmptyTables = false);
00336
00337 void Write(ostream& cifo, vector<unsigned int>& tables,
00338 const bool writeEmptyTables = false);
00339
00340 int MandatoryCategoryChecking(CifFile& ref, ofstream& log);
00341 int ItemsChecking(CifFile& ref, ofstream& log);
00342
00343 private:
00344 void Init();
00345 void ConvertEscapedString(const string& inString, string& outString);
00346
00347 };
00348
00349
00350 inline bool CifFile::GetVerbose()
00351 {
00352 return(_verbose);
00353 }
00354
00355
00356 inline void CifFile::SetSmartPrint(bool smartPrint)
00357 {
00358 _smartPrint = smartPrint;
00359 }
00360
00361
00362 inline bool CifFile::IsSmartPrint()
00363 {
00364 return(_smartPrint);
00365 }
00366
00367
00368 #endif