-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter.h
More file actions
63 lines (49 loc) · 1.46 KB
/
Copy pathWriter.h
File metadata and controls
63 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* \file
* \author Lars Bilke
* \date 2012-02-13
* \brief Definition of the Writer class.
*
* \copyright
* Copyright (c) 2012-2015, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef WRITER_H
#define WRITER_H
#include <string>
#include <sstream>
namespace FileIO
{
/// @brief Base class which enables writing an object to string, stringstream
/// or file. Also formatting (precision, scientific notation of decimal values)
/// can be set.
///
/// When subclassing you only need to implement void write() in which you have
/// to write to _out.
class Writer
{
public:
Writer();
virtual ~Writer() {}
/// @brief Writes the object to a string.
std::string writeToString();
/// @brief Writes the object to the given file.
int writeToFile(std::string const& filename);
/// @brief Sets the decimal precision.
void setPrecision(unsigned int precision);
/// @brief Sets the format (either ios::scientific or ios::fixed);
void setFormat(std::ios_base::fmtflags flags);
protected:
/// @brief Writes the object to the internal stream.
/// This method must be implemented by a subclass.
/// The implementation should return true on success, else false
virtual bool write() = 0;
/// @brief The stream to write to.
std::stringstream _out;
private:
};
} // namespace FileIO
#endif // WRITER_H