Ariles
Loading...
Searching...
No Matches
extra_visitors
jsonnet
src
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
11
#include <
ariles2/visitors/jsonnet.h
>
12
13
extern
"C"
14
{
15
#include "libjsonnet.h"
16
}
17
18
namespace
ariles2
19
{
20
namespace
ns_jsonnet
21
{
22
namespace
impl
23
{
24
class
JsonnetPreprocessor
25
{
26
public
:
27
JsonnetVm *
vm_
;
28
};
29
30
31
Reader::Reader
()
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
39
Reader::~Reader
()
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
ariles2::ns_jsonnet::impl::JsonnetPreprocessor
Definition
reader.cpp:25
ariles2::ns_jsonnet::impl::JsonnetPreprocessor::vm_
JsonnetVm * vm_
Definition
reader.cpp:27
ariles2::ns_jsonnet::impl::Reader::preprocessor_
JsonnetPreprocessorPtr preprocessor_
Definition
reader.h:28
ariles2::ns_jsonnet::impl::Reader::fromFile
const char * fromFile(const std::string &file_name)
Definition
reader.cpp:45
ariles2::ns_jsonnet::impl::Reader::~Reader
~Reader()
Definition
reader.cpp:39
ariles2::ns_jsonnet::impl::Reader::fromString
const char * fromString(const std::string &input_string)
Definition
reader.cpp:54
ariles2::ns_jsonnet::impl::Reader::Reader
Reader()
Definition
reader.cpp:31
CPPUT_ASSERT
#define CPPUT_ASSERT(condition,...)
Definition
exception.h:32
jsonnet.h
ariles2
Definition
basic.h:17
Generated by
1.9.8