blob: b23e96f149d60d9406c9a6acc6109ac990c439b8 (
plain) (
blame)
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <fstream>
#include "fileconfigwriter.h"
#include "fileconfigformatter.h"
#include "ostreamconfigwriter.h"
#include <vespa/config/common/exceptions.h>
namespace config {
FileConfigWriter::FileConfigWriter(const vespalib::string & fileName)
: _fileName(fileName)
{
}
bool
FileConfigWriter::write(const ConfigInstance & config)
{
return write(config, FileConfigFormatter());
}
bool
FileConfigWriter::write(const ConfigInstance & config, const ConfigFormatter & formatter)
{
std::ofstream file(_fileName.c_str());
if (!file.is_open())
throw ConfigWriteException("error: could not open output file: '%s'\n", _fileName.c_str());
OstreamConfigWriter osw(file);
return osw.write(config, formatter);
}
} // namespace config
|