-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter.cpp
More file actions
75 lines (62 loc) · 1.32 KB
/
Copy pathWriter.cpp
File metadata and controls
75 lines (62 loc) · 1.32 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
64
65
66
67
68
69
70
71
72
73
74
75
/**
* \file
* \author Lars Bilke
* \date 2012-02-13
* \brief Implementation 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
*
*/
// ** INCLUDES **
#include "Writer.h"
#include <iostream>
#include <fstream>
#include <limits>
namespace FileIO
{
Writer::Writer()
{
_out.precision(std::numeric_limits<double>::digits10);
}
std::string Writer::writeToString()
{
// Empty stream and clear error states.
_out.str("");
_out.clear();
if (this->write())
return _out.str();
else
return std::string("");
}
int Writer::writeToFile(std::string const& filename)
{
std::string file_content = this->writeToString();
if (!file_content.empty())
{
std::ofstream fileStream;
fileStream.open (filename.c_str());
// check file stream
if (!fileStream)
{
std::cerr << "Could not open file " << filename << " !\n";
return 0;
}
fileStream << file_content;
fileStream.close();
return 1;
}
return 0;
}
void Writer::setPrecision(unsigned int precision)
{
_out.precision(precision);
}
void Writer::setFormat(std::ios_base::fmtflags flags)
{
_out.setf(flags);
}
} // namespace FileIO