Ariles
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 
14 namespace ariles
15 {
16  namespace ns_jsonnet
17  {
18  namespace impl
19  {
21 
23  {
24  protected:
25  typedef ARILES_SHARED_PTR<JsonnetPreprocessor> JsonnetPreprocessorPtr;
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>
44  {
45  protected:
47 
48 
49  public:
50  explicit Reader(const std::string &file_name) : t_ParentVisitor()
51  {
52  const char *jsonnet_output = impl_.fromFile(file_name);
53  t_ParentVisitor::constructFromString(jsonnet_output);
54  }
55 
56  template <class t_Flags>
57  explicit Reader(const std::string &file_name, const t_Flags &flags) : t_ParentVisitor(flags)
58  {
59  const char *jsonnet_output = impl_.fromFile(file_name);
60  t_ParentVisitor::constructFromString(jsonnet_output);
61  }
62 
63 
64  explicit Reader(std::istream &input_stream) : t_ParentVisitor()
65  {
66  std::string input_string;
67  char buffer[4096];
68  while (input_stream.read(buffer, sizeof(buffer)))
69  {
70  input_string.append(buffer, sizeof(buffer));
71  }
72  input_string.append(buffer, input_stream.gcount());
73 
74 
75  const char *jsonnet_output = impl_.fromString(input_string);
76  t_ParentVisitor::constructFromString(jsonnet_output);
77  }
78 
79  template <class t_Flags>
80  explicit Reader(std::istream &input_stream, const t_Flags &flags) : t_ParentVisitor(flags)
81  {
82  std::string input_string;
83  char buffer[4096];
84  while (input_stream.read(buffer, sizeof(buffer)))
85  {
86  input_string.append(buffer, sizeof(buffer));
87  }
88  input_string.append(buffer, input_stream.gcount());
89 
90 
91  const char *jsonnet_output = impl_.fromString(input_string);
92  t_ParentVisitor::constructFromString(jsonnet_output);
93  }
94  };
95  } // namespace ns_jsonnet
96 } // namespace ariles
impl::Reader impl_
Definition: reader.h:46
const char * fromFile(const std::string &file_name)
Definition: reader.cpp:45
Reader(const std::string &file_name)
Definition: reader.h:50
const char * fromString(const std::string &input_string)
Definition: reader.cpp:54
JsonnetPreprocessorPtr preprocessor_
Definition: reader.h:28
ARILES_SHARED_PTR< JsonnetPreprocessor > JsonnetPreprocessorPtr
Definition: reader.h:25
Reader(std::istream &input_stream)
Definition: reader.h:64
class ARILES_VISIBILITY_ATTRIBUTE Reader
Definition: reader.h:23
Reader(const std::string &file_name, const t_Flags &flags)
Definition: reader.h:57
#define ARILES_VISIBILITY_ATTRIBUTE
Definition: helpers.h:69
Reader(std::istream &input_stream, const t_Flags &flags)
Definition: reader.h:80
Definition: basic.h:17