Skip to content

Commit 6092f44

Browse files
authored
Bump deps: Switch to polymorphic value and latest robin_hood_hash(#220)
* bump robin_hood hashing dep to 3.11.3 * bump value-ptr-lite to latest version * switch to polymorphic_value * implement comparisons * fix build: add operator!= * polymorphic_value into jinja2cpp integration * introduce ValuePtr and MoveValuePtr aliases
1 parent 4b86a7c commit 6092f44

38 files changed

+3505
-2114
lines changed

.github/workflows/windows-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
mkdir -p .build
7676
cd .build
7777
cmake .. -G "%INPUT_GENERATOR%" -DCMAKE_BUILD_TYPE=%INPUT_BUILD_CONFIG% -DJINJA2CPP_MSVC_RUNTIME_TYPE="%INPUT_BUILD_RUNTIME%" -DJINJA2CPP_DEPS_MODE=internal -DJINJA2CPP_BUILD_SHARED=%INPUT_BUILD_SHARED% %INPUT_BASE_FLAGS% %INPUT_EXTRA_FLAGS%
78-
cmake --build . --config %INPUT_BUILD_CONFIG%
78+
cmake --build . --config %INPUT_BUILD_CONFIG% --verbose
7979
8080
- name: Test
8181
shell: cmd

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
build/
3434
dist/
3535

36+
compile_commands.json

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ if (UNIX)
9090
endif ()
9191
else ()
9292
set(GCC_CXX_FLAGS ${GCC_CXX_FLAGS} "-Wa,-mbig-obj" -O1)
93-
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
93+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
9494
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
9595
endif ()
9696
add_definitions(-DBOOST_ALL_NO_LIB)
@@ -193,11 +193,11 @@ if (JINJA2CPP_STRICT_WARNINGS)
193193
endif ()
194194
endif ()
195195

196-
if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
196+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
197197
target_compile_options(${LIB_TARGET_NAME} PRIVATE ${GCC_CXX_FLAGS})
198-
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
198+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
199199
target_compile_options(${LIB_TARGET_NAME} PRIVATE ${CLANG_CXX_FLAGS})
200-
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "MSVC")
200+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
201201
target_compile_options(${LIB_TARGET_NAME} PRIVATE ${MSVC_CXX_FLAGS})
202202
endif ()
203203

@@ -233,7 +233,7 @@ if (JINJA2CPP_BUILD_TESTS)
233233
CXX_STANDARD ${JINJA2CPP_CXX_STANDARD}
234234
CXX_STANDARD_REQUIRED ON)
235235

236-
if (MSVC)
236+
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
237237
target_compile_options(jinja2cpp_tests PRIVATE /bigobj)
238238
endif ()
239239

include/jinja2cpp/binding/nlohmann_json.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace jinja2
1010
namespace detail
1111
{
1212

13-
class NLohmannJsonObjectAccessor : public MapItemAccessor, public ReflectedDataHolder<nlohmann::json>
13+
class NLohmannJsonObjectAccessor : public IMapItemAccessor, public ReflectedDataHolder<nlohmann::json>
1414
{
1515
public:
1616
using ReflectedDataHolder<nlohmann::json>::ReflectedDataHolder;
@@ -50,10 +50,18 @@ class NLohmannJsonObjectAccessor : public MapItemAccessor, public ReflectedDataH
5050
}
5151
return result;
5252
}
53+
54+
bool IsEqual(const IComparable& other) const override
55+
{
56+
auto* val = dynamic_cast<const NLohmannJsonObjectAccessor*>(&other);
57+
if (!val)
58+
return false;
59+
return GetValue() == val->GetValue();
60+
}
5361
};
5462

5563

