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 char *fromFile(const std::string &file_name);
37 char *fromString(const std::string &input_string);
38 void free(char *jsonnet_data);
39 };
40 } // namespace impl
41
42
43 template <class t_ParentVisitor>
44 class Reader : public t_ParentVisitor
45 {
46 protected:
48
49
50 public:
51 explicit Reader(const std::string &file_name)
52 {
53 char *jsonnet_output = impl_.fromFile(file_name);
54 t_ParentVisitor::constructFromString(jsonnet_output);
55 impl_.free(jsonnet_output);
56 }
57
58
59 explicit Reader(std::istream &input_stream)
60 {
61 std::string input_string;
62 char buffer[4096];
63 while (input_stream.read(buffer, sizeof(buffer)))
64 {
65 input_string.append(buffer, sizeof(buffer));
66 }
67 input_string.append(buffer, input_stream.gcount());
68
69
70 char *jsonnet_output = impl_.fromString(input_string);
71 t_ParentVisitor::constructFromString(jsonnet_output);
72 impl_.free(jsonnet_output);
73 }
74 };
75 } // namespace ns_jsonnet
76} // namespace ariles2
Reader(std::istream &input_stream)
Definition reader.h:59
Reader(const std::string &file_name)
Definition reader.h:51
JsonnetPreprocessorPtr preprocessor_
Definition reader.h:28
std::shared_ptr< JsonnetPreprocessor > JsonnetPreprocessorPtr
Definition reader.h:25
char * fromString(const std::string &input_string)
Definition reader.cpp:54
char * fromFile(const std::string &file_name)
Definition reader.cpp:45
void free(char *jsonnet_data)
Definition reader.cpp:63