librcsb-core-wrapper  1.000
CifFile.h
Go to the documentation of this file.
1 //$$FILE$$
2 //$$VERSION$$
3 //$$DATE$$
4 //$$LICENSE$$
5 
6 
14 /*
15  PURPOSE: Base class for read/write cif files
16 */
17 
18 
19 #ifndef CIFFILE_H
20 #define CIFFILE_H
21 
22 
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <iostream>
27 #include <sstream>
28 
29 #include <rcsb/GenString.h>
30 #include <rcsb/CifString.h>
31 #include <rcsb/TableFile.h>
32 #include <rcsb/CifParentChild.h>
33 
34 
35 
47 class CifFile : public TableFile
48 {
49  public:
50  std::string _parsingDiags;
51  std::string _checkingDiags;
52 
53  static const unsigned int STD_CIF_LINE_LENGTH = 80;
54 
55  enum eQuoting
56  {
57  eSINGLE = 0,
59  };
60 
92  CifFile(const eFileMode fileMode, const std::string& fileName,
93  const bool verbose = false, const Char::eCompareType
94  caseSense = Char::eCASE_SENSITIVE,
95  const unsigned int maxLineLength = STD_CIF_LINE_LENGTH,
96  const std::string& nullValue = CifString::UnknownValue);
97 
123  CifFile(const bool verbose = false, const Char::eCompareType
124  caseSense = Char::eCASE_SENSITIVE,
125  const unsigned int maxLineLength = STD_CIF_LINE_LENGTH,
126  const std::string& nullValue = CifString::UnknownValue);
127 
141  ~CifFile();
142 
156  void SetSrcFileName(const std::string& srcFileName);
157 
158 
172  const std::string& GetSrcFileName();
173 
174 
189  inline bool GetVerbose();
190 
207  inline void SetSmartPrint(bool smartPrint = true);
208 
209 
224  inline bool IsSmartPrint();
225 
241  void SetQuoting(eQuoting quoting);
242 
257  unsigned int GetQuoting();
258 
277  void SetLooping(const std::string& catName, bool looping = false);
278 
292  bool GetLooping(const std::string& catName);
293 
316  void Write(const std::string& cifFileName, const bool sortTables = false,
317  const bool writeEmptyTables = false);
318 
339  void Write(const std::string& cifFileName,
340  const std::vector<std::string>& tableOrder,
341  const bool writeEmptyTables = false);
342 
364  void Write(std::ostream& outStream, const bool sortTables = false,
365  const bool writeEmptyTables = false);
366 
390  void WriteNmrStar(const std::string& nmrStarFileName,
391  const std::string& globalBlockName, const bool sortTables = false,
392  const bool writeEmptyTables = false);
393 
414  int DataChecking(CifFile& dicRef, const std::string& diagFileName,
415  const bool extraChecks = false);
416 
437  int DataChecking(Block& block, Block& refBlock, std::ostringstream& buf,
438  const bool extraChecks = false);
439 
456  void SetEnumCheck(bool caseSense = false);
457 
472  bool GetEnumCheck();
473 
487  const std::string& GetParsingDiags();
488 
489 
505  void FindCifNullRows(std::vector<unsigned int>& nullRowsIndices,
506  const ISTable& isTable);
507 
508  void GetAttributeValue(std::string& attribVal, const std::string& blockId,
509  const std::string& category, const std::string& attribute);
510  void GetAttributeValueIf(std::string& attribVal, const std::string& blockId,
511  const std::string& category, const std::string& attributeA,
512  const std::string& attributeB, const std::string& valB);
513  bool IsAttributeValueDefined(const std::string& blockId,
514  const std::string& category, const std::string& attribute);
515 
516  void SetAttributeValue(const std::string& blockId,
517  const std::string& category,
518  const std::string& attribute, const std::string& value,
519  const bool create = false);
520  void SetAttributeValueIf(const std::string& blockId,
521  const std::string& category, const std::string& attributeA,
522  const std::string& valA,
523  const std::string& attributeB, const std::string& valB,
524  const bool create = false);
525  void SetAttributeValueIfNull(const std::string& blockId,
526  const std::string& category, const std::string& attribute,
527  const std::string& value);
528 
529  void GetAttributeValues(std::vector<std::string>& strings,
530  const std::string& blockId,
531  const std::string& category, const std::string& attribute);
532  void GetAttributeValuesIf(std::vector<std::string>& strings,
533  const std::string& blockId, const std::string& category,
534  const std::string& attributeA,
535  const std::string& attributeB, const std::string& valB);
536 
537  void SetAttributeValues(const std::string& blockId,
538  const std::string& category, const std::string& attribute,
539  const std::vector<std::string>& values);
540 
541 #ifdef VLAD_TO_CIF_FILE_NOT_USED
542  void del_attribute_value_where(CifFile *fobj, const char *blockId,
543  const char *category, const char *attributeB, const char *valB);
544 #endif // VLAD_TO_CIF_FILE_NOT_USED not defined
545 
546  int CheckCategories(Block& block, Block& refBlock, std::ostringstream& log);
547  void CheckCategoryKey(Block& block, std::ostringstream& log);
548  void CheckItemsTable(Block& block, std::ostringstream& log);
549  int CheckItems(Block& block, Block& refBlock, std::ostringstream& log);
550 
551 
552  protected:
553  static const unsigned int STD_PRINT_SPACING = 3;
554  static const unsigned int SMART_PRINT_SPACING = 1;
555  static const unsigned int HEADER_SPACING = 40;
556 
558  {
559  eNONE = 0,
562  };
563 
564  std::string _beginDataKeyword;
565  std::string _endDataKeyword;
566 
567  std::string _beginLoopKeyword;
568  std::string _endLoopKeyword;
569 
570  unsigned int _maxCifLineLength;
571  std::string _nullValue;
572  bool _verbose;
574  std::string _quotes;
575  std::map<std::string, bool> _looping;
577 
578  int _IsQuotableText(const std::string& itemValue);
579  eIdentType _FindPrintType(const std::vector<std::string>& values);
580 
581  void _PrintItemIdent(std::ostream& cifo, unsigned int& linePos);
582  void _PrintItemName(std::ostream& cifo, const std::string& category,
583  const std::string& itemName, unsigned int& linePos);
584  void _PrintPostItemSeparator(std::ostream& cifo, unsigned int& linePos,
585  const bool ident = false, const unsigned int numSpaces = 1);
586 
587  int _PrintItemValue(std::ostream& cifo, const std::string& itemValue,
588  unsigned int& linePos, const eIdentType identType = eNONE,
589  const unsigned int width = 0);
590 
591  int _PrintItemNameInHeader(std::ostream& cifo, const std::string& itemValue,
592  unsigned int& linePos, const eIdentType identType = eNONE,
593  const unsigned int width = 0);
594 
595  void _PrintHeaderedItems(std::ostream& cifo,
596  const std::vector<std::string>& colNames,
597  const std::vector<unsigned int>& colWidths,
598  const std::vector<eIdentType> colPrintType);
599 
600  void Write(std::ostream& cifo, const std::vector<std::string>& catOrder,
601  const bool writeEmptyTables = false);
602 
603  void Write(std::ostream& cifo, std::vector<unsigned int>& tables,
604  const bool writeEmptyTables = false);
605 
606 
607  private:
608  std::string _srcFileName;
609 
610  bool _extraChecks;
611 
612  void Init();
613 
614  bool IsCatDefinedInRef(const std::string& catName, ISTable& catTable);
615  bool IsItemDefinedInRef(const std::string& catName,
616  const std::string& itemName, ISTable& refItemTable);
617  void CheckKeyItems(const std::string& blockName, ISTable& catTable,
618  ISTable& keyTable, std::ostringstream& log);
619  void CheckKeyValues(const std::vector<std::string>& keyItems,
620  ISTable& catTable, std::ostringstream& log);
621 
622  void GetKeyAttributes(std::vector<std::string>& keyAttributes,
623  const std::string& catTableName, ISTable& catKeyTable);
624  void CheckKeyItems(const std::string& blockName, ISTable& catTable,
625  const std::vector<std::string>& keyAttributes, std::ostringstream& log);
626 
627  void CheckMandatoryItems(const std::string& blockName, ISTable& catTable,
628  ISTable& refItemTable, const std::vector<std::string>& keyItems,
629  std::ostringstream& log);
630 
631  void CheckAndRectifyItemTypeCode(Block& block, std::ostringstream& log);
632  void RectifyItemTypeCode(std::string& retItemTypeCode,
633  std::ostringstream& log, Block& block, CifParentChild& cifParentChild,
634  const std::string& cifItemName);
635 
636  int CheckRegExpRangeEnum(Block& block, ISTable& catTable,
637  const std::string& attribName, ISTable& itemTypeTable,
638  ISTable& itemTypeListTable, ISTable* itemRangeTableP,
639  ISTable* itemEnumTableP, ISTable& parChildTable, ISTable* itemAliasesP,
640  std::ostringstream& log);
641 
642  int CheckCellRange(const std::string& cell, const std::string& typeCode,
643  const std::vector<std::string>& minlist,
644  const std::vector<std::string>& maxlist);
645 
646  int CheckCellEnum(const std::string& cell, const std::string& typeCode,
647  const std::string& primCode, const std::vector<std::string>& enumlist);
648 
649  int CheckCellFloatRange(const std::string& cell,
650  const std::vector<std::string>& minlist,
651  const std::vector<std::string>& maxlist);
652 
653  int CheckCellIntRange(const std::string& cell,
654  const std::vector<std::string>& minlist,
655  const std::vector<std::string>& maxlist);
656 
657  int CheckCellFloatEnum(const std::string& cell,
658  const std::vector<std::string>& enumlist);
659 
660  int CheckCellIntEnum(const std::string& cell,
661  const std::vector<std::string>& enumlist);
662 
663  int CheckCellOtherEnum(const std::string& cell, const std::string& primCode,
664  const std::vector<std::string>& enumlist);
665 
666  void GetItemTypeCode(std::string& typeCode, const std::string& cifItemName,
667  ISTable& itemTypeTable);
668 
669  void ConvertEscapedString(const std::string& inString,
670  std::string& outString);
671 };
672 
673 
674 inline bool CifFile::GetVerbose()
675 {
676  return(_verbose);
677 }
678 
679 
680 inline void CifFile::SetSmartPrint(bool smartPrint)
681 {
682  _smartPrint = smartPrint;
683 }
684 
685 
687 {
688  return(_smartPrint);
689 }
690 
691 
692 #endif