56-
struct NLohmannJsonArrayAccessor : ListItemAccessor, IndexBasedAccessor, ReflectedDataHolder<nlohmann::json>
64+
struct NLohmannJsonArrayAccessor : IListItemAccessor, IIndexBasedAccessor, ReflectedDataHolder<nlohmann::json>
5765
{
5866
using ReflectedDataHolder<nlohmann::json>::ReflectedDataHolder;
5967

@@ -62,7 +70,8 @@ struct NLohmannJsonArrayAccessor : ListItemAccessor, IndexBasedAccessor, Reflect
6270
auto j = this->GetValue();
6371
return j ? j->size() : nonstd::optional<size_t>();
6472
}
65-
const IndexBasedAccessor* GetIndexer() const override
73+
74+
const IIndexBasedAccessor* GetIndexer() const override
6675
{
6776
return this;
6877
}
@@ -72,9 +81,9 @@ struct NLohmannJsonArrayAccessor : ListItemAccessor, IndexBasedAccessor, Reflect
7281
using Enum = Enumerator<typename nlohmann::json::const_iterator>;
7382
auto j = this->GetValue();
7483
if (!j)
75-
jinja2::ListEnumeratorPtr(nullptr, Enum::Deleter);
84+
return jinja2::ListEnumeratorPtr();
7685

77-
return jinja2::ListEnumeratorPtr(new Enum(j->begin(), j->end()), Enum::Deleter);
86+
return jinja2::ListEnumeratorPtr(new Enum(j->begin(), j->end()));
7887
}
7988

8089
Value GetItemByIndex(int64_t idx) const override
@@ -85,6 +94,14 @@ struct NLohmannJsonArrayAccessor : ListItemAccessor, IndexBasedAccessor, Reflect
8594

8695
return Reflect((*j)[idx]);
8796
}
97+
98+
bool IsEqual(const IComparable& other) const override
99+
{
100+
auto* val = dynamic_cast<const NLohmannJsonArrayAccessor*>(&other);
101+
if (!val)
102+
return false;
103+
return GetValue() == val->GetValue();
104+
}
88105
};
89106

90107
template<>

include/jinja2cpp/binding/rapid_json.h

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <jinja2cpp/reflected_value.h>
55
#include <jinja2cpp/string_helpers.h>
6+
67
#include <rapidjson/document.h>
78
#include <rapidjson/rapidjson.h>
89

@@ -27,11 +28,12 @@ struct RapidJsonNameConverter<wchar_t>
2728
};
2829

2930
template<typename T>
30-
class RapidJsonObjectAccessor : public MapItemAccessor, public ReflectedDataHolder<T, false>
31+
class RapidJsonObjectAccessor : public IMapItemAccessor, public ReflectedDataHolder<T, false>
3132
{
3233
public:
3334
using ReflectedDataHolder<T, false>::ReflectedDataHolder;
3435
using NameCvt = RapidJsonNameConverter<typename T::Ch>;
36+
using ThisType = RapidJsonObjectAccessor<T>;
3537
~RapidJsonObjectAccessor() override = default;
3638

3739
size_t GetSize() const override
@@ -69,22 +71,38 @@ class RapidJsonObjectAccessor : public MapItemAccessor, public ReflectedDataHold
6971
}
7072
return result;
7173
}
74+
75+
bool IsEqual(const IComparable& other) const override
76+
{
77+
auto* val = dynamic_cast<const ThisType*>(&other);
78+
if (!val)
79+
return false;
80+
auto enumerator = this->GetValue();
81+
auto otherEnum = val->GetValue();
82+
if (enumerator && otherEnum && enumerator != otherEnum)
83+
return false;
84+
if ((enumerator && !otherEnum) || (!enumerator && otherEnum))
85+
return false;
86+
return true;
87+
}
7288
};
7389

