blob: 1cc0d975919cd9999afc3eb3a75f5a41d337abd8 (
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
33
34
35
36
37
38
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "istreamconfigreader.h"
#include <sstream>
namespace config {
template <typename ConfigType>
IstreamConfigReader<ConfigType>::IstreamConfigReader(std::istream & is)
: _is(is)
{
}
template <typename ConfigType>
std::unique_ptr<ConfigType>
IstreamConfigReader<ConfigType>::read(const ConfigFormatter & formatter)
{
ConfigDataBuffer buffer;
std::stringstream buf;
buf << _is.rdbuf();
buffer.setEncodedString(buf.str());
formatter.decode(buffer);
return std::make_unique<ConfigType>(buffer);
}
template <typename ConfigType>
std::unique_ptr<ConfigType>
IstreamConfigReader<ConfigType>::read()
{
StringVector lines;
std::string line;
while (getline(_is, line)) {
lines.push_back(line);
}
return std::make_unique<ConfigType>(ConfigValue(std::move(lines)));
}
} // namespace config
|