Ariles
Loading...
Searching...
No Matches
reader.h
Go to the documentation of this file.
1/**
2 @file
3 @author Alexander Sherikov
4
5 @copyright 2018-2020 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
6 (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
7
8 @brief
9*/
10
11#pragma once
12
13
14namespace ariles2
15{
16 namespace ns_jsonnet
17 {
18 namespace impl
19 {
21
22 class Reader
23 {
24 protected:
25 using JsonnetPreprocessorPtr = std::shared_ptr<JsonnetPreprocessor>;
26
27 protected:
29
30
31 public:
32 Reader();
33 ~Reader();
34
35
36 const char *fromFile(const std::string &file_name);
37 const char *fromString(const std::string &input_string);
38 };
39 } // namespace impl
40
41
42 template <class t_ParentVisitor>
43 class Reader : public t_ParentVisitor
44 {
45 protected:
47
48
49 public:
50 explicit Reader(const std::string &file_name)
51 {
52 const char *jsonnet_output = impl_.fromFile(file_name);
53 t_ParentVisitor::constructFromString(jsonnet_output);
54 }
55
56
57 explicit Reader(std::istream &input_stream)
58 {
59 std::string input_string;
60 char buffer[4096];
61 while (input_stream.read(buffer, sizeof(buffer)))
62 {
63 input_string.append(buffer, sizeof(buffer));
64 }
65 input_string.append(buffer, input_stream.gcount());
66
67
68 const char *jsonnet_output = impl_.fromString(input_string);
69 t_ParentVisitor::constructFromString(jsonnet_output);
70 }
71 };
72 } // namespace ns_jsonnet
73} // namespace ariles2
Reader(std::istream &input_stream)
Definition reader.h:57
Reader(const std::string &file_name)
Definition reader.h:50
JsonnetPreprocessorPtr preprocessor_
Definition reader.h:28
std::shared_ptr< JsonnetPreprocessor > JsonnetPreprocessorPtr
Definition reader.h:25
const char * fromFile(const std::string &file_name)
Definition reader.cpp:45
const char * fromString(const std::string &input_string)
Definition reader.cpp:54