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 <map>
00026 #include <iostream>
00027 #include <sstream>
00028 
00029 #include "GenString.h"
00030 #include "CifString.h"
00031 #include "TableFile.h"
00032 
00033 
00045 class CifFile : public TableFile
00046 {
00047   public:
00048     std::string _parsingDiags;
00049     std::string _checkingDiags;
00050 
00051     static const unsigned int STD_CIF_LINE_LENGTH = 80;
00052 
00053     enum eQuoting
00054     {
00055         eSINGLE = 0,
00056         eDOUBLE
00057     };
00058 
00090     CifFile(const eFileMode fileMode, const std::string& fileName,
00091       const bool verbose = false, const Char::eCompareType
00092       caseSense = Char::eCASE_SENSITIVE,
00093       const unsigned int maxLineLength = STD_CIF_LINE_LENGTH,
00094       const std::string& nullValue = CifString::UnknownValue);
00095 
00121     CifFile(const bool verbose = false, const Char::eCompareType
00122       caseSense = Char::eCASE_SENSITIVE,
00123       const unsigned int maxLineLength = STD_CIF_LINE_LENGTH,
00124       const std::string& nullValue = CifString::UnknownValue);
00125 
00139     ~CifFile();
00140 
00154     void SetSrcFileName(const std::string& srcFileName);
00155 
00156 
00170     const std::string& GetSrcFileName();
00171 
00172 
00187     inline bool GetVerbose();
00188 
00205     inline void SetSmartPrint(bool smartPrint = true);
00206 
00207 
00222     inline bool IsSmartPrint();
00223 
00239     void SetQuoting(eQuoting quoting);
00240 
00255     unsigned int GetQuoting();
00256  
00275     void SetLooping(const std::string& catName, bool looping = false);
00276 
00290     bool GetLooping(const std::string& catName);
00291  
00314     void Write(const std::string& cifFileName, const bool sortTables = false,
00315       const bool writeEmptyTables = false);
00316 
00337     void Write(const std::string& cifFileName,
00338       const std::vector<std::string>& tableOrder,
00339       const bool writeEmptyTables = false);
00340 
00362     void Write(std::ostream& outStream, const bool sortTables = false,
00363       const bool writeEmptyTables = false);
00364 
00388     void WriteNmrStar(const std::string& nmrStarFileName,
00389       const std::string& globalBlockName,  const bool sortTables = false,
00390       const bool writeEmptyTables = false);
00391 
00412     int DataChecking(CifFile& dicRef, const std::string& diagFileName,
00413       const bool extraChecks = false);
00414 
00435     int DataChecking(Block& block, Block& refBlock, std::ostringstream& buf,
00436       const bool extraChecks = false);
00437 
00454     void SetEnumCheck(bool caseSense = false);
00455 
00470     bool GetEnumCheck();
00471 
00485     const std::string& GetParsingDiags();
00486 
00487 
00503     void FindCifNullRows(std::vector<unsigned int>& nullRowsIndices,
00504       const ISTable& isTable);
00505 
00506     void GetAttributeValue(std::string& attribVal, const std::string& blockId,
00507       const std::string& category, const std::string& attribute);
00508     void GetAttributeValueIf(std::string& attribVal, const std::string& blockId,
00509       const std::string& category, const std::string& attributeA,
00510       const std::string& attributeB, const std::string& valB);
00511     bool IsAttributeValueDefined(const std::string& blockId,
00512       const std::string& category, const std::string& attribute);
00513 
00514     void SetAttributeValue(const std::string& blockId,
00515       const std::string& category,
00516       const std::string& attribute, const std::string& value,
00517       const bool create = false);
00518     void SetAttributeValueIf(const std::string& blockId,
00519       const std::string& category, const std::string& attributeA,
00520       const std::string& valA,
00521       const std::string& attributeB, const std::string& valB,
00522        const bool create = false);
00523     void SetAttributeValueIfNull(const std::string& blockId,
00524       const std::string& category, const std::string& attribute,
00525       const std::string& value);
00526 
00527     void GetAttributeValues(std::vector<std::string>& strings,
00528       const std::string& blockId,
00529       const std::string& category, const std::string& attribute);
00530     void GetAttributeValuesIf(std::vector<std::string>& strings, 
00531       const std::string& blockId, const std::string& category,
00532       const std::string& attributeA, 
00533       const std::string& attributeB, const std::string& valB);
00534 
00535     void SetAttributeValues(const std::string& blockId,
00536       const std::string& category, const std::string& attribute,
00537       const std::vector<std::string>& values);
00538 
00539 #ifdef VLAD_TO_CIF_FILE_NOT_USED
00540     void del_attribute_value_where(CifFile *fobj, const char *blockId,
00541       const char *category, const char *attributeB, const char *valB);
00542 #endif // VLAD_TO_CIF_FILE_NOT_USED not defined
00543 
00544     int CheckCategories(Block& block, Block& refBlock, std::ostringstream& log);
00545     void CheckCategoryKey(Block& block, std::ostringstream& log);
00546     void CheckItemsTable(Block& block, std::ostringstream& log);
00547     int CheckItems(Block& block, Block& refBlock, std::ostringstream& log);
00548 
00549 
00550   protected:
00551     static const unsigned int STD_PRINT_SPACING = 3;
00552     static const unsigned int SMART_PRINT_SPACING = 1;
00553     static const unsigned int HEADER_SPACING = 40;
00554 
00555     enum eIdentType
00556     {
00557         eNONE = 0,
00558         eLEFT,
00559         eRIGHT
00560     };
00561 
00562     std::string _beginDataKeyword;
00563     std::string _endDataKeyword;
00564 
00565     std::string _beginLoopKeyword;
00566     std::string _endLoopKeyword;
00567 
00568     unsigned int _maxCifLineLength;
00569     std::string _nullValue;
00570     bool _verbose;
00571     bool _smartPrint;
00572     std::string _quotes;
00573     std::map<std::string, bool> _looping;
00574     bool _enumCaseSense;
00575 
00576     int _IsQuotableText(const std::string& itemValue);
00577     eIdentType _FindPrintType(const std::vector<std::string>& values);
00578 
00579     void _PrintItemIdent(std::ostream& cifo, unsigned int& linePos);
00580     void _PrintItemName(std::ostream& cifo, const std::string& category,
00581       const std::string& itemName, unsigned int& linePos);
00582     void _PrintPostItemSeparator(std::ostream& cifo, unsigned int& linePos,
00583       const bool ident = false, const unsigned int numSpaces = 1);
00584 
00585     int _PrintItemValue(std::ostream& cifo, const std::string& itemValue,
00586       unsigned int& linePos, const eIdentType identType = eNONE,
00587       const unsigned int width = 0);
00588 
00589     int _PrintItemNameInHeader(std::ostream& cifo, const std::string& itemValue,
00590       unsigned int& linePos, const eIdentType identType = eNONE,
00591       const unsigned int width = 0);
00592 
00593     void _PrintHeaderedItems(std::ostream& cifo,
00594       const std::vector<std::string>& colNames,
00595       const std::vector<unsigned int>& colWidths,
00596       const std::vector<eIdentType> colPrintType);
00597 
00598     void Write(std::ostream& cifo, const std::vector<std::string>& catOrder,
00599       const bool writeEmptyTables = false);
00600 
00601     void Write(std::ostream& cifo, std::vector<unsigned int>& tables,
00602       const bool writeEmptyTables = false);
00603 
00604 
00605   private:
00606     std::string _srcFileName;
00607 
00608     bool _extraChecks;
00609 
00610     void Init();
00611 
00612     bool IsCatDefinedInRef(const std::string& catName, ISTable& catTable);
00613     bool IsItemDefinedInRef(const std::string& catName,
00614       const std::string& itemName, ISTable& refItemTable);
00615     void CheckKeyItems(const std::string& blockName, ISTable& catTable,
00616       ISTable& keyTable, std::ostringstream& log);
00617     void CheckKeyValues(const std::vector<std::string>& keyItems,
00618       ISTable& catTable, std::ostringstream& log);
00619 
00620     void GetKeyAttributes(std::vector<std::string>& keyAttributes,
00621       const std::string& catTableName, ISTable& catKeyTable);
00622     void CheckKeyItems(const std::string& blockName, ISTable& catTable,
00623       const std::vector<std::string>& keyAttributes, std::ostringstream& log);
00624 
00625     void CheckMandatoryItems(const std::string& blockName, ISTable& catTable,
00626       ISTable& refItemTable, const std::vector<std::string>& keyItems,
00627       std::ostringstream& log);
00628 
00629     void CheckAndRectifyItemTypeCode(Block& block, std::ostringstream& log);
00630 
00631     int CheckRegExpRangeEnum(Block& block, ISTable& catTable,
00632       const std::string& attribName, ISTable& itemTypeTable,
00633       ISTable& itemTypeListTable, ISTable& itemRangeTable,
00634       ISTable& itemEnumTable, ISTable& parChildTable, ISTable* itemAliasesP,
00635       std::ostringstream& log);
00636 
00637     int CheckCellRange(const std::string& cell, const std::string& typeCode,
00638       const std::vector<std::string>& minlist,
00639       const std::vector<std::string>& maxlist);
00640 
00641     int CheckCellEnum(const std::string& cell, const std::string& typeCode,
00642       const std::string& primCode, const std::vector<std::string>& enumlist);
00643 
00644     int CheckCellFloatRange(const std::string& cell,
00645       const std::vector<std::string>& minlist,
00646       const std::vector<std::string>& maxlist);
00647 
00648     int CheckCellIntRange(const std::string& cell,
00649       const std::vector<std::string>& minlist,
00650       const std::vector<std::string>& maxlist);
00651 
00652     int CheckCellFloatEnum(const std::string& cell,
00653       const std::vector<std::string>& enumlist);
00654 
00655     int CheckCellIntEnum(const std::string& cell,
00656       const std::vector<std::string>& enumlist);
00657 
00658     int CheckCellOtherEnum(const std::string& cell, const std::string& primCode,
00659       const std::vector<std::string>& enumlist);
00660 
00661     void GetItemTypeCode(std::string& typeCode, const std::string& cifItemName,
00662       ISTable& itemTypeTable);
00663 
00664     void ConvertEscapedString(const std::string& inString,
00665       std::string& outString);
00666 };
00667 
00668 
00669 inline bool CifFile::GetVerbose()
00670 {
00671     return(_verbose);
00672 }
00673 
00674 
00675 inline void CifFile::SetSmartPrint(bool smartPrint)
00676 {
00677     _smartPrint = smartPrint;
00678 }
00679 
00680 
00681 inline bool CifFile::IsSmartPrint()
00682 {
00683     return(_smartPrint);
00684 }
00685 
00686 
00687 #endif

Generated on Thu Sep 29 09:19:18 2011 for cif-file-v1.1.0 by  doxygen 1.4.7