librcsb-core-wrapper 1.005
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
47class 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
56 {
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
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
417 int DataChecking(CifFile& dicRef, const std::string& diagFileName,
418 const bool extraDictChecks = false, const bool extraCifChecks = false);
419
443 int DataChecking(Block& block, Block& refBlock, std::ostringstream& buf,
444 const bool extraDictChecks = false, const bool extraCifChecks = false);
445
462 void SetEnumCheck(bool caseSense = false);
463
479
493 const std::string& GetParsingDiags();
494
495
511 void FindCifNullRows(std::vector<unsigned int>& nullRowsIndices,
512 const ISTable& isTable);
513
514 void GetAttributeValue(std::string& attribVal, const std::string& blockId,
515 const std::string& category, const std::string& attribute);
516 void GetAttributeValueIf(std::string& attribVal, const std::string& blockId,
517 const std::string& category, const std::string& attributeA,
518 const std::string& attributeB, const std::string& valB);
519 bool IsAttributeValueDefined(const std::string& blockId,
520 const std::string& category, const std::string& attribute);
521
522 void SetAttributeValue(const std::string& blockId,
523 const std::string& category,
524 const std::string& attribute, const std::string& value,
525 const bool create = false);
526 void SetAttributeValueIf(const std::string& blockId,
527 const std::string& category, const std::string& attributeA,
528 const std::string& valA,
529 const std::string& attributeB, const std::string& valB,
530 const bool create = false);
531 void SetAttributeValueIfNull(const std::string& blockId,
532 const std::string& category, const std::string& attribute,
533 const std::string& value);
534
535 void GetAttributeValues(std::vector<std::string>& strings,
536 const std::string& blockId,
537 const std::string& category, const std::string& attribute);
538 void GetAttributeValuesIf(std::vector<std::string>& strings,
539 const std::string& blockId, const std::string& category,
540 const std::string& attributeA,
541 const std::string& attributeB, const std::string& valB);
542
543 void SetAttributeValues(const std::string& blockId,
544 const std::string& category, const std::string& attribute,
545 const std::vector<std::string>& values);
546
547#ifdef VLAD_TO_CIF_FILE_NOT_USED
548 void del_attribute_value_where(CifFile *fobj, const char *blockId,
549 const char *category, const char *attributeB, const char *valB);
550#endif // VLAD_TO_CIF_FILE_NOT_USED not defined
551
552 int CheckCategories(Block& block, Block& refBlock, std::ostringstream& log);
553 void CheckCategoryKey(Block& block, std::ostringstream& log);
554 void CheckItemsTable(Block& block, std::ostringstream& log);
555 int CheckItems(Block& block, Block& refBlock, std::ostringstream& log);
556
557
558 protected:
559 static const unsigned int STD_PRINT_SPACING = 3;
560 static const unsigned int SMART_PRINT_SPACING = 1;
561 static const unsigned int HEADER_SPACING = 40;
562
564 {
565 eNONE = 0,
567 eRIGHT
568 };
569
570 std::string _beginDataKeyword;
571 std::string _endDataKeyword;
572
573 std::string _beginLoopKeyword;
574 std::string _endLoopKeyword;
575
576 unsigned int _maxCifLineLength;
577 std::string _nullValue;
580 std::string _quotes;
581 std::map<std::string, bool> _looping;
583
584 int _IsQuotableText(const std::string& itemValue);
585 eIdentType _FindPrintType(const std::vector<std::string>& values);
586
587 void _PrintItemIdent(std::ostream& cifo, unsigned int& linePos);
588 void _PrintItemName(std::ostream& cifo, const std::string& category,
589 const std::string& itemName, unsigned int& linePos);
590 void _PrintPostItemSeparator(std::ostream& cifo, unsigned int& linePos,
591 const bool ident = false, const unsigned int numSpaces = 1);
592
593 int _PrintItemValue(std::ostream& cifo, const std::string& itemValue,
594 unsigned int& linePos, const eIdentType identType = eNONE,
595 const unsigned int width = 0);
596
597 int _PrintItemNameInHeader(std::ostream& cifo, const std::string& itemValue,
598 unsigned int& linePos, const eIdentType identType = eNONE,
599 const unsigned int width = 0);
600
601 void _PrintHeaderedItems(std::ostream& cifo,
602 const std::vector<std::string>& colNames,
603 const std::vector<unsigned int>& colWidths,
604 const std::vector<eIdentType> colPrintType);
605
606 void Write(std::ostream& cifo, const std::vector<std::string>& catOrder,
607 const bool writeEmptyTables = false);
608
609 void Write(std::ostream& cifo, std::vector<unsigned int>& tables,
610 const bool writeEmptyTables = false);
611
612
613 private:
614 std::string _srcFileName;
615
616 bool _extraDictChecks;
617 bool _extraCifChecks;
618
619 void Init();
620
621 bool IsCatDefinedInRef(const std::string& catName, ISTable& catTable);
622 bool IsItemDefinedInRef(const std::string& catName,
623 const std::string& itemName, ISTable& refItemTable);
624 void CheckKeyItems(const std::string& blockName, ISTable& catTable,
625 ISTable& keyTable, std::ostringstream& log);
626 void CheckKeyValues(const std::vector<std::string>& keyItems,
627 ISTable& catTable, std::ostringstream& log);
628
629 void GetKeyAttributes(std::vector<std::string>& keyAttributes,
630 const std::string& catTableName, ISTable& catKeyTable);
631 void CheckKeyItems(const std::string& blockName, ISTable& catTable,
632 const std::vector<std::string>& keyAttributes, std::ostringstream& log);
633
634 void CheckMandatoryItems(const std::string& blockName, ISTable& catTable,
635 ISTable& refItemTable, const std::vector<std::string>& keyItems,
636 std::ostringstream& log);
637
638 void CheckAndRectifyItemTypeCode(Block& block, std::ostringstream& log);
639 void RectifyItemTypeCode(std::string& retItemTypeCode,
640 std::ostringstream& log, Block& block, CifParentChild& cifParentChild,
641 const std::string& cifItemName);
642
643 int CheckRegExpRangeEnum(Block& block, ISTable& catTable,
644 const std::string& attribName, ISTable& itemTypeTable,
645 ISTable& itemTypeListTable, ISTable* itemRangeTableP,
646 ISTable* itemEnumTableP, ISTable& parChildTable, ISTable* itemAliasesP,
647 std::ostringstream& log);
648
649 int CheckCellRange(const std::string& cell, const std::string& typeCode,
650 const std::vector<std::string>& minlist,
651 const std::vector<std::string>& maxlist);
652
653 int CheckCellEnum(const std::string& cell, const std::string& typeCode,
654 const std::string& primCode, const std::vector<std::string>& enumlist);
655
656 int CheckCellFloatRange(const std::string& cell,
657 const std::vector<std::string>& minlist,
658 const std::vector<std::string>& maxlist);
659
660 int CheckCellIntRange(const std::string& cell,
661 const std::vector<std::string>& minlist,
662 const std::vector<std::string>& maxlist);
663
664 int CheckCellFloatEnum(const std::string& cell,
665 const std::vector<std::string>& enumlist);
666
667 int CheckCellIntEnum(const std::string& cell,
668 const std::vector<std::string>& enumlist);
669
670 int CheckCellOtherEnum(const std::string& cell, const std::string& primCode,
671 const std::vector<std::string>& enumlist);
672
673 void GetItemTypeCode(std::string& typeCode, const std::string& cifItemName,
674 ISTable& itemTypeTable);
675
676 void ConvertEscapedString(const std::string& inString,
677 std::string& outString);
678};
679
680
682{
683 return(_verbose);
684}
685
686
687inline void CifFile::SetSmartPrint(bool smartPrint)
688{
689 _smartPrint = smartPrint;
690}
691
692
694{
695 return(_smartPrint);
696}
697
698
699#endif
Header file for CifParentChild class.
eFileMode
Definition: Serializer.h:34
Header file for Block and TableFile classes.
Public class that represents a data block, that contains tables.
Definition: TableFile.h:41
eCompareType
Definition: GenString.h:27
@ eCASE_SENSITIVE
Definition: GenString.h:28
Public class that represents a CIF file, composed of blocks with tables.
Definition: CifFile.h:48
static const unsigned int STD_CIF_LINE_LENGTH
Definition: CifFile.h:53
eIdentType
Definition: CifFile.h:564
@ eRIGHT
Definition: CifFile.h:567
@ eLEFT
Definition: CifFile.h:566
@ eNONE
Definition: CifFile.h:565
int DataChecking(Block &block, Block &refBlock, std::ostringstream &buf, const bool extraDictChecks=false, const bool extraCifChecks=false)
eIdentType _FindPrintType(const std::vector< std::string > &values)
bool GetLooping(const std::string &catName)
const std::string & GetSrcFileName()
bool _verbose
Definition: CifFile.h:578
void SetAttributeValue(const std::string &blockId, const std::string &category, const std::string &attribute, const std::string &value, const bool create=false)
void SetAttributeValueIfNull(const std::string &blockId, const std::string &category, const std::string &attribute, const std::string &value)
bool GetVerbose()
Definition: CifFile.h:681
std::string _parsingDiags
Definition: CifFile.h:50
bool GetEnumCheck()
void GetAttributeValuesIf(std::vector< std::string > &strings, const std::string &blockId, const std::string &category, const std::string &attributeA, const std::string &attributeB, const std::string &valB)
std::string _nullValue
Definition: CifFile.h:577
void SetLooping(const std::string &catName, bool looping=false)
void Write(const std::string &cifFileName, const bool sortTables=false, const bool writeEmptyTables=false)
int _IsQuotableText(const std::string &itemValue)
CifFile(const eFileMode fileMode, const std::string &fileName, const bool verbose=false, const Char::eCompareType caseSense=Char::eCASE_SENSITIVE, const unsigned int maxLineLength=STD_CIF_LINE_LENGTH, const std::string &nullValue=CifString::UnknownValue)
int CheckCategories(Block &block, Block &refBlock, std::ostringstream &log)
void SetSrcFileName(const std::string &srcFileName)
std::string _endLoopKeyword
Definition: CifFile.h:574
eQuoting
Definition: CifFile.h:56
@ eSINGLE
Definition: CifFile.h:57
@ eDOUBLE
Definition: CifFile.h:58
bool IsSmartPrint()
Definition: CifFile.h:693
int DataChecking(CifFile &dicRef, const std::string &diagFileName, const bool extraDictChecks=false, const bool extraCifChecks=false)
void Write(std::ostream &cifo, std::vector< unsigned int > &tables, const bool writeEmptyTables=false)
void _PrintHeaderedItems(std::ostream &cifo, const std::vector< std::string > &colNames, const std::vector< unsigned int > &colWidths, const std::vector< eIdentType > colPrintType)
void SetAttributeValueIf(const std::string &blockId, const std::string &category, const std::string &attributeA, const std::string &valA, const std::string &attributeB, const std::string &valB, const bool create=false)
void SetQuoting(eQuoting quoting)
bool IsAttributeValueDefined(const std::string &blockId, const std::string &category, const std::string &attribute)
void WriteNmrStar(const std::string &nmrStarFileName, const std::string &globalBlockName, const bool sortTables=false, const bool writeEmptyTables=false)
void GetAttributeValues(std::vector< std::string > &strings, const std::string &blockId, const std::string &category, const std::string &attribute)
void GetAttributeValueIf(std::string &attribVal, const std::string &blockId, const std::string &category, const std::string &attributeA, const std::string &attributeB, const std::string &valB)
std::map< std::string, bool > _looping
Definition: CifFile.h:581
int CheckItems(Block &block, Block &refBlock, std::ostringstream &log)
void _PrintItemName(std::ostream &cifo, const std::string &category, const std::string &itemName, unsigned int &linePos)
const std::string & GetParsingDiags()
std::string _quotes
Definition: CifFile.h:580
static const unsigned int SMART_PRINT_SPACING
Definition: CifFile.h:560
static const unsigned int STD_PRINT_SPACING
Definition: CifFile.h:559
int _PrintItemNameInHeader(std::ostream &cifo, const std::string &itemValue, unsigned int &linePos, const eIdentType identType=eNONE, const unsigned int width=0)
std::string _checkingDiags
Definition: CifFile.h:51
void SetSmartPrint(bool smartPrint=true)
Definition: CifFile.h:687
bool _enumCaseSense
Definition: CifFile.h:582
void SetEnumCheck(bool caseSense=false)
void _PrintPostItemSeparator(std::ostream &cifo, unsigned int &linePos, const bool ident=false, const unsigned int numSpaces=1)
void FindCifNullRows(std::vector< unsigned int > &nullRowsIndices, const ISTable &isTable)
std::string _beginLoopKeyword
Definition: CifFile.h:573
void GetAttributeValue(std::string &attribVal, const std::string &blockId, const std::string &category, const std::string &attribute)
unsigned int GetQuoting()
std::string _endDataKeyword
Definition: CifFile.h:571
void _PrintItemIdent(std::ostream &cifo, unsigned int &linePos)
bool _smartPrint
Definition: CifFile.h:579
std::string _beginDataKeyword
Definition: CifFile.h:570
unsigned int _maxCifLineLength
Definition: CifFile.h:576
void Write(std::ostream &outStream, const bool sortTables=false, const bool writeEmptyTables=false)
CifFile(const bool verbose=false, const Char::eCompareType caseSense=Char::eCASE_SENSITIVE, const unsigned int maxLineLength=STD_CIF_LINE_LENGTH, const std::string &nullValue=CifString::UnknownValue)
void SetAttributeValues(const std::string &blockId, const std::string &category, const std::string &attribute, const std::vector< std::string > &values)
void Write(std::ostream &cifo, const std::vector< std::string > &catOrder, const bool writeEmptyTables=false)
void Write(const std::string &cifFileName, const std::vector< std::string > &tableOrder, const bool writeEmptyTables=false)
void CheckCategoryKey(Block &block, std::ostringstream &log)
void CheckItemsTable(Block &block, std::ostringstream &log)
static const unsigned int HEADER_SPACING
Definition: CifFile.h:561
int _PrintItemValue(std::ostream &cifo, const std::string &itemValue, unsigned int &linePos, const eIdentType identType=eNONE, const unsigned int width=0)
Definition: CifParentChild.h:38
static const std::string UnknownValue
Definition: CifString.h:128
Public class that respresents a two-dimensional table of strings.
Definition: ISTable.h:54
Public class that represents a file composed of blocks with tables.
Definition: TableFile.h:362