RxDock 0.1.0
A fast, versatile, and open-source program for docking ligands to proteins and nucleic acids
Loading...
Searching...
No Matches
BaseFileSink.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 text file-based output. Knows how to Open a file,
14// Write a text cache to the file, and Close the file.
15// It is up to derived classes to provide a Render method to populate the cache
16// with text records of the appropriate format.
17
18#ifndef _RBTBASEFILESINK_H_
19#define _RBTBASEFILESINK_H_
20
21#include <fstream>
22
23#include "rxdock/Config.h"
24
25#include <nlohmann/json.hpp>
26
27using json = nlohmann::json;
28
29namespace rxdock {
30
32public:
34 // Constructors/destructors
35 // BaseFileSink(const char* fileName);
36 BaseFileSink(const std::string &fileName);
37
38 virtual ~BaseFileSink(); // Default destructor
39
40 friend void to_json(json &j, const BaseFileSink &baseFileSink);
41 friend void from_json(const json &j, BaseFileSink &baseFileSink);
42
44 // Public methods
46 std::string GetFileName() const { return m_strFileName; }
47 // void SetFileName(const char* fileName);
48 void SetFileName(const std::string &fileName);
49 bool StatusOK() { return Status().isOK(); }
50 Error Status();
51
52 // PURE VIRTUAL - MUST BE OVERRIDDEN IN DERIVED CLASSES
53 virtual void Render() = 0;
54
55protected:
57 // Protected methods
59 // Write the cache to the file
60 // DM 11 Feb 1999 - add flag to allow the cache to be written without clearing
61 // it
62 void Write(bool bClearCache = true);
63 // Add a complete line to the cache
64 void AddLine(const std::string &fileRec);
65 // Replace a complete line in the cache
66 void ReplaceLine(const std::string &fileRec, unsigned int nRec);
67 // Is cache empty
68 bool isCacheEmpty() const { return m_lineRecs.empty(); }
69
70 // DM 06 Apr 1999 - append attribute is for derived class use only
71 bool GetAppend() const {
72 return m_bAppend;
73 } // Get append status (true=append, false=overwrite)
74 void SetAppend(bool bAppend) {
75 m_bAppend = bAppend;
76 } // Set append status (true=append, false=overwrite)
77
78private:
80 // Private methods
82
83 BaseFileSink(); // Disable default constructor
84 BaseFileSink(const BaseFileSink &); // Copy constructor disabled by default
86 operator=(const BaseFileSink &); // Copy assignment disabled by default
87
88 void Open(bool bAppend = false);
89 void Close();
90 void ClearCache();
91
92protected:
94 // Protected data
96
97private:
99 // Private data
101 std::vector<std::string> m_lineRecs;
102 std::string m_strFileName;
103 std::ofstream m_fileOut;
104 bool m_bAppend; // If true, Write() appends to file rather than overwriting
105};
106
107void to_json(json &j, const BaseFileSink &baseFileSink);
108void from_json(const json &j, BaseFileSink &baseFileSink);
109
110// Useful typedefs
111typedef SmartPtr<BaseFileSink> BaseFileSinkPtr; // Smart pointer
112
113} // namespace rxdock
114
115#endif //_RBTBASEFILESINK_H_
Definition BaseFileSink.h:31
Definition Error.h:59
Definition SmartPointer.h:48