7490
template<typename Enc>
7591
struct RapidJsonArrayAccessor
76-
: ListItemAccessor
77-
, IndexBasedAccessor
92+
: IListItemAccessor
93+
, IIndexBasedAccessor
7894
, ReflectedDataHolder<rapidjson::GenericValue<Enc>, false>
7995
{
8096
using ReflectedDataHolder<rapidjson::GenericValue<Enc>, false>::ReflectedDataHolder;
97+
using ThisType = RapidJsonArrayAccessor<Enc>;
8198

8299
nonstd::optional<size_t> GetSize() const override
83100
{
84101
auto j = this->GetValue();
85102
return j ? j->Size() : nonstd::optional<size_t>();
86103
}
87-
const IndexBasedAccessor* GetIndexer() const override
104+
105+
const IIndexBasedAccessor* GetIndexer() const override
88106
{
89107
return this;
90108
}
@@ -94,9 +112,9 @@ struct RapidJsonArrayAccessor
94112
using Enum = Enumerator<typename rapidjson::GenericValue<Enc>::ConstValueIterator>;
95113
auto j = this->GetValue();
96114
if (!j)
97-
jinja2::ListEnumeratorPtr(nullptr, Enum::Deleter);
115+
return jinja2::ListEnumeratorPtr();
98116

99-
return jinja2::ListEnumeratorPtr(new Enum(j->Begin(), j->End()), Enum::Deleter);
117+
return jinja2::ListEnumeratorPtr(new Enum(j->Begin(), j->End()));
100118
}
101119

102120
Value GetItemByIndex(int64_t idx) const override
@@ -107,6 +125,20 @@ struct RapidJsonArrayAccessor
107125

108126
return Reflect((*j)[static_cast<rapidjson::SizeType>(idx)]);
109127
}
128+
129+
bool IsEqual(const IComparable& other) const override
130+
{
131+
auto* val = dynamic_cast<const ThisType*>(&other);
132+
if (!val)
133+
return false;
134+
auto enumerator = this->GetValue();
135+
auto otherEnum = val->GetValue();
136+
if (enumerator && otherEnum && enumerator != otherEnum)
137+
return false;
138+
if ((enumerator && !otherEnum) || (!enumerator && otherEnum))
139+
return false;
140+
return true;
141+
}
110142
};
111143

112144
template<typename Enc>

include/jinja2cpp/filesystem_handler.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "config.h"
55

6+
#include <jinja2cpp/utils/i_comparable.h>
7+
68
#include <nonstd/optional.hpp>
79
#include <nonstd/variant.hpp>
810

@@ -28,7 +30,7 @@ using WCharFileStreamPtr = FileStreamPtr<wchar_t>;
2830
* So, the exact type (ex. `ifstream`, `istringstream` etc.) of input stream is unspecified. In order to delete stream object correctly returned pointer
2931
* provide the custom deleter which should properly delete the stream object.
3032
*/
31-
class JINJA2CPP_EXPORT IFilesystemHandler
33+
class JINJA2CPP_EXPORT IFilesystemHandler : public IComparable
3234
{
3335
public:
3436
//! Destructor
@@ -101,11 +103,27 @@ class JINJA2CPP_EXPORT MemoryFileSystem : public IFilesystemHandler
101103
WCharFileStreamPtr OpenWStream(const std::string& name) const override;
102104
nonstd::optional<std::chrono::system_clock::time_point> GetLastModificationDate(const std::string& name) const override;
103105

106+
/*!
107+
* \brief Compares to an object of the same type
108+
*
109+
* return true if equal
110+
*/
111+
bool IsEqual(const IComparable& other) const override;
104112
private:
105113
struct FileContent
106114
{
107115
nonstd::optional<std::string> narrowContent;
108116
nonstd::optional<std::wstring> wideContent;
117+
bool operator==(const FileContent& other) const
118+
{
119+
if (narrowContent != other.narrowContent)
120+
return false;
121+
return wideContent == other.wideContent;
122+
}
123+
bool operator!=(const FileContent& other) const
124+
{
125+
return !(*this == other);
126+
}
109127
};
110128
mutable std::unordered_map<std::string, FileContent> m_filesMap;
111129
};
@@ -168,6 +186,13 @@ class JINJA2CPP_EXPORT RealFileSystem : public IFilesystemHandler
168186
CharFileStreamPtr OpenByteStream(const std::string& name) const;
169187
nonstd::optional<std::chrono::system_clock::time_point> GetLastModificationDate(const std::string& name) const override;
170188

189+
/*!
190+
* \brief Compares to an object of the same type
191+
*
192+
* return true if equal
193+
*/
194+
bool IsEqual(const IComparable& other) const override;
195+
171196
private:
172197
std::string m_rootFolder;
173198
};

0 commit comments

Comments
 (0)