Skip to content

Commit ab149f4

Browse files
committed
Improve reflection
1 parent 4854abf commit ab149f4

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

include/jinja2cpp/reflected_value.h

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,30 @@ struct Reflector<const T&>
218218
{
219219
return Reflector<T>::CreateFromPtr(&val);
220220
}
221+
static auto Create(const T*& val)
222+
{
223+
return Reflector<T>::CreateFromPtr(val);
224+
}
225+
};
226+
227+
template<typename T>
228+
struct Reflector<const T*&>
229+
{
230+
static auto Create(const T*& val)
231+
{
232+
return Reflector<T>::CreateFromPtr(val);
233+
}
234+
235+
};
236+
237+
template<typename T>
238+
struct Reflector<const T*const&>
239+
{
240+
static auto Create(const T*const& val)
241+
{
242+
return Reflector<T>::CreateFromPtr(val);
243+
}
244+
221245
};
222246

223247
template<typename T>
@@ -245,6 +269,14 @@ struct Reflector<const T*>
245269
{
246270
return Reflector<T>::CreateFromPtr(val);
247271
}
272+
static auto CreateFromPtr(const T* val)
273+
{
274+
return Reflector<T>::CreateFromPtr(val);
275+
}
276+
// static auto CreateFromPtr(const T*const val)
277+
// {
278+
// return Reflector<T>::CreateFromPtr(val);
279+
// }
248280
};
249281

250282
template<typename T>
@@ -279,17 +311,40 @@ struct Reflector<std::string>
279311
};
280312

281313
template<>
282-
struct Reflector<int64_t>
314+
struct Reflector<bool>
283315
{
284-
static auto Create(int64_t val)
316+
static auto Create(bool val)
285317
{
286318
return Value(val);
287319
}
288-
static auto CreateFromPtr(const int64_t* val)
320+
static auto CreateFromPtr(const bool* val)
289321
{
290322
return Value(*val);
291323
}
292324
};
325+
326+
#define JINJA2_INT_REFLECTOR(Type) \
327+
template<> \
328+
struct Reflector<Type> \
329+
{ \
330+
static auto Create(Type val) \
331+
{ \
332+
return Value(static_cast<int64_t>(val)); \
333+
} \
334+
static auto CreateFromPtr(const Type* val) \
335+
{ \
336+
return Value(static_cast<int64_t>(*val)); \
337+
} \
338+
}
339+
340+
JINJA2_INT_REFLECTOR(int8_t);
341+
JINJA2_INT_REFLECTOR(uint8_t);
342+
JINJA2_INT_REFLECTOR(int16_t);
343+
JINJA2_INT_REFLECTOR(uint16_t);
344+
JINJA2_INT_REFLECTOR(int32_t);
345+
JINJA2_INT_REFLECTOR(uint32_t);
346+
JINJA2_INT_REFLECTOR(int64_t);
347+
JINJA2_INT_REFLECTOR(uint64_t);
293348
} // detail
294349

295350
template<typename T>

0 commit comments

Comments
 (0)