Ariles
reader.cpp
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 
12 
13 extern "C"
14 {
15 #include "libjsonnet.h"
16 }
17 
18 namespace ariles2
19 {
20  namespace ns_jsonnet
21  {
22  namespace impl
23  {
25  {
26  public:
27  JsonnetVm *vm_;
28  };
29 
30 
32  {
33  preprocessor_ = std::make_shared<JsonnetPreprocessor>();
34  preprocessor_->vm_ = ::jsonnet_make();
35  CPPUT_ASSERT(nullptr != preprocessor_->vm_, "Could not initialize jsonnet preprocessor.");
36  }
37 
38 
40  {
41  ::jsonnet_destroy(preprocessor_->vm_);
42  }
43 
44 
45  const char *Reader::fromFile(const std::string &file_name)
46  {
47  int error = 0;
48  const char *jsonnet_output = ::jsonnet_evaluate_file(preprocessor_->vm_, file_name.c_str(), &error);
49  CPPUT_ASSERT(0 == error, jsonnet_output);
50  return (jsonnet_output);
51  }
52 
53 
54  const char *Reader::fromString(const std::string &input_string)
55  {
56  int error = 0;
57  const char *jsonnet_output =
58  ::jsonnet_evaluate_snippet(preprocessor_->vm_, "<input steam>", input_string.c_str(), &error);
59  CPPUT_ASSERT(0 == error, jsonnet_output);
60  return (jsonnet_output);
61  }
62  } // namespace impl
63  } // namespace ns_jsonnet
64 } // namespace ariles2
JsonnetPreprocessorPtr preprocessor_
Definition: reader.h:28
const char * fromFile(const std::string &file_name)
Definition: reader.cpp:45
const char * fromString(const std::string &input_string)
Definition: reader.cpp:54
#define CPPUT_ASSERT(condition,...)
Definition: exception.h:32
Definition: basic.h:17