CifFile.h

Go to the documentation of this file.
00001 //$$FILE$$
00002 //$$VERSION$$
00003 //$$DATE$$
00004 //$$LICENSE$$
00005 
00006 
00014 /* 
00015   PURPOSE:    Base class for read/write cif files
00016 */
00017 
00018 
00019 #ifndef CIFFILE_H
00020 #define CIFFILE_H
00021 
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <iostream>
00026 #include <sstream>
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 
00085     CifFile(const eFileMode fileMode, const string& fileName,
00086       const bool verbose = false, const StringCompare::eCompareType
00087       caseSense = StringCompare::eCASE_SENSITIVE,
00088       const unsigned int maxLineLength = STD_CIF_LINE_LENGTH,
00089       const string& nullValue = CifString::NullValue);
00090 
00116     CifFile(const bool verbose = false, const StringCompare::eCompareType
00117       caseSense = StringCompare::eCASE_SENSITIVE,
00118       const unsigned int maxLineLength = STD_CIF_LINE_LENGTH,
00119       const string& nullValue = CifString::NullValue);
00120 
00134     ~CifFile();
00135 
00150     inline bool GetVerbose();
00151 
00168     inline void SetSmartPrint(bool smartPrint = true);
00169 
00184     inline bool IsSmartPrint();
00185 
00201     void SetQuoting(eQuoting quoting);
00202 
00217     unsigned int GetQuoting();
00218  
00241     void Write(const string& cifFileName, const bool sortTables = false,
00242       const bool writeEmptyTables = false);
00243 
00264     void Write(const string& cifFileName, const vector<string>& tableOrder,
00265       const bool writeEmptyTables = false);
00266 
00288     void Write(ostream& outStream, const bool sortTables = false,
00289       const bool writeEmptyTables = false);
00290 
00306     int DataChecking(CifFile& dicRef);
00307 
00325     int DataChecking(Block& block, Block& refBlock, ostringstream& buf);
00326 
00344     static void GetItemNames(vector<string>& itemNames, ISTable& isTable);
00345 
00346     void GetAttributeValue(string& attribVal, const string& blockId,
00347       const string& category, const string& attribute);
00348     void GetAttributeValueIf(string& attribVal, const string& blockId,
00349       const string& category, const string& attributeA,
00350       const string& attributeB, const string& valB);
00351     bool IsAttributeValueDefined(const string& blockId,
00352       const string& category, const string& attribute);
00353 
00354     void SetAttributeValue(const string& blockId, const string& category,
00355       const string& attribute, const string& value,
00356       const bool create = false);
00357     void SetAttributeValueIf(const string& blockId,
00358       const string& category, const string& attributeA, const string& valA,
00359       const string& attributeB, const string& valB, const bool create = false);
00360     void SetAttributeValueIfNull(const string& blockId,
00361       const string& category, const string& attribute, const string& value);
00362 
00363     void GetAttributeValues(vector<string>& strings, const string& blockId,
00364       const string& category, const string& attribute);
00365     void GetAttributeValuesIf(vector<string>& strings, 
00366       const string& blockId, const string& category, const string& attributeA, 
00367       const string& attributeB, const string& valB);
00368 
00369     void SetAttributeValues(const string& blockId,
00370       const string& category, const string& attribute,
00371       const vector<string>& values);
00372 
00373 #ifdef VLAD_TO_CIF_FILE_NOT_USED
00374     void del_attribute_value_where(CifFile *fobj, const char *blockId,
00375       const char *category, const char *attributeB, const char *valB);
00376 #endif // VLAD_TO_CIF_FILE_NOT_USED not defined
00377 
00378     int CheckCategories(Block& block, Block& refBlock, ostringstream& log);
00379     void CheckCategoryKey(Block& block, ostringstream& log);
00380     int CheckItems(Block& block, Block& refBlock, ostringstream& log);
00381 
00382 
00383   protected:
00384     static const unsigned int STD_PRINT_SPACING = 3;
00385     static const unsigned int SMART_PRINT_SPACING = 1;
00386     static const unsigned int HEADER_SPACING = 40;
00387 
00388     enum eIdentType
00389     {
00390         eNONE = 0,
00391         eLEFT,
00392         eRIGHT
00393     };
00394 
00395     unsigned int _maxCifLineLength;
00396     string _nullValue;
00397     bool _verbose;
00398     bool _smartPrint;
00399     string _quotes;
00400 
00401     int _IsQuotableText(const string& itemValue);
00402     eIdentType _FindPrintType(const vector<string>& values);
00403 
00404     void _PrintItemIdent(ostream& cifo, unsigned int& linePos);
00405     void _PrintItemName(ostream& cifo, const string& category,
00406       const string& itemName, unsigned int& linePos);
00407     void _PrintPostItemSeparator(ostream& cifo, unsigned int& linePos,
00408       const bool ident = false, const unsigned int numSpaces = 1);
00409 
00410     int _PrintItemValue(ostream& cifo, const string& itemValue,
00411       unsigned int& linePos, const eIdentType identType = eNONE,
00412       const unsigned int width = 0);
00413 
00414     int _PrintItemNameInHeader(ostream& cifo, const string& itemValue,
00415       unsigned int& linePos, const eIdentType identType = eNONE,
00416       const unsigned int width = 0);
00417 
00418     void _PrintHeaderedItems(ostream& cifo, const vector<string>& colNames,
00419       const vector<unsigned int>& colWidths,
00420       const vector<eIdentType> colPrintType);
00421 
00422     void Write(ostream& cifo, const vector<string>& catOrder,
00423       const bool writeEmptyTables = false);
00424 
00425     void Write(ostream& cifo, vector<unsigned int>& tables,
00426       const bool writeEmptyTables = false);
00427 
00428 
00429   private:
00430     void Init();
00431 
00432     bool IsCatDefinedInRef(const string& catName, ISTable& catTable);
00433     bool IsItemDefinedInRef(const string& catName, const string& itemName,
00434       ISTable& refItemTable);
00435     void CheckKeyItems(const string& blockName, ISTable& catTable,
00436       ISTable& keyTable, ostringstream& log);
00437 
00438     void CheckMandatoryItems(const string& blockName, ISTable& catTable,
00439       ISTable& refItemTable, ostringstream& log);
00440 
00441     void CheckAndRectifyItemTypeCode(Block& block, ostringstream& log);
00442 
00443     int CheckParentChild(Block& block, ISTable& catTable,
00444       const vector<string>& cifItemNames, ISTable& parChildTable,
00445       ostringstream& log);
00446 
00447     int CheckRegExpRangeEnum(Block& block, ISTable& catTable,
00448       const string& cifItemName, ISTable& itemTypeTable,
00449       ISTable& itemTypeListTable, ISTable& itemRangeTable,
00450       ISTable& itemEnumTable, ISTable& parChildTable, ostringstream& log);
00451 
00452     int CheckCellRange(const string& cell, const string& typeCode,
00453       const vector<string>& minlist, const vector<string>& maxlist);
00454 
00455     int CheckCellEnum(const string& cell, const string& typeCode,
00456       const string& primCode, const vector<string>& enumlist);
00457 
00458     int CheckCellFloatRange(const string& cell, const vector<string>& minlist,
00459       const vector<string>& maxlist);
00460 
00461     int CheckCellIntRange(const string& cell, const vector<string>& minlist,
00462       const vector<string>& maxlist);
00463 
00464     int CheckCellFloatEnum(const string& cell, const vector<string>& enumlist);
00465 
00466     int CheckCellIntEnum(const string& cell, const vector<string>& enumlist);
00467 
00468     int CheckCellOtherEnum(const string& cell, const string& primCode,
00469       const vector<string>& enumlist);
00470 
00471     ISTable* CreateKeysTable(const vector<string>& cifItemNames,
00472       ISTable& parChildTable, map<string, unsigned int>& maxKeyGroups);
00473 
00474     void GetComboKeys(const string& parCatName,
00475       const unsigned int maxKeyGroup, ISTable& keysTable,
00476       vector<vector<string> >& comboKeys, vector<string>& parKeys);
00477 
00478     void GetItemTypeCode(string& typeCode, const string& cifItemName,
00479       ISTable& itemTypeTable);
00480 
00481     void ConvertEscapedString(const string& inString, string& outString);
00482 };
00483 
00484 
00485 inline bool CifFile::GetVerbose()
00486 {
00487     return(_verbose);
00488 }
00489 
00490 
00491 inline void CifFile::SetSmartPrint(bool smartPrint)
00492 {
00493     _smartPrint = smartPrint;
00494 }
00495 
00496 
00497 inline bool CifFile::IsSmartPrint()
00498 {
00499     return(_smartPrint);
00500 }
00501 
00502 
00503 #endif

Generated on Wed Feb 6 07:44:01 2008 for cif-file-v1.0 by  doxygen 1.5.1