62 std::swap(*
this, temp);
76 TClass
const*
cl =
nullptr;
89 static constexpr const char* GetStateString[4] = {
105 template <
typename T>
110 return put_impl(
key,
value, s,
int{});
114 template <
typename T>
115 const T*
get(std::string
const&
key)
const
118 return get_impl<T>(
key, s,
int{});
122 template <
typename T>
125 return get_impl<T>(
key,
state,
int{});
130 template <
typename T>
146 return mStore.find(
key) != mStore.end();
156 void print(
bool includetypeinfo =
false)
const;
162 mStore =
other.mStore;
166 std::map<std::string, SerializedInfo> mStore;
169 template <
typename T>
174 auto ptr = std::make_unique<T>(T{
value});
175 auto cl = TClass::GetClass(
typeid(
value));
180 std::unique_ptr<char> bufferptr(
nullptr);
182 buff.WriteObjectAny(
ptr.get(), cl);
183 int N = buff.Length();
184 bufferptr.reset(
new char[N]);
185 memcpy(bufferptr.get(), buff.Buffer(),
sizeof(
char) * N);
187 auto name = std::type_index(
typeid(
value)).name();
188 mStore.insert(std::pair<std::string, SerializedInfo>(
key, SerializedInfo(N, std::move(bufferptr), cl,
name)));
192 template <typename T, typename std::enable_if<std::is_trivial<T>::value,
T>
::type* =
nullptr>
196 static_assert(!std::is_pointer<T>::value);
198 auto ptr = std::make_unique<T>(T{
value});
200 std::unique_ptr<char> bufferptr(
new char[N]);
201 memcpy(bufferptr.get(), (
char*)
ptr.get(),
sizeof(
char) * N);
203 auto name = std::type_index(
typeid(
value)).name();
204 mStore.insert(std::pair<std::string, SerializedInfo>(
key, SerializedInfo(N, std::move(bufferptr),
nullptr,
name)));
208 template <
typename T>
212 auto iter = mStore.find(
key);
213 if (iter != mStore.end()) {
214 auto& info =
const_cast<SerializedInfo&
>(iter->second);
215 auto cl = TClass::GetClass(
typeid(T));
220 if (info.cl && strcmp(cl->GetName(), info.cl->GetName()) == 0) {
223 return (T*)info.objptr;
226 TBufferFile buff(TBuffer::kRead, info.N, info.bufferptr,
false,
nullptr);
228 auto instance = (
T*)buff.ReadObjectAny(cl);
229 info.objptr = instance;
230 return (T*)info.objptr;
241 template <typename T, typename std::enable_if<std::is_trivial<T>::value,
T>
::type* =
nullptr>
245 auto iter = mStore.find(
key);
246 if (iter != mStore.end()) {
247 auto& info =
const_cast<SerializedInfo&
>(iter->second);
248 if (strcmp(std::type_index(
typeid(T)).
name(), info.typeinfo_name.c_str()) == 0) {
251 return (T*)info.objptr;
253 info.objptr = (
T*)info.bufferptr;
254 return (T*)info.objptr;
265 void remove_entry(std::string
const&
key)
267 auto iter = mStore.find(
key);
268 if (iter != mStore.end()) {