RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
BaseFileSource.h
1/***********************************************************************
2 * The rDock program was developed from 1998 - 2006 by the software team
3 * at RiboTargets (subsequently Vernalis (R&D) Ltd).
4 * In 2006, the software was licensed to the University of York for
5 * maintenance and distribution.
6 * In 2012, Vernalis and the University of York agreed to release the
7 * program as Open Source software.
8 * This version is licensed under GNU-LGPL version 3.0 with support from
9 * the University of Barcelona.
10 * http://rdock.sourceforge.net/
11 ***********************************************************************/
12
13// Abstract base class for file-based input
14
15#ifndef _RBTBASEFILESOURCE_H_
16#define _RBTBASEFILESOURCE_H_
17
18#include <fstream>
19
20#include "rxdock/Config.h"
21
22#include <nlohmann/json.hpp>
23
24using json = nlohmann::json;
25
26namespace rxdock {
27
28// useful typedefs
29typedef std::string FileRec;
30typedef std::vector<FileRec> FileRecList;
31typedef FileRecList::iterator FileRecListIter;
32
33// Max line length expected in file
34const int MAXLINELENGTH = 255;
35
37public:
38 // Constructors
39 // BaseFileSource(const char* fileName);
40 BaseFileSource(const std::string &fileName);
41 BaseFileSource(const std::string &fileName, const std::string &strRecDelim);
42
43 // Default destructor
44 virtual ~BaseFileSource();
45
46 friend void to_json(json &j, const BaseFileSource &baseFileSource);
47 friend void from_json(const json &j, BaseFileSource &baseFileSource);
48
49 // Public methods
50
51 RBTDLL_EXPORT std::string GetFileName();
52 // void SetFileName(const char* fileName);
53 void SetFileName(const std::string &fileName);
54
55 // Status and StatusOK parse the file to check for errors
56 bool StatusOK();
57 RBTDLL_EXPORT Error Status();
58
59 // FileStatus and FileStatusOK just try and read the file
60 RBTDLL_EXPORT bool FileStatusOK();
61 Error FileStatus();
62
63 // Multi-record methods
64 bool isMultiRecordSupported() { return m_bMultiRec; }
65 RBTDLL_EXPORT void NextRecord();
66 void Rewind();
67 RBTDLL_EXPORT std::size_t GetEstimatedNumRecords();
68
69protected:
71 // Protected member functions
72 // PURE VIRTUAL - MUST BE OVERRIDDEN IN DERIVED CLASSES
73 virtual void Parse() = 0;
74 // chance to give false when record delimiter at the beginning
75 void Read(bool aDelimiterAtEnd = true);
77
78 // Protected data
79protected:
80 bool m_bParsedOK; // For use by Parse
81 FileRecList m_lineRecs; // Allow direct access to cache from derived
82 // classes
83
84 // Private member functions
85private:
86 BaseFileSource(); // Disable default constructor
88 const BaseFileSource &); // Copy constructor disabled by default
90 operator=(const BaseFileSource &); // Copy assignment disabled by default
91 void Open();
92 void Close();
93 void ClearCache();
94
95 // Private data
96private:
97 std::string m_strFileName;
98 std::size_t m_fileSize;
99 bool m_bReadOK; // For use by Read
100 std::size_t m_numReads;
101 std::size_t m_bytesRead;
102 std::ifstream m_fileIn;
103 char *m_szBuf; // Line buffer
104 bool m_bFileOpen; // Keep track of whether we've opened the file or not
105 bool m_bMultiRec; // Is file multi-record ?
106 std::string m_strRecDelim; // Record delimiter
107};
108
109void to_json(json &j, const BaseFileSource &baseFileSource);
110void from_json(const json &j, BaseFileSource &baseFileSource);
111
112} // namespace rxdock
113
114#endif //_RBTBASEFILESOURCE_H_
Definition BaseFileSource.h:36
Definition Error.h:59