CifFile.h
Go to the documentation of this file.
//$$FILE$$
//$$VERSION$$
//$$DATE$$
//$$LICENSE$$
/*
PURPOSE: Base class for read/write cif files
*/
#ifndef CIFFILE_H
#define CIFFILE_H
#include <string>
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include <rcsb/GenString.h>
#include <rcsb/CifString.h>
#include <rcsb/TableFile.h>
#include <rcsb/CifParentChild.h>
class CifFile : public TableFile
{
public:
std::string _parsingDiags;
std::string _checkingDiags;
static const unsigned int STD_CIF_LINE_LENGTH = 80;
enum eQuoting
{
eSINGLE = 0,
eDOUBLE
};
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);
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);
~CifFile();
void SetSrcFileName(const std::string& srcFileName);
const std::string& GetSrcFileName();
inline bool GetVerbose();
inline void SetSmartPrint(bool smartPrint = true);
inline bool IsSmartPrint();
void SetQuoting(eQuoting quoting);
unsigned int GetQuoting();
void SetLooping(const std::string& catName, bool looping = false);
bool GetLooping(const std::string& catName);
void Write(const std::string& cifFileName, const bool sortTables = false,
const bool writeEmptyTables = false);
void Write(const std::string& cifFileName,
const std::vector<std::string>& tableOrder,
const bool writeEmptyTables = false);
void Write(std::ostream& outStream, const bool sortTables = false,
const bool writeEmptyTables = false);
void WriteNmrStar(const std::string& nmrStarFileName,
const std::string& globalBlockName, const bool sortTables = false,
const bool writeEmptyTables = false);
int DataChecking(CifFile& dicRef, const std::string& diagFileName,
const bool extraChecks = false);
int DataChecking(Block& block, Block& refBlock, std::ostringstream& buf,
const bool extraChecks = false);
void SetEnumCheck(bool caseSense = false);
bool GetEnumCheck();
const std::string& GetParsingDiags();
void FindCifNullRows(std::vector<unsigned int>& nullRowsIndices,
const ISTable& isTable);
void GetAttributeValue(std::string& attribVal, 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);
bool IsAttributeValueDefined(const std::string& blockId,
const std::string& category, const std::string& attribute);
void SetAttributeValue(const std::string& blockId,
const std::string& category,
const std::string& attribute, const std::string& value,
const bool create = false);
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 SetAttributeValueIfNull(const std::string& blockId,
const std::string& category, const std::string& attribute,
const std::string& value);
void GetAttributeValues(std::vector<std::string>& strings,
const std::string& blockId,
const std::string& category, const std::string& attribute);
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);
void SetAttributeValues(const std::string& blockId,
const std::string& category, const std::string& attribute,
const std::vector<std::string>& values);
#ifdef VLAD_TO_CIF_FILE_NOT_USED
void del_attribute_value_where(CifFile *fobj, const char *blockId,
const char *category, const char *attributeB, const char *valB);
#endif // VLAD_TO_CIF_FILE_NOT_USED not defined
int CheckCategories(Block& block, Block& refBlock, std::ostringstream& log);
void CheckCategoryKey(Block& block, std::ostringstream& log);
void CheckItemsTable(Block& block, std::ostringstream& log);
int CheckItems(Block& block, Block& refBlock, std::ostringstream& log);
protected:
static const unsigned int STD_PRINT_SPACING = 3;
static const unsigned int SMART_PRINT_SPACING = 1;
static const unsigned int HEADER_SPACING = 40;
enum eIdentType
{
eNONE = 0,
eLEFT,
eRIGHT
};
std::string _beginDataKeyword;
std::string _endDataKeyword;
std::string _beginLoopKeyword;
std::string _endLoopKeyword;
unsigned int _maxCifLineLength;
std::string _nullValue;
bool _verbose;
bool _smartPrint;
std::string _quotes;
std::map<std::string, bool> _looping;
bool _enumCaseSense;
int _IsQuotableText(const std::string& itemValue);
eIdentType _FindPrintType(const std::vector<std::string>& values);
void _PrintItemIdent(std::ostream& cifo, unsigned int& linePos);
void _PrintItemName(std::ostream& cifo, const std::string& category,
const std::string& itemName, unsigned int& linePos);
void _PrintPostItemSeparator(std::ostream& cifo, unsigned int& linePos,
const bool ident = false, const unsigned int numSpaces = 1);
int _PrintItemValue(std::ostream& cifo, const std::string& itemValue,
unsigned int& linePos, const eIdentType identType = eNONE,
const unsigned int width = 0);
int _PrintItemNameInHeader(std::ostream& cifo, const std::string& itemValue,
unsigned int& linePos, const eIdentType identType = eNONE,
const unsigned int width = 0);
void _PrintHeaderedItems(std::ostream& cifo,
const std::vector<std::string>& colNames,
const std::vector<unsigned int>& colWidths,
const std::vector<eIdentType> colPrintType);
void Write(std::ostream& cifo, const std::vector<std::string>& catOrder,
const bool writeEmptyTables = false);
void Write(std::ostream& cifo, std::vector<unsigned int>& tables,
const bool writeEmptyTables = false);
private:
std::string _srcFileName;
bool _extraChecks;
void Init();
bool IsCatDefinedInRef(const std::string& catName, ISTable& catTable);
bool IsItemDefinedInRef(const std::string& catName,
const std::string& itemName, ISTable& refItemTable);
void CheckKeyItems(const std::string& blockName, ISTable& catTable,
ISTable& keyTable, std::ostringstream& log);
void CheckKeyValues(const std::vector<std::string>& keyItems,
ISTable& catTable, std::ostringstream& log);
void GetKeyAttributes(std::vector<std::string>& keyAttributes,
const std::string& catTableName, ISTable& catKeyTable);
void CheckKeyItems(const std::string& blockName, ISTable& catTable,
const std::vector<std::string>& keyAttributes, std::ostringstream& log);
void CheckMandatoryItems(const std::string& blockName, ISTable& catTable,
ISTable& refItemTable, const std::vector<std::string>& keyItems,
std::ostringstream& log);
void CheckAndRectifyItemTypeCode(Block& block, std::ostringstream& log);
void RectifyItemTypeCode(std::string& retItemTypeCode,
std::ostringstream& log, Block& block, CifParentChild& cifParentChild,
const std::string& cifItemName);
int CheckRegExpRangeEnum(Block& block, ISTable& catTable,
const std::string& attribName, ISTable& itemTypeTable,
ISTable& itemTypeListTable, ISTable* itemRangeTableP,
ISTable* itemEnumTableP, ISTable& parChildTable, ISTable* itemAliasesP,
std::ostringstream& log);
int CheckCellRange(const std::string& cell, const std::string& typeCode,
const std::vector<std::string>& minlist,
const std::vector<std::string>& maxlist);
int CheckCellEnum(const std::string& cell, const std::string& typeCode,
const std::string& primCode, const std::vector<std::string>& enumlist);
int CheckCellFloatRange(const std::string& cell,
const std::vector<std::string>& minlist,
const std::vector<std::string>& maxlist);
int CheckCellIntRange(const std::string& cell,
const std::vector<std::string>& minlist,
const std::vector<std::string>& maxlist);
int CheckCellFloatEnum(const std::string& cell,
const std::vector<std::string>& enumlist);
int CheckCellIntEnum(const std::string& cell,
const std::vector<std::string>& enumlist);
int CheckCellOtherEnum(const std::string& cell, const std::string& primCode,
const std::vector<std::string>& enumlist);
void GetItemTypeCode(std::string& typeCode, const std::string& cifItemName,
ISTable& itemTypeTable);
void ConvertEscapedString(const std::string& inString,
std::string& outString);
};
inline bool CifFile::GetVerbose()
{
return(_verbose);
}
inline void CifFile::SetSmartPrint(bool smartPrint)
{
_smartPrint = smartPrint;
}
inline bool CifFile::IsSmartPrint()
{
return(_smartPrint);
}
#endif