77#include < unordered_map>
88#include < string>
99#include < functional>
10- #include < boost/variant.hpp>
10+ #include < nonstd/variant.hpp>
11+ #include < nonstd/value_ptr.hpp>
1112
1213namespace jinja2
1314{
@@ -34,6 +35,7 @@ class GenericMap
3435{
3536public:
3637 GenericMap () = default ;
38+
3739 GenericMap (std::function<const MapItemAccessor* ()> accessor)
3840 : m_accessor(std::move(accessor))
3941 {
@@ -89,13 +91,20 @@ class GenericList
8991
9092using ValuesList = std::vector<Value>;
9193using ValuesMap = std::unordered_map<std::string, Value>;
92- using ValueData = boost::variant<EmptyValue, bool , std::string, std::wstring, int64_t , double , boost::recursive_wrapper<ValuesList>, boost::recursive_wrapper<ValuesMap>, GenericList, GenericMap>;
94+ struct FunctionCallParams ;
95+
96+ using UserFunction = std::function<Value (const FunctionCallParams&)>;
97+
98+ template <typename T>
99+ using RecWrapper = nonstd::value_ptr<T>;
93100
94101class Value {
95102public:
103+ using ValueData = nonstd::variant<EmptyValue, bool , std::string, std::wstring, int64_t , double , RecWrapper<ValuesList>, RecWrapper<ValuesMap>, GenericList, GenericMap, UserFunction>;
104+
96105 Value () = default ;
97106 template <typename T>
98- Value (T&& val, typename std::enable_if<!std::is_same<std::decay_t <T>, Value>::value>::type* = nullptr )
107+ Value (T&& val, typename std::enable_if<!std::is_same<std::decay_t <T>, Value>::value && !std::is_same<std:: decay_t <T>, ValuesList>::value >::type* = nullptr )
99108 : m_data(std::forward<T>(val))
100109 {
101110 }
@@ -112,51 +121,67 @@ class Value {
112121 : m_data(static_cast <int64_t >(val))
113122 {
114123 }
124+ Value (const ValuesList& list)
125+ : m_data(RecWrapper<ValuesList>(list))
126+ {
127+ }
128+ Value (const ValuesMap& map)
129+ : m_data(RecWrapper<ValuesMap>(map))
130+ {
131+ }
132+ Value (ValuesList&& list) noexcept
133+ : m_data(RecWrapper<ValuesList>(std::move(list)))
134+ {
135+ }
136+ Value (ValuesMap&& map) noexcept
137+ : m_data(RecWrapper<ValuesMap>(std::move(map)))
138+ {
139+ }
115140
116141 const ValueData& data () const {return m_data;}
117142
118143 ValueData& data () {return m_data;}
119144
120145 bool isString () const
121146 {
122- return boost::get <std::string>(&m_data) != nullptr ;
147+ return nonstd::get_if <std::string>(&m_data) != nullptr ;
123148 }
124149 auto & asString ()
125150 {
126- return boost ::get<std::string>(m_data);
151+ return nonstd ::get<std::string>(m_data);
127152 }
128153 auto & asString () const
129154 {
130- return boost ::get<std::string>(m_data);
155+ return nonstd ::get<std::string>(m_data);
131156 }
132157
133158 bool isList () const
134159 {
135- return boost::get< ValuesList>(&m_data) != nullptr || boost::get <GenericList>(&m_data) != nullptr ;
160+ return nonstd::get_if<RecWrapper< ValuesList>> (&m_data) != nullptr || nonstd::get_if <GenericList>(&m_data) != nullptr ;
136161 }
137162 auto & asList ()
138163 {
139- return boost ::get<ValuesList>(m_data);
164+ return *nonstd ::get<RecWrapper< ValuesList>> (m_data). get ( );
140165 }
141166 auto & asList () const
142167 {
143- return boost ::get<ValuesList>(m_data);
168+ return *nonstd ::get<RecWrapper< ValuesList>> (m_data). get ( );
144169 }
145170 bool isMap () const
146171 {
147- return boost::get< ValuesMap>(&m_data) != nullptr || boost::get <GenericMap>(&m_data) != nullptr ;
172+ return nonstd::get_if<RecWrapper< ValuesMap>> (&m_data) != nullptr || nonstd::get_if <GenericMap>(&m_data) != nullptr ;
148173 }
149174 auto & asMap ()
150175 {
151- return boost ::get<ValuesMap>(m_data);
176+ return *nonstd ::get<RecWrapper< ValuesMap>> (m_data). get ( );
152177 }
153178 auto & asMap () const
154179 {
155- return boost ::get<ValuesMap>(m_data);
180+ return *nonstd ::get<RecWrapper< ValuesMap>> (m_data). get ( );
156181 }
157182 bool isEmpty () const
158183 {
159- return boost::get <EmptyValue>(&m_data) != nullptr ;
184+ return nonstd::get_if <EmptyValue>(&m_data) != nullptr ;
160185 }
161186
162187 Value subscript (const Value& index) const ;
@@ -165,6 +190,12 @@ class Value {
165190 ValueData m_data;
166191};
167192
193+ struct FunctionCallParams
194+ {
195+ ValuesMap kwParams;
196+ ValuesList posParams;
197+ };
198+
168199inline Value GenericMap::GetValueByName (const std::string& name) const
169200{
170201 return m_accessor ()->GetValueByName (name);
0 commit comments