Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,46 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_ASSERT_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_ASSERT_H
#pragma once
#ifdef SERIALIZATION_STANDALONE
#include <assert.h>
#else
#include <platform.h>
#endif
#ifdef YASLI_ASSERT
# undef YASLI_ASSERT
#endif
#ifdef YASLI_VERIFY
# undef YASLI_VERIFY
#endif
#ifdef YASLI_ESCAPE
# undef YASLI_ESCAPE
#endif
#ifdef SERIALIZATION_STANDALONE
#define YASLI_ASSERT(x) assert(x)
#define YASLI_ASSERT_STR(x, str) assert(x && str)
#define YASLI_ESCAPE(x, action) if (!(x)) { YASLI_ASSERT(0 && #x); action; };
#else
#define YASLI_ASSERT(x) CRY_ASSERT(x)
#define YASLI_ASSERT_STR(x, str) CRY_ASSERT_MESSAGE(x, str)
#define YASLI_ESCAPE(x, action) if (!(x)) { YASLI_ASSERT(0 && #x); action; };
#endif // SERIALIZATION_STANDALONE
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_ASSERT_H
@@ -0,0 +1,39 @@
// Copyright (c) 2012 Crytek GmbH
// Authors: Evgeny Andreeshchev, Alexander Kotliar
// Based on: Yasli - the serialization library.
// Modifications copyright Amazon.com, Inc. or its affiliates
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_BITVECTOR_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_BITVECTOR_H
#pragma once
namespace Serialization{
class IArchive;
template<class Enum>
class BitVector
{
public:
BitVector(int value = 0) : value_(value) {}
operator int&() { return value_; }
operator int() const { return value_; }
BitVector& operator|= (Enum value) { value_ |= value; return *this; }
BitVector& operator|= (int value) { value_ |= value; return *this; }
BitVector& operator&= (int value) { value_ &= value; return *this; }
void Serialize(IArchive& ar);
private:
int value_;
};
template<class Enum>
bool Serialize(Serialization::IArchive& ar, Serialization::BitVector<Enum>& value, const char* name, const char* label);
}
#include "BitVectorImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_BITVECTOR_H
@@ -0,0 +1,88 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_BITVECTORIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_BITVECTORIMPL_H
#pragma once
#include "Serialization/BitVector.h"
#include "Serialization/IArchive.h"
#include "Serialization/Enum.h"
namespace Serialization {
struct BitVectorWrapper
{
int* valuePointer;
int value;
const CEnumDescription* description;
explicit BitVectorWrapper(int* _value = 0, const CEnumDescription* _description = 0)
: valuePointer(_value)
, description(_description)
{
if (valuePointer)
{
value = *valuePointer;
}
}
BitVectorWrapper(const BitVectorWrapper& _rhs)
: value(_rhs.value)
, description(0)
, valuePointer(0)
{
}
~BitVectorWrapper()
{
if (valuePointer)
{
* valuePointer = value;
}
}
BitVectorWrapper& operator=(const BitVectorWrapper& rhs)
{
value = rhs.value;
return *this;
}
void Serialize(IArchive& ar)
{
ar(value, "value", "Value");
}
};
template<class Enum>
void BitVector<Enum>::Serialize(IArchive& ar)
{
ar(value_, "value", "Value");
}
}
template<class Enum>
bool Serialize(Serialization::IArchive& ar, Serialization::BitVector<Enum>& value, const char* name, const char* label)
{
using namespace Serialization;
CEnumDescription& desc = getEnumDescription<Enum>();
if (ar.IsEdit())
{
return ar(BitVectorWrapper(&static_cast<int&>(value), &desc), name, label);
}
else
{
return desc.serializeBitVector(ar, static_cast<int&>(value), name, label);
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_BITVECTORIMPL_H
@@ -0,0 +1,93 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_BLACKBOX_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_BLACKBOX_H
#pragma once
#include <stdlib.h> // for malloc and free
namespace Serialization
{
// Black box is used to store opaque data blobs in a format internal to
// specific Archive. For example it can be used to store sections of the JSON
// or binary archive.
//
// This is useful for the Editor to store portions of files with unfamiliar
// structure.
//
// We store deallocation function here so we can safely pass the blob
// across DLLs with different memory allocators.
struct SBlackBox
{
const char* format;
void* data;
size_t size;
typedef void(* FreeFunction)(void*);
FreeFunction freeFunction;
SBlackBox()
: format("")
, data(0)
, size(0)
, freeFunction(0)
{
}
SBlackBox(const SBlackBox& rhs)
: format("")
, data(0)
, size(0)
, freeFunction(0)
{
*this = rhs;
}
void set(const char* _format, const void* _data, size_t _size)
{
if (_data && freeFunction)
{
freeFunction(this->data);
this->data = 0;
this->size = 0;
freeFunction = 0;
}
this->format = _format;
if (_data && _size)
{
this->data = CryModuleMalloc(_size);
memcpy(this->data, _data, _size);
this->size = _size;
freeFunction = &Free;
}
}
SBlackBox& operator=(const SBlackBox& rhs)
{
set(rhs.format, rhs.data, rhs.size);
return *this;
}
~SBlackBox()
{
set("", 0, 0);
}
static void Free(void* ptr)
{
CryModuleFree(ptr);
}
};
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_BLACKBOX_H
@@ -0,0 +1,102 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#pragma once
#include <Serialization/Serializer.h>
#include "ClassFactory.h"
template <class T>
class BoostSharedPtrSerializer
: public Serialization::IPointer
{
public:
BoostSharedPtrSerializer(AZStd::shared_ptr<T>& ptr)
: m_ptr(ptr)
{
}
const char* registeredTypeName() const override
{
if (m_ptr)
{
return factoryOverride().getRegisteredTypeName(m_ptr.get());
}
else
{
return "";
}
}
void create(const char* registeredTypeName) const override
{
CRY_ASSERT(!m_ptr || m_ptr.use_count() == 1);
if (registeredTypeName && registeredTypeName[0] != '\0')
{
m_ptr.reset(factoryOverride().create(registeredTypeName));
}
else
{
m_ptr.reset();
}
}
Serialization::TypeID baseType() const override
{
return Serialization::TypeID::get<T>();
}
virtual Serialization::SStruct serializer() const override
{
return Serialization::SStruct(*m_ptr);
}
void* get() const
{
return reinterpret_cast<void*>(m_ptr.get());
}
const void* handle() const
{
return &m_ptr;
}
Serialization::TypeID pointerType() const override
{
return Serialization::TypeID::get<AZStd::shared_ptr<T> >();
}
Serialization::ClassFactory<T>* factory() const override
{
return &factoryOverride();
}
virtual Serialization::ClassFactory<T>& factoryOverride() const
{
return Serialization::ClassFactory<T>::the();
}
protected:
AZStd::shared_ptr<T>& m_ptr;
};
namespace AZStd
{
template <class T>
bool Serialize(Serialization::IArchive& ar, AZStd::shared_ptr<T>& ptr, const char* name, const char* label)
{
BoostSharedPtrSerializer<T> serializer(ptr);
return ar(static_cast<Serialization::IPointer&>(serializer), name, label);
}
}
@@ -0,0 +1,30 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRCREF_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRCREF_H
#pragma once
template <uint32 StoreStrings, typename THash>
struct SCRCRef;
namespace Serialization
{
class IArchive;
}
template <uint32 StoreStrings, typename THash>
bool Serialize(Serialization::IArchive& ar, SCRCRef<StoreStrings, THash>& crcRef, const char* name, const char* label);
#include "CRCRefImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRCREF_H
@@ -0,0 +1,100 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRCREFIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRCREFIMPL_H
#pragma once
#include "IArchive.h"
#include "Serializer.h"
template <typename TCRCRef>
class CRCRefSerializer
: public Serialization::IString
{
public:
CRCRefSerializer(TCRCRef& crcRef)
: m_crcRef(crcRef)
{
}
virtual void set(const char* value)
{
m_crcRef.SetByString(value);
}
virtual const char* get() const
{
return m_crcRef.c_str();
}
const void* handle() const
{
return &m_crcRef;
}
Serialization::TypeID type() const
{
return Serialization::TypeID::get<TCRCRef>();
}
TCRCRef& m_crcRef;
};
template <uint32 StoreStrings, typename THash>
class CCRCRefSerializerNoStrings
{
public:
CCRCRefSerializerNoStrings(struct SCRCRef<StoreStrings, THash>& crcRef)
: crc(crcRef.crc)
{
}
bool Serialize(Serialization::IArchive& ar)
{
return ar(crc, "CRC", "CRC");
}
typedef typename THash::TInt TInt;
TInt& crc;
};
template <uint32 StoreStrings, typename THash>
bool Serialize(Serialization::IArchive& ar, struct SCRCRef<StoreStrings, THash>& crcRef, const char* name, const char* label)
{
if (StoreStrings == 0)
{
if (ar.IsInput())
{
SCRCRef<StoreStrings, THash> crcCopy;
ar(CCRCRefSerializerNoStrings<StoreStrings, THash>(crcCopy), name, label);
if (crcCopy.crc != THash::INVALID)
{
crcRef = crcCopy;
return true;
}
}
else if (ar.IsOutput())
{
return ar(CCRCRefSerializerNoStrings<StoreStrings, THash>(crcRef), name, label);
}
}
CRCRefSerializer<SCRCRef<StoreStrings, THash> > crcRefSerializer(crcRef);
return ar(static_cast<Serialization::IString&>(crcRefSerializer), name, label);
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRCREFIMPL_H
@@ -0,0 +1,184 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CALLBACK_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CALLBACK_H
#pragma once
#include <AzCore/std/functional.h>
namespace Serialization
{
struct ICallback
{
virtual bool SerializeValue(IArchive& ar, const char* name, const char* value) = 0;
virtual ICallback* Clone() = 0;
virtual void Release() = 0;
virtual TypeID Type() const = 0;
typedef AZStd::function<void(void*, const TypeID&)> ApplyFunction;
virtual void Call(const ApplyFunction&) = 0;
};
template<class T, class Decorator = T>
struct CallbackSimple
: ICallback
{
typedef AZStd::function<void(const T&)> CallbackFunction;
T* value;
T oldValue;
CallbackFunction callback;
CallbackSimple(T* value, const T& oldValue, const AZStd::function<void(const T&)>& callback)
: value(value)
, oldValue(oldValue)
, callback(callback)
{
}
ICallback* Clone() { return new CallbackSimple<T>(0, oldValue, callback); }
void Release() { delete this; }
bool SerializeValue(IArchive& ar, const char* name, const char* label) { return ar(*value, name, label); }
TypeID Type() const{ return TypeID::get<T>(); }
void Call(const ApplyFunction& applyFunction)
{
T newValue;
applyFunction((void*)&newValue, TypeID::get<T>());
if (oldValue != newValue)
{
callback(newValue);
oldValue = newValue;
}
}
};
template<class T, class Decorator = T>
struct CallbackWithDecorator
: ICallback
{
typedef AZStd::function<void(const T&)> CallbackFunction;
typedef AZStd::function<Decorator (T&)> DecoratorFunction;
T oldValue;
T* value;
CallbackFunction callback;
DecoratorFunction decorator;
CallbackWithDecorator(T* value,
const T& oldValue,
const CallbackFunction& callback,
const DecoratorFunction& decorator)
: value(value)
, oldValue(oldValue)
, callback(callback)
, decorator(decorator)
{
}
ICallback* Clone() { return new CallbackWithDecorator<T, Decorator>(0, oldValue, callback, decorator); }
void Release() { delete this; }
bool SerializeValue(IArchive& ar, const char* name, const char* label) { return ar(decorator(*value), name, label); }
TypeID Type() const{ return TypeID::get<Decorator>(); }
void Call(const ApplyFunction& applyFunction)
{
T newValue;
Decorator dec = decorator(newValue);
applyFunction((void*)&dec, TypeID::get<Decorator>());
if (oldValue != newValue)
{
callback(newValue);
oldValue = newValue;
}
}
};
namespace Detail
{
template <typename T>
struct MethodReturnType
{
typedef void type;
};
template <typename ClassType, typename ReturnType, typename Arg0>
struct MethodReturnType<ReturnType(ClassType::*)(Arg0) const>
{
typedef ReturnType type;
};
template<class T>
struct OperatorBracketsReturnType
{
typedef typename MethodReturnType<decltype(& T::operator())>::type Type;
};
}
template<class T, class CallbackFunc>
CallbackSimple<T>
Callback(T& value, const CallbackFunc& callback)
{
return CallbackSimple<T>(&value, value, AZStd::function<void(const T&)>(callback));
}
template<class T, class CallbackFunc, class DecoratorFunc>
CallbackWithDecorator<T, typename Detail::OperatorBracketsReturnType<DecoratorFunc>::Type>
Callback(T& value, const CallbackFunc& callback, const DecoratorFunc& decorator)
{
typedef typename Detail::OperatorBracketsReturnType<DecoratorFunc>::Type Decorator;
return CallbackWithDecorator<T, Decorator>(&value, value,
AZStd::function<void(const T&)>(callback),
AZStd::function<Decorator(T&)>(decorator));
}
template<class T>
bool Serialize(IArchive& ar, CallbackSimple<T>& callback, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(static_cast<ICallback&>(callback), name, label);
}
else
{
if (!ar(*callback.value, name, label))
{
return false;
}
return true;
}
}
template<class T, class Decorator>
bool Serialize(IArchive& ar, CallbackWithDecorator<T, Decorator>& callback, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(static_cast<ICallback&>(callback), name, label);
}
else
{
if (!ar(*callback.value, name, label))
{
return false;
}
return true;
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CALLBACK_H
@@ -0,0 +1,376 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CLASSFACTORY_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CLASSFACTORY_H
#pragma once
#include <map>
#include <vector>
#include "Serialization/Assert.h"
#include "Serialization/IClassFactory.h"
#include "Serialization/TypeID.h"
namespace Serialization {
class IArchive;
class ClassFactoryManager
{
public:
static ClassFactoryManager& the()
{
static ClassFactoryManager factoryManager;
return factoryManager;
}
const IClassFactory* find(TypeID baseType) const
{
lazyRegisterFactories();
Factories::const_iterator it = factories_.find(baseType);
if (it == factories_.end())
{
return 0;
}
else
{
return it->second;
}
}
void registerFactory([[maybe_unused]] TypeID type, IClassFactory* factory)
{
factory->m_next = m_head;
m_head = factory;
}
protected:
void lazyRegisterFactories() const
{
if (m_head)
{
IClassFactory* factory = m_head;
while (factory)
{
const_cast<ClassFactoryManager*>(this)->factories_[factory->baseType_] = factory;
factory = factory->m_next;
}
const_cast<ClassFactoryManager*>(this)->m_head = nullptr;
}
}
typedef AZStd::unordered_map<TypeID, const IClassFactory*, AZStd::hash<TypeID>, AZStd::equal_to<TypeID>, AZ::StdLegacyAllocator> Factories;
Factories factories_;
IClassFactory* m_head = nullptr;
};
template<class BaseType>
class ClassFactory
: public IClassFactory
{
public:
static ClassFactory& the()
{
static AZStd::aligned_storage_for_t<ClassFactory> storage;
if (s_instance != (decltype(s_instance))&storage)
{
s_instance = new(&storage) ClassFactory();
}
return *s_instance;
}
static void destroy()
{
if (s_instance)
{
s_instance->~ClassFactory();
s_instance = nullptr;
}
}
class CreatorBase
{
public:
virtual ~CreatorBase() {}
virtual BaseType* create() const = 0;
virtual const TypeDescription& description() const{ return *description_; }
virtual void* vptr() const { return vptr_; }
virtual TypeID typeID() const = 0;
protected:
const TypeDescription* description_ = nullptr;
void* vptr_ = nullptr;
public:
CreatorBase* next;
};
static void* extractVPtr(BaseType* ptr)
{
return *((void**)ptr);
}
template<class Derived>
struct Annotation
{
Annotation(IClassFactory* factory, const char* name, const char* value) { static_cast<ClassFactory<BaseType>*>(factory)->addAnnotation<Derived>(name, value); }
};
template<class Derived>
class Creator
: public CreatorBase
{
public:
Creator(const TypeDescription* description, ClassFactory* factory = nullptr)
{
this->description_ = description;
if (!factory)
{
factory = &ClassFactory::the();
}
factory->registerCreator(this);
}
void* vptr() const override
{
if (!this->vptr_)
{
Derived vptrProbe;
const_cast<Creator*>(this)->vptr_ = extractVPtr(&vptrProbe);
}
return this->vptr_;
}
BaseType* create() const override { return new Derived(); }
TypeID typeID() const override { return Serialization::TypeID::get<Derived>(); }
};
ClassFactory()
: IClassFactory(TypeID::get<BaseType>())
{
ClassFactoryManager::the().registerFactory(baseType_, this);
}
~ClassFactory()
{
m_data->~Data();
m_data = nullptr;
}
typedef AZStd::unordered_map<string, const CreatorBase*, AZStd::hash<string>, AZStd::equal_to<string>, AZ::StdLegacyAllocator> TypeToCreatorMap;
typedef AZStd::unordered_map<void*, CreatorBase*, AZStd::hash<void*>, AZStd::equal_to<void*>, AZ::StdLegacyAllocator> VPtrToCreatorMap;
typedef AZStd::unordered_map<string, TypeID, AZStd::hash<string>, AZStd::equal_to<string>, AZ::StdLegacyAllocator> RegisteredNameToTypeID;
typedef AZStd::unordered_map<TypeID, std::vector<std::pair<const char*, const char*> >, AZStd::hash<TypeID>, AZStd::equal_to<TypeID>, AZ::StdLegacyAllocator> AnnotationMap;
virtual BaseType* create(const char* registeredName) const
{
lazyRegisterCreators();
if (!registeredName)
{
return 0;
}
if (registeredName[0] == '\0')
{
return 0;
}
typename TypeToCreatorMap::const_iterator it = m_data->typeToCreatorMap_.find(registeredName);
if (it != m_data->typeToCreatorMap_.end())
{
return it->second->create();
}
else
{
return 0;
}
}
virtual const char* getRegisteredTypeName(BaseType* ptr) const
{
lazyRegisterCreators();
if (ptr == 0)
{
return "";
}
void* vptr = extractVPtr(ptr);
typename VPtrToCreatorMap::const_iterator it = m_data->vptrToCreatorMap_.find(vptr);
if (it == m_data->vptrToCreatorMap_.end())
{
return "";
}
return it->second->description().name();
}
BaseType* createByIndex(int index) const
{
lazyRegisterCreators();
YASLI_ASSERT(size_t(index) < m_data->creators_.size());
return m_data->creators_[index]->create();
}
void serializeNewByIndex(IArchive& ar, int index, const char* name, const char* label)
{
lazyRegisterCreators();
YASLI_ESCAPE(size_t(index) < m_data->creators_.size(), return );
BaseType* ptr = m_data->creators_[index]->create();
ar(*ptr, name, label);
delete ptr;
}
// from ClassFactoryInterface:
size_t size() const{ return m_data->creators_.size(); }
const TypeDescription* descriptionByIndex(int index) const override
{
lazyRegisterCreators();
if (size_t(index) >= int(m_data->creators_.size()))
{
return 0;
}
return &m_data->creators_[index]->description();
}
const TypeDescription* descriptionByRegisteredName(const char* name) const override
{
lazyRegisterCreators();
const size_t numCreators = m_data->creators_.size();
for (size_t i = 0; i < numCreators; ++i)
{
if (strcmp(m_data->creators_[i]->description().name(), name) == 0)
{
return &m_data->creators_[i]->description();
}
}
return 0;
}
// ^^^
TypeID typeIDByRegisteredName(const char* registeredTypeName) const
{
lazyRegisterCreators();
RegisteredNameToTypeID::const_iterator it = m_data->registeredNameToTypeID_.find(registeredTypeName);
if (it == m_data->registeredNameToTypeID_.end())
{
return TypeID();
}
return it->second;
}
const char* findAnnotation(const char* registeredTypeName, const char* name) const
{
lazyRegisterCreators();
TypeID typeID = typeIDByRegisteredName(registeredTypeName);
AnnotationMap::const_iterator it = m_data->annotations_.find(typeID);
if (it == m_data->annotations_.end())
{
return "";
}
for (size_t i = 0; i < it->second.size(); ++i)
{
if (strcmp(it->second[i].first, name) == 0)
{
return it->second[i].second;
}
}
return "";
}
void unregisterCreator(const TypeDescription& typeDescription)
{
auto creator = m_data->typeToCreatorMap_.find(typeDescription.name());
if (creator != m_data->typeToCreatorMap_.end())
{
m_data->creators_.erase(std::find(m_data->creators_.begin(), m_data->creators_.end(), m_data->creator->second));
m_data->vptrToCreatorMap_.erase(m_data->vptrToCreatorMap_.find(creator->second->vptr()));
m_data->typeToCreatorMap_.erase(creator);
}
}
protected:
virtual void registerCreator(CreatorBase* creator)
{
creator->next = creatorsList;
creatorsList = creator;
}
void lazyRegisterCreators() const
{
if (!m_data)
{
const_cast<ClassFactory*>(this)->m_data = ::new((void*)&m_dataStorage) Data();
for (CreatorBase* creator = creatorsList; creator; creator = creator->next)
{
if (!const_cast<ClassFactory*>(this)->m_data->typeToCreatorMap_.insert(AZStd::make_pair(creator->description().name(), creator)).second)
{
YASLI_ASSERT(0 && "Type registered twice in the same factory. Was SERIALIZATION_CLASS_NAME put into header file by mistake?");
}
const_cast<ClassFactory*>(this)->m_data->creators_.push_back(creator);
const_cast<ClassFactory*>(this)->m_data->registeredNameToTypeID_[creator->description().name()] = creator->typeID();
const_cast<ClassFactory*>(this)->m_data->vptrToCreatorMap_[creator->vptr()] = creator;
}
}
}
template<class T>
void addAnnotation(const char* name, const char* value)
{
addAnnotation(Serialization::TypeID::get<T>(), name, value);
}
virtual void addAnnotation(const Serialization::TypeID& id, const char* name, const char* value)
{
lazyRegisterCreators();
m_data->annotations_[id].push_back(std::make_pair(name, value));
}
CreatorBase* creatorsList = nullptr;
static ClassFactory* s_instance;
struct Data
{
TypeToCreatorMap typeToCreatorMap_;
AZStd::vector<CreatorBase*, AZ::StdLegacyAllocator> creators_;
VPtrToCreatorMap vptrToCreatorMap_;
RegisteredNameToTypeID registeredNameToTypeID_;
AnnotationMap annotations_;
};
Data* m_data = nullptr;
AZStd::aligned_storage_for_t<Data> m_dataStorage;
};
template <class T>
ClassFactory<T>* ClassFactory<T>::s_instance = nullptr;
}
#define SERIALIZATION_CLASS_NULL(BaseType, name) \
namespace { \
bool BaseType##_NullRegistered = Serialization::ClassFactory<BaseType>::the().setNullLabel(name); \
}
#define SERIALIZATION_CLASS_NAME(BaseType, Type, name, label) \
static const Serialization::TypeDescription Type##BaseType##_DerivedDescription(name, label); \
static Serialization::ClassFactory<BaseType>::Creator<Type> Type##BaseType##_Creator(&Type##BaseType##_DerivedDescription); \
int dummyForType_##Type##BaseType;
#define SERIALIZATION_CLASS_NAME_FOR_FACTORY(Factory, BaseType, Type, name, label) \
static const Serialization::TypeDescription Type##BaseType##_DerivedDescription(name, label); \
static Serialization::ClassFactory<BaseType>::Creator<Type> Type##BaseType##_Creator(&Type##BaseType##_DerivedDescription, &(Factory));
#define SERIALIZATION_CLASS_ANNOTATION(BaseType, Type, attributeName, attributeValue) \
static Serialization::ClassFactory<BaseType>::Annotation<Type> Type##BaseType##_Annotation(&Serialization::ClassFactory<BaseType>::the(), attributeName, attributeValue);
#define SERIALIZATION_CLASS_ANNOTATION_FOR_FACTORY(factory, BaseType, Type, attributeName, attributeValue) \
static Serialization::ClassFactory<BaseType>::Annotation<Type> Type##BaseType##_Annotation(&factory, attributeName, attributeValue);
#define SERIALIZATION_FORCE_CLASS(BaseType, Type) \
extern int dummyForType_##Type##BaseType; \
int* dummyForTypePtr_##Type##BaseType = &dummyForType_##Type##BaseType + 1;
#include "ClassFactoryImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CLASSFACTORY_H
@@ -0,0 +1,47 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CLASSFACTORYIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CLASSFACTORYIMPL_H
#pragma once
#include "IArchive.h"
#include "IClassFactory.h"
#include "STL.h"
#include "ClassFactory.h"
#include "Strings.h"
namespace Serialization {
inline bool Serialize(Serialization::IArchive& ar, Serialization::TypeNameWithFactory& value, const char* name, [[maybe_unused]] const char* label)
{
if (!ar(value.registeredName, name))
{
return false;
}
if (ar.IsInput())
{
const TypeDescription* desc = value.factory->descriptionByRegisteredName(value.registeredName.c_str());
if (!desc)
{
ar.Error(value, "Unable to read TypeID: unregistered type name: \'%s\'", value.registeredName.c_str());
value.registeredName.clear();
return false;
}
}
return true;
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CLASSFACTORYIMPL_H
@@ -0,0 +1,55 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_COLOR_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_COLOR_H
#pragma once
#include <Serialization/IArchive.h>
#include <Serialization/Decorators/Range.h>
template<typename T>
inline bool Serialize(Serialization::IArchive& ar, Color_tpl<T>& c, const char* name, const char* label);
namespace Serialization
{
struct Vec3AsColor
{
Vec3& v;
Vec3AsColor(Vec3& v)
: v(v) {}
void Serialize(Serialization::IArchive& ar)
{
ar(Range(v.x, 0.0f, 1.0f), "r", "^");
ar(Range(v.y, 0.0f, 1.0f), "g", "^");
ar(Range(v.z, 0.0f, 1.0f), "b", "^");
}
};
inline bool Serialize(Serialization::IArchive& ar, Vec3AsColor& c, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct(c), name, label);
}
else
{
typedef float (* Array)[3];
return ar(*((Array) & c.v.x), name, label);
}
}
}
#include "ColorImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_COLOR_H
@@ -0,0 +1,53 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_COLORIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_COLORIMPL_H
#pragma once
#include "Color.h"
//////////////////////////////////////////////////////////////////////////
template<typename T>
struct SerializableColor_tpl
: Color_tpl<T>
{
static float ColorRangeMin(float) { return 0.0f; }
static float ColorRangeMax(float) { return 1.0f; }
static unsigned char ColorRangeMin(unsigned char) { return 0; }
static unsigned char ColorRangeMax(unsigned char) { return 255; }
void Serialize(Serialization::IArchive& ar)
{
ar(Serialization::Range(Color_tpl<T>::r, ColorRangeMin(Color_tpl<T>::r), ColorRangeMax(Color_tpl<T>::r)), "r", "^");
ar(Serialization::Range(Color_tpl<T>::g, ColorRangeMin(Color_tpl<T>::g), ColorRangeMax(Color_tpl<T>::g)), "g", "^");
ar(Serialization::Range(Color_tpl<T>::b, ColorRangeMin(Color_tpl<T>::b), ColorRangeMax(Color_tpl<T>::b)), "b", "^");
ar(Serialization::Range(Color_tpl<T>::a, ColorRangeMin(Color_tpl<T>::a), ColorRangeMax(Color_tpl<T>::a)), "a", "^");
}
};
template<typename T>
bool Serialize(Serialization::IArchive& ar, Color_tpl<T>& c, const char* name, const char* label)
{
if (ar.IsEdit())
{
return Serialize(ar, static_cast<SerializableColor_tpl<T>&>(c), name, label);
}
else
{
typedef T (& Array)[4];
return ar((Array)c, name, label);
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_COLORIMPL_H
@@ -0,0 +1,44 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYEXTENSION_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYEXTENSION_H
#pragma once
#ifdef GetClassName
#undef GetClassName
#endif
#include <CryExtension/ICryFactory.h>
namespace Serialization
{
// Allows to have AZStd::shared_ptr<TPointer> but serialize it by
// interface-casting to TSerializable, i.e. implementing Serialization through
// separate interface.
template<class TPointer, class TSerializable = TPointer>
struct CryExtensionPointer
{
AZStd::shared_ptr<TPointer>& ptr;
CryExtensionPointer(AZStd::shared_ptr<TPointer>& _ptr)
: ptr(_ptr) {}
void Serialize(Serialization::IArchive& ar);
};
}
// This function treats T as a type derived from CryUnknown type.
template<class T>
bool Serialize(Serialization::IArchive& ar, AZStd::shared_ptr<T>& ptr, const char* name, const char* label);
#include "CryExtensionImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYEXTENSION_H
@@ -0,0 +1,281 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYEXTENSIONIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYEXTENSIONIMPL_H
#pragma once
#include <Serialization/StringList.h>
#include <CryExtension/ICryFactoryRegistry.h>
#include <CryExtension/CryTypeID.h>
#include <ISystem.h>
namespace Serialization {
// Generate user-friendly class name, e.g. convert
// "AnimationPoseModifier_FootStore" -> "Foot Store"
inline string MakePrettyClassName(const char* className)
{
const char* firstSep = strchr(className, '_');
if (!firstSep)
{
// name doesn't follow expected convention, return as is
return className;
}
const char* start = firstSep + 1;
string result;
result.reserve(strlen(start) + 4);
const char* p = start;
while (*p != '\0')
{
if (*p >= 'A' && *p <= 'Z' &&
*(p - 1) >= 'a' && *(p - 1) <= 'z')
{
result += ' ';
}
if (*p == '_')
{
result += ' ';
}
else
{
result += *p;
}
++p;
}
return result;
}
// Provides Serialization::IClassFactory interface for classes
// registered with CryExtension to IArchive.
//
// TSerializable can be used to expose Serialize method through
// a separate interface, rathern than TBase. Safe to missing
// as QueryInterface is used to check its presence.
template<class TBase, class TSerializable = TBase>
class CryExtensionClassFactory
: public Serialization::IClassFactory
{
public:
size_t size() const override
{
return m_types.size();
}
static CryExtensionClassFactory& the()
{
static CryExtensionClassFactory instance;
return instance;
}
CryExtensionClassFactory()
: IClassFactory(Serialization::TypeID::get<TBase>())
{
setNullLabel("[ None ]");
ICryFactoryRegistry* factoryRegistry = gEnv->pSystem->GetCryFactoryRegistry();
size_t factoryCount = 0;
factoryRegistry->IterateFactories(cryiidof<TBase>(), 0, factoryCount);
if (factoryCount)
{
string sharedPrefix;
bool hasSharedPrefix = true;
AZStd::unique_ptr<ICryFactory*[]> factories(new ICryFactory*[factoryCount]);
factoryRegistry->IterateFactories(cryiidof<TBase>(), factories.get(), factoryCount);
for (size_t i = 0; i < factoryCount; ++i)
{
ICryFactory* factory = factories[i];
if (factory->ClassSupports(cryiidof<TSerializable>()))
{
m_factories.push_back(factory);
if (hasSharedPrefix)
{
// make sure that shared prefix is the same for all the names
const char* name = factory->GetName();
const char* lastPrefixCharacter = strchr(name, '_');
if (lastPrefixCharacter == 0)
{
hasSharedPrefix = false;
}
else
{
if (!sharedPrefix.empty())
{
if (strncmp(name, sharedPrefix.c_str(), sharedPrefix.size()) != 0)
{
hasSharedPrefix = false;
}
}
else
{
sharedPrefix.assign(name, lastPrefixCharacter + 1);
}
}
}
}
}
size_t usableFactoriesCount = m_factories.size();
m_types.reserve(usableFactoriesCount);
m_labels.reserve(usableFactoriesCount);
for (size_t i = 0; i < usableFactoriesCount; ++i)
{
ICryFactory* factory = m_factories[i];
m_classIds.push_back(factory->GetClassID());
const char* name = factory->GetName();
m_labels.push_back(MakePrettyClassName(name));
if (hasSharedPrefix)
{
name += sharedPrefix.size();
}
m_types.push_back(Serialization::TypeDescription(name, m_labels.back().c_str()));
}
}
}
const Serialization::TypeDescription* descriptionByIndex(int index) const override
{
if (size_t(index) >= m_types.size())
{
return 0;
}
return &m_types[index];
}
const Serialization::TypeDescription* descriptionByRegisteredName(const char* registeredName) const override
{
size_t count = m_types.size();
for (size_t i = 0; i < m_types.size(); ++i)
{
if (strcmp(m_types[i].name(), registeredName) == 0)
{
return &m_types[i];
}
}
return 0;
}
const char* findAnnotation(const char* typeName, const char* name) const override { return ""; }
void serializeNewByIndex(IArchive& ar, int index, const char* name, const char* label) override
{
if (size_t(index) >= m_types.size())
{
return;
}
AZStd::shared_ptr<TBase> ptr(create(m_types[index].name()));
if (TSerializable* ser = cryinterface_cast<TSerializable>(ptr.get()))
{
ar(*ser, name, label);
}
}
AZStd::shared_ptr<TBase> create(const char* registeredName)
{
size_t count = m_types.size();
for (size_t i = 0; i < count; ++i)
{
if (strcmp(m_types[i].name(), registeredName) == 0)
{
return AZStd::static_pointer_cast<TBase>(m_factories[i]->CreateClassInstance());
}
}
return AZStd::shared_ptr<TBase>();
}
const char* getRegisteredTypeName(const AZStd::shared_ptr<TBase>& ptr) const
{
if (!ptr.get())
{
return "";
}
CryInterfaceID id = AZStd::static_pointer_cast<TBase>(ptr)->GetFactory()->GetClassID();
size_t count = m_classIds.size();
for (size_t i = 0; i < count; ++i)
{
if (m_classIds[i] == id)
{
return m_types[i].name();
}
}
return "";
}
private:
std::vector<Serialization::TypeDescription> m_types;
std::vector<string> m_labels;
std::vector<ICryFactory*> m_factories;
std::vector<CryInterfaceID> m_classIds;
};
// Exposes CryExtension shared_ptr<> as serializeable type for Serialization::IArchive
template<class T, class TSerializable>
class CryExtensionSharedPtr
: public Serialization::IPointer
{
public:
CryExtensionSharedPtr(AZStd::shared_ptr<T>& ptr)
: m_ptr(ptr)
{}
const char* registeredTypeName() const override
{
if (m_ptr)
{
return factory()->getRegisteredTypeName(m_ptr);
}
else
{
return "";
}
}
void create(const char* registeredTypeName) const override
{
if (registeredTypeName[0] != '\0')
{
m_ptr = factory()->create(registeredTypeName);
}
else
{
m_ptr.reset((T*)0);
}
}
Serialization::TypeID baseType() const{ return Serialization::TypeID::get<T>(); }
virtual Serialization::SStruct serializer() const override
{
if (TSerializable* ser = cryinterface_cast<TSerializable>(m_ptr.get()))
{
return Serialization::SStruct(*ser);
}
else
{
return Serialization::SStruct();
}
}
void* get() const override { return reinterpret_cast<void*>(m_ptr.get()); }
const void* handle() const override { return &m_ptr; }
Serialization::TypeID pointerType() const override { return Serialization::TypeID::get<AZStd::shared_ptr<T> >(); }
CryExtensionClassFactory<T, TSerializable>* factory() const override { return &CryExtensionClassFactory<T, TSerializable>::the(); }
protected:
AZStd::shared_ptr<T>& m_ptr;
};
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYEXTENSIONIMPL_H
@@ -0,0 +1,26 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYNAME_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYNAME_H
#pragma once
namespace Serialization {
class IArchive;
}
inline bool Serialize(Serialization::IArchive & ar, class CCryName & cryName, const char* name, const char* label);
#include "CryNameImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYNAME_H
@@ -0,0 +1,61 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYNAMEIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYNAMEIMPL_H
#pragma once
#include "CryName.h"
#include "IArchive.h"
class CryNameSerializer
: public Serialization::IString
{
public:
CryNameSerializer(CCryName& s)
: m_s(s)
{
}
virtual void set(const char* value)
{
m_s = value;
}
virtual const char* get() const
{
return m_s.c_str();
}
virtual const void* handle() const
{
return &m_s;
}
virtual Serialization::TypeID type() const
{
return Serialization::TypeID::get<CCryName>();
}
CCryName& m_s;
};
inline bool Serialize(Serialization::IArchive& ar, CCryName& cryName, const char* name, const char* label)
{
CryNameSerializer serializer(cryName);
return ar(static_cast<Serialization::IString&>(serializer), name, label);
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_CRYNAMEIMPL_H
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#pragma once
#include "CryFixedString.h"
#include "Serialization/Serializer.h"
namespace Serialization
{
class IArchive;
}
// Note : if you are looking for the CryStringT serialization, it is handled in Serialization/STL.h
template< size_t N >
bool Serialize(Serialization::IArchive& ar, CryFixedStringT< N >& value, const char* name, const char* label);
template< size_t N >
bool Serialize(Serialization::IArchive& ar, CryStackStringT< char, N >& value, const char* name, const char* label);
template< size_t N >
bool Serialize(Serialization::IArchive& ar, CryStackStringT< wchar_t, N >& value, const char* name, const char* label);
#include "Serialization/CryStringsImpl.h"
@@ -0,0 +1,74 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#pragma once
#include "Serialization/IArchive.h"
#include "Serialization/CryStrings.h"
namespace Serialization
{
template< class TFixedStringClass >
class CFixedStringSerializer
: public IString
{
public:
CFixedStringSerializer(TFixedStringClass& str)
: str_(str) { }
void set(const char* value) { str_ = value; }
const char* get() const { return str_.c_str(); }
const void* handle() const { return &str_; }
TypeID type() const { return TypeID::get<TFixedStringClass>(); }
private:
TFixedStringClass& str_;
};
template< class TFixedStringClass >
class CFixedWStringSerializer
: public IWString
{
public:
CFixedWStringSerializer(TFixedStringClass& str)
: str_(str) { }
void set(const wchar_t* value) { str_ = value; }
const wchar_t* get() const { return str_.c_str(); }
const void* handle() const { return &str_; }
TypeID type() const { return TypeID::get<TFixedStringClass>(); }
private:
TFixedStringClass& str_;
};
}
template< size_t N >
inline bool Serialize(Serialization::IArchive& ar, CryFixedStringT< N >& value, const char* name, const char* label)
{
Serialization::CFixedStringSerializer< CryFixedStringT< N > > str(value);
return ar(static_cast<Serialization::IString&>(str), name, label);
}
template< size_t N >
inline bool Serialize(Serialization::IArchive& ar, CryStackStringT< char, N >& value, const char* name, const char* label)
{
Serialization::CFixedStringSerializer< CryStackStringT< char, N > > str(value);
return ar(static_cast<Serialization::IString&>(str), name, label);
}
template< size_t N >
inline bool Serialize(Serialization::IArchive& ar, CryStackStringT< wchar_t, N >& value, const char* name, const char* label)
{
Serialization::CFixedWStringSerializer< CryStackStringT< wchar_t, N > > str(value);
return ar(static_cast<Serialization::IWString&>(str), name, label);
}
@@ -0,0 +1,89 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#pragma once
#include <SmartPointersHelpers.h>
#include <Serialization/IArchive.h>
#include <functor.h>
namespace Serialization
{
struct IActionButton;
DECLARE_SMART_POINTERS(IActionButton)
struct IActionButton
{
virtual ~IActionButton() {}
virtual void Callback() const = 0;
virtual const char* Icon() const = 0;
virtual IActionButtonPtr Clone() const = 0;
};
typedef Functor0 FunctorActionButtonCallback;
struct FunctorActionButton
: public IActionButton
{
FunctorActionButtonCallback callback;
string icon;
explicit FunctorActionButton(const FunctorActionButtonCallback& callback, const char* icon = "")
: callback(callback)
, icon(icon)
{
}
// IActionButton
virtual void Callback() const override
{
if (callback)
{
callback();
}
}
virtual const char* Icon() const override
{
return icon.c_str();
}
virtual IActionButtonPtr Clone() const override
{
return IActionButtonPtr(new FunctorActionButton(callback, icon.c_str()));
}
// ~IActionButton
};
inline bool Serialize(Serialization::IArchive& ar, FunctorActionButton& button, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(static_cast<Serialization::IActionButton&>(button)), name, label);
}
else
{
return false;
}
}
inline FunctorActionButton ActionButton(const FunctorActionButtonCallback& callback, const char* icon = "")
{
return FunctorActionButton(callback, icon);
}
}
@@ -0,0 +1,64 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_BITFLAGS_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_BITFLAGS_H
#pragma once
#include <Serialization/Enum.h>
namespace Serialization {
class IArchive;
struct BitFlagsWrapper
{
int* variable;
unsigned int visibleMask;
const CEnumDescription* description;
void Serialize(IArchive& ar);
};
template<class Enum>
BitFlagsWrapper BitFlags(Enum& value)
{
BitFlagsWrapper wrapper;
wrapper.variable = (int*)&value;
wrapper.visibleMask = ~0U;
wrapper.description = &getEnumDescription<Enum>();
return wrapper;
}
template<class Enum>
BitFlagsWrapper BitFlags(int& value, int visibleMask = ~0)
{
BitFlagsWrapper wrapper;
wrapper.variable = &value;
wrapper.visibleMask = visibleMask;
wrapper.description = &getEnumDescription<Enum>();
return wrapper;
}
template<class Enum>
BitFlagsWrapper BitFlags(unsigned int& value, unsigned int visibleMask = ~0)
{
BitFlagsWrapper wrapper;
wrapper.variable = (int*)&value;
wrapper.visibleMask = visibleMask;
wrapper.description = &getEnumDescription<Enum>();
return wrapper;
}
}
#include "BitFlagsImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_BITFLAGS_H
@@ -0,0 +1,67 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_BITFLAGSIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_BITFLAGSIMPL_H
#pragma once
#include "Serialization/IArchive.h"
namespace Serialization {
inline void BitFlagsWrapper::Serialize(IArchive& ar)
{
const Serialization::CEnumDescription& desc = *description;
int count = desc.count();
if (ar.IsInput())
{
int previousValue = *variable;
for (int i = 0; i < count; ++i)
{
int flagValue = desc.valueByIndex(i);
if (!(flagValue & visibleMask))
{
continue;
}
bool flag = (previousValue & flagValue) == flagValue;
bool previousFlag = flag;
ar(flag, desc.nameByIndex(i), desc.labelByIndex(i));
if (flag != previousFlag)
{
if (flag)
{
*variable |= flagValue;
}
else
{
*variable &= ~flagValue;
}
}
}
}
else
{
for (int i = 0; i < count; ++i)
{
int flagValue = desc.valueByIndex(i);
if (!(flagValue & visibleMask))
{
continue;
}
bool flag = (*variable & flagValue) == flagValue;
ar(flag, desc.nameByIndex(i), desc.labelByIndex(i));
}
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_BITFLAGSIMPL_H
@@ -0,0 +1,43 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_COLORPICKER_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_COLORPICKER_H
#pragma once
#include <Cry_Math.h>
#include <Cry_Color.h>
#include <ISystem.h>
namespace Serialization
{
class IArchive;
struct ColorPicker
{
ColorF* color;
explicit ColorPicker(ColorF& color_)
: color(&color_)
{
}
// the function should stay virtual to ensure cross-dll calls are using right heap
virtual void SetColor(const ColorF* color_){* color = *color_; }
};
bool Serialize(Serialization::IArchive& ar, Serialization::ColorPicker& value, const char* name, const char* label);
} // namespace Serialization
#include "ColorPickerImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_COLORPICKER_H
@@ -0,0 +1,33 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_COLORPICKERIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_COLORPICKERIMPL_H
#pragma once
#include "../Color.h"
namespace Serialization
{
inline bool Serialize(Serialization::IArchive& ar, Serialization::ColorPicker& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(value), name, label);
}
else
{
return ar(*value.color, name, label);
}
}
} // namespace Serialization
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_COLORPICKERIMPL_H
@@ -0,0 +1,19 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_JOINTNAME_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_JOINTNAME_H
#pragma once
#include <Serialization/Decorators/Resources.h>
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_JOINTNAME_H
@@ -0,0 +1,19 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_JOINTNAMEIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_JOINTNAMEIMPL_H
#pragma once
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_JOINTNAMEIMPL_H
@@ -0,0 +1,117 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_LOCALFRAME_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_LOCALFRAME_H
#pragma once
#include <Cry_Math.h>
#include "Serialization/Math.h"
namespace Serialization
{
class IArchive;
struct LocalPosition
{
Vec3* value;
int space;
const char* parentName;
const void* handle;
LocalPosition(Vec3& _vec, int _space, const char* _parentName, const void* _handle)
: value(&_vec)
, space(_space)
, parentName(_parentName)
, handle(_handle)
{
}
void Serialize(IArchive& ar);
};
struct LocalOrientation
{
Quat* value;
int space;
const char* parentName;
const void* handle;
LocalOrientation(Quat& _vec, int _space, const char* _parentName, const void* _handle)
: value(&_vec)
, space(_space)
, parentName(_parentName)
, handle(_handle)
{
}
void Serialize(IArchive& ar);
};
struct LocalFrame
{
Quat* rotation;
Vec3* position;
const char* parentName;
int rotationSpace;
int positionSpace;
const void* handle;
LocalFrame(Quat* _rotation, int _rotationSpace, Vec3* _position, int _positionSpace, const char* _parentName, const void* _handle)
: rotation(_rotation)
, position(_position)
, parentName(_parentName)
, rotationSpace(_rotationSpace)
, positionSpace(_positionSpace)
, handle(_handle)
{
}
void Serialize(IArchive& ar);
};
enum
{
SPACE_JOINT,
SPACE_ENTITY,
SPACE_JOINT_WITH_PARENT_ROTATION,
SPACE_JOINT_WITH_CHARACTER_ROTATION,
SPACE_SOCKET_RELATIVE_TO_JOINT,
SPACE_SOCKET_RELATIVE_TO_BINDPOSE
};
//position
inline LocalPosition LocalToEntity(Vec3& position, const void* handle = 0)
{
return LocalPosition(position, SPACE_ENTITY, "", handle ? handle : &position);
}
inline LocalPosition LocalToJoint(Vec3& position, const string& jointName, const void* handle = 0)
{
return LocalPosition(position, SPACE_JOINT, jointName.c_str(), handle ? handle : &position);
}
inline LocalPosition LocalToJointCharacterRotation(Vec3& position, const string& jointName, const void* handle = 0)
{
return LocalPosition(position, SPACE_JOINT_WITH_CHARACTER_ROTATION, jointName.c_str(), handle ? handle : &position);
}
bool Serialize(Serialization::IArchive& ar, Serialization::LocalPosition& value, const char* name, const char* label);
bool Serialize(Serialization::IArchive& ar, Serialization::LocalOrientation& value, const char* name, const char* label);
bool Serialize(Serialization::IArchive& ar, Serialization::LocalFrame& value, const char* name, const char* label);
}
#include "LocalFrameImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_LOCALFRAME_H
@@ -0,0 +1,89 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_LOCALFRAMEIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_LOCALFRAMEIMPL_H
#pragma once
#include "LocalFrame.h"
#include "Serialization/IArchive.h"
#include "Serialization/MathImpl.h"
namespace Serialization
{
inline void LocalPosition::Serialize(Serialization::IArchive& ar)
{
ar(value->x, "x", "^");
ar(value->y, "y", "^");
ar(value->z, "z", "^");
}
inline void LocalOrientation::Serialize(Serialization::IArchive& ar)
{
ar(Serialization::AsAng3(*value), "q", "^");
}
inline void LocalFrame::Serialize(Serialization::IArchive& ar)
{
ar(*position, "t", "<T");
ar(AsAng3(*rotation), "q", "<R");
}
inline bool Serialize(Serialization::IArchive& ar, Serialization::LocalPosition& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct(value), name, label);
}
else
{
return ar(*value.value, name, label);
}
}
inline bool Serialize(Serialization::IArchive& ar, Serialization::LocalOrientation& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct(value), name, label);
}
else
{
return ar(*value.value, name, label);
}
}
inline bool Serialize(Serialization::IArchive& ar, Serialization::LocalFrame& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct(value), name, label);
}
else
{
QuatT t(*value.rotation, *value.position);
if (!ar(t, name, label))
{
return false;
}
if (ar.IsInput())
{
*value.position = t.t;
*value.rotation = t.q;
}
return true;
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_LOCALFRAMEIMPL_H
@@ -0,0 +1,49 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_OUTPUTFILEPATH_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_OUTPUTFILEPATH_H
#pragma once
#include "Serialization/Strings.h"
namespace Serialization
{
class IArchive;
struct OutputFilePath
{
string* m_path;
// if we don't use dynamic filters we could replace following two with const char*
string filter;
string startFolder;
// filters are defined in the following format:
// "All Images (bmp, jpg, tga)|*.bmp;*.jpg;*.tga|Targa (tga)|*.tga"
explicit OutputFilePath(string& path, const char* filter = "All files|*.*", const char* startFolder = "")
: m_path(&path)
, filter(filter)
, startFolder(startFolder)
{
}
// the function should stay virtual to ensure cross-dll calls are using right heap
virtual void SetPath(const char* path) { *this->m_path = path; }
};
bool Serialize(Serialization::IArchive& ar, Serialization::OutputFilePath& value, const char* name, const char* label);
}
#include "OutputFilePathImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_OUTPUTFILEPATH_H
@@ -0,0 +1,32 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_OUTPUTFILEPATHIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_OUTPUTFILEPATHIMPL_H
#pragma once
namespace Serialization
{
inline bool Serialize(Serialization::IArchive& ar, Serialization::OutputFilePath& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(value), name, label);
}
else
{
return ar(*value.m_path, name, label);
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_OUTPUTFILEPATHIMPL_H
@@ -0,0 +1,63 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RANGE_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RANGE_H
#pragma once
namespace Serialization
{
template<class T>
struct RangeDecorator
{
T* value;
T softMin;
T softMax;
T hardMin;
T hardMax;
};
template<class T>
RangeDecorator<T> Range(T& value, T hardMin, T hardMax)
{
RangeDecorator<T> r;
r.value = &value;
r.softMin = hardMin;
r.softMax = hardMax;
r.hardMin = hardMin;
r.hardMax = hardMax;
return r;
}
template<class T>
RangeDecorator<T> Range(T& value, T softMin, T softMax, T hardMin, T hardMax)
{
RangeDecorator<T> r;
r.value = &value;
r.softMin = softMin;
r.softMax = softMax;
r.hardMin = hardMin;
r.hardMax = hardMax;
return r;
}
namespace Decorators
{
// Obsolete name, will be removed. Please use Serialization::Range instead.
using Serialization::Range;
}
}
#include "RangeImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RANGE_H
@@ -0,0 +1,50 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RANGEIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RANGEIMPL_H
#pragma once
namespace Serialization
{
template<class T>
bool Serialize(IArchive& ar, RangeDecorator<T>& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
if (!ar(SStruct::ForEdit(value), name, label))
{
return false;
}
}
else if (!ar(*value.value, name, label))
{
return false;
}
if (ar.IsInput())
{
if (*value.value < value.hardMin)
{
*value.value = value.hardMin;
}
if (*value.value > value.hardMax)
{
*value.value = value.hardMax;
}
}
return true;
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RANGEIMPL_H
@@ -0,0 +1,59 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFILEPATH_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFILEPATH_H
#pragma once
#include "Serialization/Strings.h"
namespace Serialization
{
class IArchive;
struct ResourceFilePath
{
enum
{
STRIP_EXTENSION = 1 << 0
};
string* m_path;
string filter;
bool group;
int flags;
// filters are defined in the following format:
// "All Images (bmp, jpg, tga)|*.bmp;*.jpg;*.tga|Targa (tga)|*.tga"
explicit ResourceFilePath(string& path, const char* filter = "", bool group = false, int flags = 0)
: m_path(&path)
, filter(filter)
, group(group)
, flags(flags)
{
}
// the function should stay virtual to ensure cross-dll calls are using right heap
virtual void SetPath(const char* path) { *this->m_path = path; }
};
inline ResourceFilePath MaterialPath(string& path)
{
return ResourceFilePath(path, "Material", false, ResourceFilePath::STRIP_EXTENSION);
}
bool Serialize(Serialization::IArchive& ar, Serialization::ResourceFilePath& value, const char* name, const char* label);
}
#include "ResourceFilePathImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFILEPATH_H
@@ -0,0 +1,32 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFILEPATHIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFILEPATHIMPL_H
#pragma once
namespace Serialization
{
inline bool Serialize(Serialization::IArchive& ar, Serialization::ResourceFilePath& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(value), name, label);
}
else
{
return ar(*value.m_path, name, label);
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFILEPATHIMPL_H
@@ -0,0 +1,43 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFOLDERPATH_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFOLDERPATH_H
#pragma once
#include "Serialization/Strings.h"
namespace Serialization
{
class IArchive;
struct ResourceFolderPath
{
string* m_path;
string startFolder;
explicit ResourceFolderPath(string& path, const char* startFolder = "")
: m_path(&path)
, startFolder(startFolder)
{
}
// the function should stay virtual to ensure cross-dll calls are using right heap
virtual void SetPath(const char* path) { *this->m_path = path; }
};
bool Serialize(Serialization::IArchive& ar, Serialization::ResourceFolderPath& value, const char* name, const char* label);
}
#include "ResourceFolderPathImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFOLDERPATH_H
@@ -0,0 +1,34 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFOLDERPATHIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFOLDERPATHIMPL_H
#pragma once
#include "Serialization/IArchive.h"
namespace Serialization
{
inline bool Serialize(Serialization::IArchive& ar, Serialization::ResourceFolderPath& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(value), name, label);
}
else
{
return ar(*value.m_path, name, label);
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCEFOLDERPATHIMPL_H
@@ -0,0 +1,100 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#pragma once
namespace Serialization
{
struct IResourceSelector
{
const char* resourceType;
virtual ~IResourceSelector() {}
virtual const char* GetValue() const = 0;
virtual void SetValue(const char* s) = 0;
virtual int GetId() const{ return -1; }
virtual const void* GetHandle() const = 0;
virtual Serialization::TypeID GetType() const = 0;
};
// Provides a way to annotate resource reference so different UI can be used
// for them. See IResourceSelector.h to see how selectors for specific types
// are registered.
//
// TString could be SCRCRef or CCryName as well.
//
// Do not use this class directly, instead use function that wraps it for
// specific type, see Resources.h for example.
template<class TString>
struct ResourceSelector
: IResourceSelector
{
TString& value;
const char* GetValue() const { return value.c_str(); }
void SetValue(const char* s) { value = s; }
const void* GetHandle() const { return &value; }
Serialization::TypeID GetType() const { return Serialization::TypeID::get<TString>(); }
ResourceSelector(TString& _value, const char* _resourceType)
: value(_value)
{
this->resourceType = _resourceType;
}
};
struct ResourceSelectorWithId
: IResourceSelector
{
string& value;
int id;
const char* GetValue() const { return value.c_str(); }
void SetValue(const char* s) { value = s; }
int GetId() const { return id; }
const void* GetHandle() const { return &value; }
Serialization::TypeID GetType() const { return Serialization::TypeID::get<string>(); }
ResourceSelectorWithId(string& _value, const char* _resourceType, int _id)
: value(_value)
, id(_id)
{
this->resourceType = _resourceType;
}
};
template<class T>
bool Serialize(IArchive& ar, ResourceSelector<T>& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(static_cast<IResourceSelector&>(value)), name, label);
}
else
{
return ar(value.value, name, label);
}
}
inline bool Serialize(IArchive& ar, ResourceSelectorWithId& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(static_cast<IResourceSelector&>(value)), name, label);
}
else
{
return ar(value.value, name, label);
}
}
}
@@ -0,0 +1,67 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCES_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCES_H
#pragma once
#include "ResourceSelector.h"
namespace Serialization
{
// animation resources
template<class T>
ResourceSelector<T> AnimationAlias(T& s) { return ResourceSelector<T>(s, "AnimationAlias"); } // "name" from animation set
template<class T>
ResourceSelector<T> AnimationPath(T& s) { return ResourceSelector<T>(s, "Animation"); }
inline ResourceSelectorWithId AnimationPathWithId(string& s, int id) { return ResourceSelectorWithId(s, "Animation", id); }
template<class T>
ResourceSelector<T> CharacterPath(T& s) { return ResourceSelector<T>(s, "Character"); }
template<class T>
ResourceSelector<T> CharacterPhysicsPath(T& s) { return ResourceSelector<T>(s, "CharacterPhysics"); }
template<class T>
ResourceSelector<T> CharacterRigPath(T& s) { return ResourceSelector<T>(s, "CharacterRig"); }
template<class T>
ResourceSelector<T> SkeletonPath(T& s) { return ResourceSelector<T>(s, "Skeleton"); }
template<class T>
ResourceSelector<T> SkeletonParamsPath(T& s) { return ResourceSelector<T>(s, "SkeletonParams"); } // CHRParams
template<class T>
ResourceSelector<T> JointName(T& s) { return ResourceSelector<T>(s, "Joint"); }
template<class T>
ResourceSelector<T> AttachmentName(T& s) { return ResourceSelector<T>(s, "Attachment"); }
// miscelaneous resources
template<class T>
ResourceSelector<T> SoundName(T& s) { return ResourceSelector<T>(s, "Sound"); }
template<class T>
ResourceSelector<T> DialogName(T& s) { return ResourceSelector<T>(s, "Dialog"); }
template<class T>
ResourceSelector<T> ForceFeedbackIdName(T& s) { return ResourceSelector<T>(s, "ForceFeedbackId"); }
template<class T>
ResourceSelector<T> ModelFilename(T& s) { return ResourceSelector<T>(s, "Model"); }
template<class T>
ResourceSelector<T> ParticleName(T& s) { return ResourceSelector<T>(s, "Particle"); }
namespace Decorators
{
// Decorators namespace is obsolete now, SHOULD NOT BE USED.
template<class T>
ResourceSelector<T> AnimationName(T& s) { return ResourceSelector<T>(s, "Animation"); }
using Serialization::SoundName;
using Serialization::AttachmentName;
template<class T>
ResourceSelector<T> ObjectFilename(T& s) { return ResourceSelector<T>(s, "Model"); }
using Serialization::JointName;
using Serialization::ForceFeedbackIdName;
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCES_H
@@ -0,0 +1,31 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#pragma once
#include "ResourceSelector.h"
namespace Serialization
{
template<class T>
ResourceSelector<T> AudioTrigger(T& s) { return ResourceSelector<T>(s, "AudioTrigger"); }
template<class T>
ResourceSelector<T> AudioSwitch(T& s) { return ResourceSelector<T>(s, "AudioSwitch"); }
template<class T>
ResourceSelector<T> AudioSwitchState(T& s) { return ResourceSelector<T>(s, "AudioSwitchState"); }
template<class T>
ResourceSelector<T> AudioRTPC(T& s) { return ResourceSelector<T>(s, "AudioRTPC"); }
template<class T>
ResourceSelector<T> AudioEnvironment(T& s) { return ResourceSelector<T>(s, "AudioEnvironment"); }
template<class T>
ResourceSelector<T> AudioPreloadRequest(T& s) { return ResourceSelector<T>(s, "AudioPreloadRequest"); }
};
@@ -0,0 +1,44 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCESIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCESIMPL_H
#pragma once
namespace Serialization
{
template<class T>
bool Serialize(IArchive& ar, ResourceSelector<T>& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(static_cast<IResourceSelector&>(value)), name, label);
}
else
{
return ar(value.value, name, label);
}
}
inline bool Serialize(IArchive& ar, ResourceSelectorWithId& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(static_cast<IResourceSelector&>(value)), name, label);
}
else
{
return ar(value.value, name, label);
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_RESOURCESIMPL_H
@@ -0,0 +1,88 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SLIDER_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SLIDER_H
#pragma once
namespace Serialization
{
class IArchive;
struct SSliderF
{
SSliderF(float* value, float _minLimit, float _maxLimit)
: valuePointer(value)
, minLimit(_minLimit)
, maxLimit(_maxLimit)
{
}
SSliderF()
: valuePointer(0)
, minLimit(0.0f)
, maxLimit(1.0f)
{
}
float* valuePointer;
float minLimit;
float maxLimit;
};
struct SSliderI
{
SSliderI(int* value, int minLimit, int maxLimit)
: valuePointer(value)
, minLimit(minLimit)
, maxLimit(maxLimit)
{
}
SSliderI()
: valuePointer(0)
, minLimit(0)
, maxLimit(1)
{
}
int* valuePointer;
int minLimit;
int maxLimit;
};
inline SSliderF Slider(float& value, float minLimit, float maxLimit)
{
return SSliderF(&value, minLimit, maxLimit);
}
inline SSliderI Slider(int& value, int minLimit, int maxLimit)
{
return SSliderI(&value, minLimit, maxLimit);
}
bool Serialize(IArchive& ar, SSliderF& slider, const char* name, const char* label);
bool Serialize(IArchive& ar, SSliderI& slider, const char* name, const char* label);
namespace Decorators
{
// OBSOLETE NAME, please use Serialization::Slider instead (without Decorators namespace)
using Serialization::Slider;
}
}
#include "SliderImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SLIDER_H
@@ -0,0 +1,47 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SLIDERIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SLIDERIMPL_H
#pragma once
#include "Slider.h"
#include "Serialization/IArchive.h"
namespace Serialization
{
inline bool Serialize(IArchive& ar, SSliderF& slider, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(SStruct::ForEdit(slider), name, label);
}
else
{
return ar(*slider.valuePointer, name, label);
}
}
inline bool Serialize(IArchive& ar, SSliderI& slider, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(SStruct::ForEdit(slider), name, label);
}
else
{
return ar(*slider.valuePointer, name, label);
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SLIDERIMPL_H
@@ -0,0 +1,44 @@
//-------------------------------------------------------------------------------
// Copyright (C) Amazon.com, Inc. or its affiliates.
// All Rights Reserved.
//
// Licensed under the terms set out in the LICENSE.HTML file included at the
// root of the distribution; you may not use this file except in compliance
// with the License.
//
// Do not remove or modify this notice or the LICENSE.HTML file. This file
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
//-------------------------------------------------------------------------------
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SPRITE_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SPRITE_H
#pragma once
namespace Serialization
{
class IArchive;
struct Sprite
{
string* m_path;
string m_filter;
string m_startFolder;
// filters are defined in the following format:
// "All Images (bmp, jpg, tga)|*.bmp;*.jpg;*.tga|Targa (tga)|*.tga"
explicit Sprite(string& path, const char* filter = "All files|*.*", const char* startFolder = "")
: m_path(&path)
, m_filter(filter)
, m_startFolder(startFolder)
{
}
};
bool Serialize(IArchive& ar, Sprite& value, const char* name, const char* label);
} // namespace Serialization
#include "SpriteImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SPRITE_H
@@ -0,0 +1,35 @@
//-------------------------------------------------------------------------------
// Copyright (C) Amazon.com, Inc. or its affiliates.
// All Rights Reserved.
//
// Licensed under the terms set out in the LICENSE.HTML file included at the
// root of the distribution; you may not use this file except in compliance
// with the License.
//
// Do not remove or modify this notice or the LICENSE.HTML file. This file
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
//-------------------------------------------------------------------------------
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SPRITEIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SPRITEIMPL_H
#pragma once
namespace Serialization
{
inline bool Serialize(IArchive& ar, Sprite& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(SStruct::ForEdit(value), name, label);
}
else
{
return ar(*value.m_path, name, label);
}
}
} // namespace Serialization
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_SPRITEIMPL_H
@@ -0,0 +1,49 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_TAGLIST_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_TAGLIST_H
#pragma once
#include <vector>
#include "Serialization/Strings.h"
namespace Serialization {
class IArchive;
}
struct ITagSource
{
virtual void AddRef() = 0;
virtual void Release() = 0;
virtual unsigned int TagCount(unsigned int group) const = 0;
virtual const char* TagValue(unsigned int group, unsigned int index) const = 0;
virtual const char* TagDescription(unsigned int group, unsigned int index) const = 0;
virtual const char* GroupName(unsigned int group) const = 0;
virtual unsigned int GroupCount() const = 0;
};
struct TagList
{
std::vector<Serialization::string>* tags;
TagList(std::vector<Serialization::string>& tags)
: tags(&tags)
{
}
};
bool Serialize(Serialization::IArchive& ar, TagList& tagList, const char* name, const char* label);
#include "TagListImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_TAGLIST_H
@@ -0,0 +1,40 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_TAGLISTIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_TAGLISTIMPL_H
#pragma once
#include <vector>
#include "Serialization/IArchive.h"
#include "Serialization/Strings.h"
#include "Serialization/STL.h"
struct TagListContainer
: Serialization::ContainerSTL<std::vector<Serialization::string>, Serialization::string>
{
TagListContainer(TagList& tagList)
: ContainerSTL(tagList.tags)
{
}
Serialization::TypeID containerType() const override { return Serialization::TypeID::get<TagList>(); };
};
inline bool Serialize(Serialization::IArchive& ar, TagList& tagList, const char* name, const char* label)
{
TagListContainer container(tagList);
return ar(static_cast<Serialization::IContainer&>(container), name, label);
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DECORATORS_TAGLISTIMPL_H
@@ -0,0 +1,27 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DYNARRAY_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DYNARRAY_H
#pragma once
namespace Serialization {
class IArchive;
}
template<class T, class I, class S>
bool Serialize(Serialization::IArchive& ar, DynArray<T, I, S>& container, const char* name, const char* label);
#include "DynArrayImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DYNARRAY_H
@@ -0,0 +1,28 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_DYNARRAYIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_DYNARRAYIMPL_H
#pragma once
#include "IArchive.h"
#include "STLImpl.h"
template<class T, class I, class S>
bool Serialize(Serialization::IArchive& ar, DynArray<T, I, S>& container, const char* name, const char* label)
{
Serialization::ContainerSTL<DynArray<T, I, S>, T> ser(&container);
return ar(static_cast<Serialization::IContainer&>(ser), name, label);
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_DYNARRAYIMPL_H
@@ -0,0 +1,170 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_ENUM_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_ENUM_H
#pragma once
#include <vector>
#include <map>
#include "StringList.h"
#include "Serialization/TypeID.h"
namespace Serialization {
class IArchive;
struct LessStrCmp
{
bool operator()(const char* l, const char* r) const
{
return strcmp(l, r) < 0;
}
};
class CEnumDescription
{
public:
struct NameValue
{
NameValue* m_next;
const char* m_name;
const int m_value;
const char* m_label;
NameValue(CEnumDescription& desc, const char* name, int value, const char* label="")
: m_next(desc.m_regListHead)
, m_name(name)
, m_value(value)
, m_label(label)
{
desc.m_regListHead = this;
}
};
NameValue* m_regListHead = nullptr;
CEnumDescription(const Serialization::TypeID& type)
: type_(type) {}
inline int value(const char* name) const;
inline int valueByIndex(int index) const;
inline int valueByLabel(const char* label) const;
inline const char* name(int value) const;
inline const char* nameByIndex(int index) const;
inline const char* labelByIndex(int index) const;
inline const char* label(int value) const;
inline const char* indexByName(const char* name) const;
inline int indexByValue(int value) const;
inline bool Serialize(IArchive& ar, int& value, const char* name, const char* label) const;
inline bool serializeBitVector(IArchive& ar, int& value, const char* name, const char* label) const;
void add(int value, const char* name, const char* label = "");
int count() const{ return int(values_.size()); }
const StringListStatic& names() const{ return names_; }
const StringListStatic& labels() const{ return labels_; }
inline StringListStatic nameCombination(int bitVector) const;
inline StringListStatic labelCombination(int bitVector) const;
bool registered() const { return !names_.empty(); }
TypeID type() const{ return type_; }
private:
void lazyRegister() const;
StringListStatic names_;
StringListStatic labels_;
typedef AZStd::unordered_map<AZStd::string_view, int, AZStd::hash<AZStd::string_view>, AZStd::equal_to<AZStd::string_view>, AZ::StdLegacyAllocator> NameToValue;
NameToValue nameToValue_;
typedef AZStd::unordered_map<AZStd::string_view, int, AZStd::hash<AZStd::string_view>, AZStd::equal_to<AZStd::string_view>, AZ::StdLegacyAllocator> LabelToValue;
LabelToValue labelToValue_;
typedef AZStd::unordered_map<int, int, AZStd::hash<int>, AZStd::equal_to<int>, AZ::StdLegacyAllocator> ValueToIndex;
ValueToIndex valueToIndex_;
typedef AZStd::unordered_map<int, const char*, AZStd::hash<int>, AZStd::equal_to<int>, AZ::StdLegacyAllocator> ValueToName;
ValueToName valueToName_;
typedef AZStd::unordered_map<int, const char*, AZStd::hash<int>, AZStd::equal_to<int>, AZ::StdLegacyAllocator> ValueToLabel;
ValueToName valueToLabel_;
AZStd::vector<int, AZ::StdLegacyAllocator> values_;
TypeID type_;
};
template<class Enum>
class EnumDescriptionImpl
: public CEnumDescription
{
EnumDescriptionImpl()
: CEnumDescription(Serialization::TypeID::get<Enum>()) {}
public:
static CEnumDescription& the()
{
static EnumDescriptionImpl description;
return description;
}
};
template<class Enum>
CEnumDescription& getEnumDescription()
{
return EnumDescriptionImpl<Enum>::the();
}
inline bool serializeEnum(const CEnumDescription& desc, IArchive& ar, int& value, const char* name, const char* label)
{
return desc.Serialize(ar, value, name, label);
}
}
#define SERIALIZATION_ENUM_BEGIN(Type, label) \
namespace { \
bool registerEnum_##Type(); \
bool Type##_enum_registered = registerEnum_##Type(); \
bool registerEnum_##Type(){ \
Serialization::CEnumDescription& description = Serialization::EnumDescriptionImpl<Type>::the();
#define SERIALIZATION_ENUM_BEGIN_NESTED(Class, Enum, label) \
namespace { \
bool registerEnum_##Class##_##Enum(); \
bool Class##_##Enum##_enum_registered = registerEnum_##Class##_##Enum(); \
bool registerEnum_##Class##_##Enum(){ \
Serialization::CEnumDescription& description = Serialization::EnumDescriptionImpl<Class::Enum>::the();
#define SERIALIZATION_ENUM_BEGIN_NESTED2(Class, Class1, Enum, label) \
namespace { \
bool registerEnum_##Class##Class1##_##Enum(); \
bool Class##Class1##_##Enum##_enum_registered = registerEnum_##Class##Class1##_##Enum(); \
bool registerEnum_##Class##Class1##_##Enum(){ \
Serialization::CEnumDescription& description = Serialization::EnumDescriptionImpl<Class::Class1::Enum>::the();
#define SERIALIZATION_ENUM_VALUE(value, label) \
static Serialization::CEnumDescription::NameValue AZ_JOIN(enumValue, __LINE__)(description, label, (int)value);
#define SERIALIZATION_ENUM(value, name, label) \
static Serialization::CEnumDescription::NameValue AZ_JOIN(enumValue, __LINE__)(description, name, (int)value, label);
#define SERIALIZATION_ENUM_VALUE_NESTED(Class, value, label) \
static Serialization::CEnumDescription::NameValue AZ_JOIN(enumValue, __LINE__)(description, #value, (int)Class::value, label);
#define SERIALIZATION_ENUM_VALUE_NESTED2(Class, Class1, value, label) \
static Serialization::CEnumDescription::NameValue AZ_JOIN(enumValue, __LINE__)(description, #value, (int)Class::Class1::value, label);
#define SERIALIZATION_ENUM_END() \
return true; \
}; \
};
#include "EnumImpl.h"
// vim:ts=4 sw=4:
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_ENUM_H
@@ -0,0 +1,248 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_ENUMIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_ENUMIMPL_H
#pragma once
#pragma once
#include "IArchive.h"
#include "STL.h"
#include "Enum.h"
#include "StringList.h"
#ifndef SERIALIZATION_STANDALONE
#include <ISystem.h>
#endif
namespace Serialization {
inline void CEnumDescription::add(int value, const char* name, const char* label)
{
YASLI_ESCAPE(name && label, return );
// Filter for dupes in case enum description included in a shared header
NameToValue::iterator nameIt = nameToValue_.find(name);
if (nameIt != nameToValue_.end() && nameIt->second == value)
{ LabelToValue::iterator labelIt = labelToValue_.find(label);
if (labelIt != labelToValue_.end() && labelIt->second == value)
{
return;
}
}
nameToValue_[name] = value;
labelToValue_[label] = value;
valueToName_[value] = name;
valueToLabel_[value] = label;
valueToIndex_[value] = int(names_.size());
names_.push_back(name);
labels_.push_back(label);
values_.push_back(value);
}
inline bool CEnumDescription::Serialize(IArchive& ar, int& value, const char* name, const char* label) const
{
lazyRegister();
if (!ar.IsInPlace())
{
if (count() == 0)
{
#ifdef SERIALIZATION_STANDALONE
assert(0 && "Attempt to serialize enum type that is not registered with SERIALIZATION_ENUM macro");
#else
CryFatalError("Attempt to serialize enum type that is not registered with SERIALIZATION_ENUM macro: %s", type().name());
#endif
return false;
}
int index = StringListStatic::npos;
if (ar.IsOutput())
{
index = indexByValue(value);
}
StringListStaticValue stringListValue(ar.IsEdit() ? labels() : names(), index, &value, type());
ar(stringListValue, name, label);
if (ar.IsInput())
{
if (stringListValue.index() == StringListStatic::npos)
{
return false;
}
value = ar.IsEdit() ? valueByLabel(stringListValue.c_str()) : this->value(stringListValue.c_str());
}
else if (index == StringListStatic::npos)
{
ar.Error(&value, type(), "Unregistered or uninitialized enumeration value.");
}
}
else
{
return ar(value, name, label);
}
return true;
}
inline bool CEnumDescription::serializeBitVector(IArchive& ar, int& value, const char* name, const char* label) const
{
lazyRegister();
if (ar.IsOutput())
{
StringListStatic names = nameCombination(value);
string str;
joinStringList(&str, names, '|');
return ar(str, name, label);
}
else
{
string str;
if (!ar(str, name, label))
{
return false;
}
StringList values;
splitStringList(&values, str.c_str(), '|');
StringList::iterator it;
value = 0;
for (it = values.begin(); it != values.end(); ++it)
{
if (!it->empty())
{
value |= this->value(it->c_str());
}
}
return true;
}
}
inline const char* CEnumDescription::name(int value) const
{
lazyRegister();
ValueToName::const_iterator it = valueToName_.find(value);
YASLI_ESCAPE(it != valueToName_.end(), return "");
return it->second;
}
inline const char* CEnumDescription::label(int value) const
{
lazyRegister();
ValueToLabel::const_iterator it = valueToLabel_.find(value);
YASLI_ESCAPE(it != valueToLabel_.end(), return "");
return it->second;
}
inline StringListStatic CEnumDescription::nameCombination(int bitVector) const
{
lazyRegister();
StringListStatic strings;
for (ValueToName::const_iterator i = valueToName_.begin(); i != valueToName_.end(); ++i)
{
if ((bitVector & i->first) == i->first)
{
bitVector &= ~i->first;
strings.push_back(i->second);
}
}
YASLI_ASSERT(!bitVector && "Unregistered enum value");
return strings;
}
inline StringListStatic CEnumDescription::labelCombination(int bitVector) const
{
lazyRegister();
StringListStatic strings;
for (ValueToLabel::const_iterator i = valueToLabel_.begin(); i != valueToLabel_.end(); ++i)
{
if (i->second && (bitVector & i->first) == i->first)
{
bitVector &= ~i->first;
strings.push_back(i->second);
}
}
YASLI_ASSERT(!bitVector && "Unregistered enum value");
return strings;
}
inline int CEnumDescription::indexByValue(int value) const
{
lazyRegister();
ValueToIndex::const_iterator it = valueToIndex_.find(value);
if (it == valueToIndex_.end())
{
return -1;
}
else
{
return it->second;
}
}
inline int CEnumDescription::valueByIndex(int index) const
{
lazyRegister();
if (size_t(index) < values_.size())
{
return values_[index];
}
return 0;
}
inline const char* CEnumDescription::nameByIndex(int index) const
{
lazyRegister();
if (size_t(index) < size_t(names_.size()))
{
return names_[size_t(index)];
}
return 0;
}
inline const char* CEnumDescription::labelByIndex(int index) const
{
lazyRegister();
if (size_t(index) < size_t(labels_.size()))
{
return labels_[size_t(index)];
}
return 0;
}
inline int CEnumDescription::value(const char* name) const
{
lazyRegister();
NameToValue::const_iterator it = nameToValue_.find(name);
YASLI_ESCAPE(it != nameToValue_.end(), return 0);
return it->second;
}
inline int CEnumDescription::valueByLabel(const char* label) const
{
lazyRegister();
LabelToValue::const_iterator it = labelToValue_.find(label);
YASLI_ESCAPE(it != labelToValue_.end(), return 0);
return it->second;
}
inline void CEnumDescription::lazyRegister() const
{
if (m_regListHead)
{
NameValue* val = m_regListHead;
while (val)
{
const_cast<CEnumDescription*>(this)->add(val->m_value, val->m_name, val->m_label);
val = val->m_next;
}
const_cast<CEnumDescription*>(this)->m_regListHead = nullptr;
}
}
}
// vim:ts=4 sw=4:
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_ENUMIMPL_H
@@ -0,0 +1,446 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_IARCHIVE_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_IARCHIVE_H
#pragma once
#include <stdarg.h>
#include <map>
#include "Serializer.h"
#include "KeyValue.h"
#include "TypeID.h"
namespace Serialization {
class IArchive;
template<class T>
bool Serialize(Serialization::IArchive& ar, T& object, const char* name, const char* label);
class CEnumDescription;
template <class Enum>
CEnumDescription& getEnumDescription();
bool serializeEnum(const CEnumDescription& desc, IArchive& ar, int& value, const char* name, const char* label);
// SContextLink should not be used directly. See SContext<> below.
struct SContextLink
{
SContextLink* outer;
TypeID type;
void* contextObject;
SContextLink()
: outer()
, contextObject()
{
}
};
struct SBlackBox;
struct ICallback;
class IArchive
{
public:
enum ArchiveCaps
{
INPUT = 1 << 0,
OUTPUT = 1 << 1,
TEXT = 1 << 2,
BINARY = 1 << 3,
EDIT = 1 << 4,
INPLACE = 1 << 5,
NO_EMPTY_NAMES = 1 << 6,
VALIDATION = 1 << 7,
DOCUMENTATION = 1 << 8
};
IArchive(int caps)
: caps_(caps)
, filter_(0)
, innerContext_(0)
{
}
virtual ~IArchive() {}
bool IsInput() const{ return caps_ & INPUT ? true : false; }
bool IsOutput() const{ return caps_ & OUTPUT ? true : false; }
bool IsEdit() const
{
#if !defined(CONSOLE) && !defined(RELEASE)
return (caps_ & EDIT) != 0;
#else
return false;
#endif
}
bool IsInPlace() const{ return caps_ & INPLACE ? true : false; }
bool GetCaps(int caps) const { return (caps_ & caps) == caps; }
void SetFilter(int filter)
{
filter_ = filter;
}
int GetFilter() const{ return filter_; }
bool Filter(int flags) const
{
YASLI_ASSERT(flags != 0 && "flags is supposed to be a bit mask");
YASLI_ASSERT(filter_ && "Filter is not set!");
return (filter_ & flags) != 0;
}
virtual bool operator()([[maybe_unused]] bool& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] char& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] uint8& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] int8& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] int16& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] uint16& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] int32& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] uint32& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] int64& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] uint64& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] float& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] double& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] IString& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] IWString& value, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] const SStruct& ser, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { notImplemented(); return false; }
virtual bool operator()([[maybe_unused]] IContainer& ser, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { return false; }
virtual bool operator()(IPointer& ptr, const char* name = "", const char* label = 0);
virtual bool operator()(IKeyValue& keyValue, const char* name = "", const char* label = 0) { return operator()(SStruct(keyValue), name, label); }
virtual bool operator()([[maybe_unused]] const SBlackBox& blackBox, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { return false; }
virtual bool operator()([[maybe_unused]] ICallback& callback, [[maybe_unused]] const char* name = "", [[maybe_unused]] const char* label = 0) { return false; }
template<class T>
bool operator()(const T& value, const char* name = "", const char* label = 0);
// Error and Warning calls are used for diagnostics and validation of the
// values. Output depends on the specific implementation of IArchive,
// for example PropertyTree uses it to show bubbles with errors in UI
// next to the mentioned property.
template<class T>
void Error(T& value, const char* format, ...);
template<class T>
void Warning(T& value, const char* format, ...);
void Error(const void* value, const Serialization::TypeID& type, const char* format, ...);
// Used to add tooltips in PropertyTree
void Doc(const char* docString);
virtual bool OpenBlock([[maybe_unused]] const char* name, [[maybe_unused]] const char* label) { return true; }
virtual void CloseBlock() {}
// long, unsigned long and long double are intentionally omitted
template<class T>
T* FindContext() const { return (T*)FindContextByType(TypeID::get<T>()); }
void* FindContextByType(const TypeID& type) const
{
SContextLink* context = innerContext_;
while (context)
{
if (context->type == type)
{
return context->contextObject;
}
context = context->outer;
}
return 0;
}
SContextLink* SetInnerContext(SContextLink* context)
{
SContextLink* result = innerContext_;
innerContext_ = context;
return result;
}
SContextLink* GetInnerContext() const{ return innerContext_; }
protected:
virtual void ValidatorMessage([[maybe_unused]] bool error, [[maybe_unused]] const void* handle, [[maybe_unused]] const TypeID& type, [[maybe_unused]] const char* message) {}
virtual void DocumentLastField([[maybe_unused]] const char* text) {}
void notImplemented() { YASLI_ASSERT(0 && "Not implemented!"); }
int caps_;
int filter_;
SContextLink* innerContext_;
};
// IArchive::SContext can be used to establish access to outer objects in serialization stack.
//
// Example:
// void Scene::Serialize(...) {
// IArchive::SContext<Scene> context(ar, this);
// ar(rootNode, ...);
// }
//
// void Node::Serialize(...) {
// Scene* scene = ar.FindContext<Scene>();
// }
template<class T>
struct SContext
: SContextLink
{
SContext(IArchive& ar, T* context)
: ar_(&ar)
{
outer = ar_->SetInnerContext(this);
type = TypeID::get<T>();
contextObject = (void*)context;
}
SContext(T* context)
: ar_(0)
{
outer = 0;
type = TypeID::get<T>();
contextObject = (void*)context;
}
~SContext()
{
if (ar_)
{
ar_->SetInnerContext(outer);
}
}
private:
IArchive* ar_;
};
namespace detail {
template<bool C, class T1, class T2>
struct Selector{};
template<class T1, class T2>
struct Selector<false, T1, T2>
{
typedef T2 type;
};
template<class T1, class T2>
struct Selector<true, T1, T2>
{
typedef T1 type;
};
template<class C, class T1, class T2>
struct Select
{
typedef typename Selector<C::value, T1, T2>::type selected_type;
typedef typename selected_type::type type;
};
template<class T>
struct Identity
{
typedef T type;
};
template<class T>
struct IsArray
{
enum
{
value = false
};
};
template<class T, int Size>
struct IsArray< T[Size] >
{
enum
{
value = true
};
};
template<class T, int Size>
struct ArraySize
{
enum
{
value = true
};
};
template<class T>
struct SerializeStruct
{
static bool invoke(IArchive& ar, T& value, const char* name, const char* label)
{
SStruct ser(value);
return ar(ser, name, label);
};
};
template<class Enum>
struct SerializeEnum
{
static bool invoke(IArchive& ar, Enum& value, const char* name, const char* label)
{
const CEnumDescription& enumDescription = getEnumDescription<Enum>();
return serializeEnum(enumDescription, ar, reinterpret_cast<int&>(value), name, label);
};
};
template<class T>
struct SerializeArray{};
template<class T, int Size>
struct SerializeArray<T[Size]>
{
static bool invoke(IArchive& ar, T value[Size], const char* name, const char* label)
{
ContainerArray<T> ser(value, Size);
return ar(static_cast<IContainer&>(ser), name, label);
}
};
template<class T>
struct IsClass
{
private:
struct NoType
{
char dummy;
};
struct YesType
{
char dummy[100];
};
template<class U>
static YesType function_helper(void(U::*)(void));
template<class U>
static NoType function_helper(...);
public:
enum
{
value = (sizeof(function_helper<T>(0)) == sizeof(YesType))
};
};
}
template<class T>
bool IArchive::operator()(const T& value, const char* name, const char* label)
{
return Serialize(*this, const_cast<T&>(value), name, label);
}
inline bool IArchive::operator()(IPointer& ptr, const char* name, const char* label)
{
return (*this)(SStruct(const_cast<IPointer&>(ptr)), name, label);
}
inline void IArchive::Doc([[maybe_unused]] const char* docString)
{
#if !defined(CONSOLE) && !defined(RELEASE)
if (caps_ & DOCUMENTATION)
{
DocumentLastField(docString);
}
#endif
}
template<class T>
void IArchive::Error([[maybe_unused]] T& value, [[maybe_unused]] const char* format, ...)
{
#if !defined(CONSOLE) && !defined(RELEASE)
if ((caps_ & VALIDATION) == 0)
{
return;
}
va_list args;
va_start(args, format);
char buf[1024];
azvsnprintf(buf, sizeof(buf), format, args);
va_end(args);
ValidatorMessage(true, &value, TypeID::get<T>(), buf);
#endif
}
inline void IArchive::Error([[maybe_unused]] const void* handle, [[maybe_unused]] const Serialization::TypeID& type, [[maybe_unused]] const char* format, ...)
{
#if !defined(CONSOLE) && !defined(RELEASE)
if ((caps_ & VALIDATION) == 0)
{
return;
}
va_list args;
va_start(args, format);
char buf[1024];
azvsnprintf(buf, sizeof(buf), format, args);
va_end(args);
ValidatorMessage(true, handle, type, buf);
#endif
}
template<class T>
void IArchive::Warning([[maybe_unused]] T& value, [[maybe_unused]] const char* format, ...)
{
#if !defined(CONSOLE) && !defined(RELEASE)
if ((caps_ & VALIDATION) == 0)
{
return;
}
va_list args;
va_start(args, format);
char buf[1024];
azvsnprintf(buf, sizeof(buf), format, args);
va_end(args);
ValidatorMessage(false, &value, TypeID::get<T>(), buf);
#endif
}
template<class T, int Size>
bool Serialize(Serialization::IArchive& ar, T object[Size], const char* name, const char* label)
{
YASLI_ASSERT(0);
return false;
}
template<class T>
bool Serialize(Serialization::IArchive& ar, const T& object, const char* name, const char* label)
{
T::unable_to_serialize_CONST_object();
YASLI_ASSERT(0);
return false;
}
template<class T>
bool Serialize(Serialization::IArchive& ar, T& object, const char* name, const char* label)
{
using namespace Serialization::detail;
return
Select< IsClass<T>,
Identity< SerializeStruct<T> >,
Select< IsArray<T>,
Identity< SerializeArray<T> >,
Identity< SerializeEnum<T> >
>
>::type::invoke(ar, object, name, label);
}
}
#include "Serialization/SerializerImpl.h"
// vim: ts=4 sw=4:
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_IARCHIVE_H
@@ -0,0 +1,153 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#pragma once
// IArchiveHost serves a purpose of sharing IArchive implementations among
// diffferent modules.
//
// Example of usage:
//
// struct SType
// {
// void Serialize(Serialization::IArchive& ar);
// };
//
// SType instanceToSave;
// bool saved = Serialization::SaveJsonFile("Scripts/instance.json", instanceToSave);
//
// SType instanceToLoad;
// bool loaded = Serialization::LoadJsonFile(instanceToLoad, "Scripts/instance.json");
//
#include <CryArray.h>
#include <Serialization/Serializer.h>
namespace Serialization
{
struct IArchiveHost
{
virtual ~IArchiveHost() {}
virtual bool LoadJsonFile(const SStruct& outObj, const char* filename) = 0;
virtual bool SaveJsonFile(const char* filename, const SStruct& obj) = 0;
virtual bool LoadJsonBuffer(const SStruct& outObj, const char* buffer, size_t bufferLength) = 0;
virtual bool SaveJsonBuffer(DynArray<char>& outBuffer, const SStruct& obj) = 0;
virtual bool LoadBinaryFile(const SStruct& outObj, const char* filename) = 0;
virtual bool SaveBinaryFile(const char* filename, const SStruct& obj) = 0;
virtual bool LoadBinaryBuffer(const SStruct& outObj, const char* buffer, size_t bufferLength) = 0;
virtual bool SaveBinaryBuffer(DynArray<char>& outBuffer, const SStruct& obj) = 0;
virtual bool CloneBinary(const SStruct& dest, const SStruct& source) = 0;
// Compares two instances in serialized form through binary archive
virtual bool CompareBinary(const SStruct& lhs, const SStruct& rhs) = 0;
virtual bool LoadXmlFile(const SStruct& outObj, const char* filename) = 0;
virtual bool SaveXmlFile(const char* filename, const SStruct& obj, const char* rootNodeName) = 0;
virtual bool LoadXmlNode(const SStruct& outObj, const XmlNodeRef& node) = 0;
virtual XmlNodeRef SaveXmlNode(const SStruct& obj, const char* nodeName) = 0;
virtual bool SaveXmlNode(XmlNodeRef& node, const SStruct& obj) = 0;
};
// Syntactic sugar
template<class T>
bool LoadJsonFile(T& instance, const char* filename)
{
return gEnv->pSystem->GetArchiveHost()->LoadJsonFile(Serialization::SStruct(instance), filename);
}
template<class T>
bool SaveJsonFile(const char* filename, const T& instance)
{
return gEnv->pSystem->GetArchiveHost()->SaveJsonFile(filename, Serialization::SStruct(instance));
}
template<class T>
bool LoadJsonBuffer(T& instance, const char* buffer, size_t bufferLength)
{
return gEnv->pSystem->GetArchiveHost()->LoadJsonBuffer(Serialization::SStruct(instance), buffer, bufferLength);
}
template<class T>
bool SaveJsonBuffer(DynArray<char>& outBuffer, const T& instance)
{
return gEnv->pSystem->GetArchiveHost()->SaveJsonBuffer(outBuffer, Serialization::SStruct(instance));
}
// ---------------------------------------------------------------------------
template<class T>
bool LoadBinaryFile(T& outInstance, const char* filename)
{
return gEnv->pSystem->GetArchiveHost()->LoadBinaryFile(Serialization::SStruct(outInstance), filename);
}
template<class T>
bool SaveBinaryFile(const char* filename, const T& instance)
{
return gEnv->pSystem->GetArchiveHost()->SaveBinaryFile(filename, Serialization::SStruct(instance));
}
template<class T>
bool LoadBinaryBuffer(T& outInstance, const char* buffer, size_t bufferLength)
{
return gEnv->pSystem->GetArchiveHost()->LoadBinaryBuffer(Serialization::SStruct(outInstance), buffer, bufferLength);
}
template<class T>
bool SaveBinaryBuffer(DynArray<char>& outBuffer, const T& instance)
{
return gEnv->pSystem->GetArchiveHost()->SaveBinaryBuffer(outBuffer, Serialization::SStruct(instance));
}
template<class T>
bool CloneBinary(T& outInstance, const T& inInstance)
{
return gEnv->pSystem->GetArchiveHost()->CloneBinary(Serialization::SStruct(outInstance), Serialization::SStruct(inInstance));
}
template<class T>
bool CompareBinary(const T& lhs, const T& rhs)
{
return gEnv->pSystem->GetArchiveHost()->CompareBinary(Serialization::SStruct(lhs), Serialization::SStruct(rhs));
}
// ---------------------------------------------------------------------------
template<class T>
bool LoadXmlFile(T& outInstance, const char* filename)
{
return gEnv->pSystem->GetArchiveHost()->LoadXmlFile(Serialization::SStruct(outInstance), filename);
}
template<class T>
bool SaveXmlFile(const char* filename, const T& instance, const char* rootNodeName)
{
return gEnv->pSystem->GetArchiveHost()->SaveXmlFile(filename, Serialization::SStruct(instance), rootNodeName);
}
template<class T>
bool LoadXmlNode(T& outInstance, const XmlNodeRef& node)
{
return gEnv->pSystem->GetArchiveHost()->LoadXmlNode(Serialization::SStruct(outInstance), node);
}
template<class T>
XmlNodeRef SaveXmlNode(const T& instance, const char* nodeName)
{
return gEnv->pSystem->GetArchiveHost()->SaveXmlNode(Serialization::SStruct(instance), nodeName);
}
template<class T>
bool SaveXmlNode(XmlNodeRef& node, const T& instance)
{
return gEnv->pSystem->GetArchiveHost()->SaveXmlNode(node, Serialization::SStruct(instance));
}
}
@@ -0,0 +1,85 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_ICLASSFACTORY_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_ICLASSFACTORY_H
#pragma once
#include <map>
#include "Serialization/Assert.h"
#include "Serialization/TypeID.h"
namespace Serialization {
class IArchive;
class TypeDescription
{
public:
TypeDescription(const char* name, const char* label)
: name_(name)
, label_(label)
{
}
const char* name() const{ return name_; }
const char* label() const{ return label_; }
protected:
const char* name_;
const char* label_;
};
class IClassFactory
{
friend class ClassFactoryManager;
public:
IClassFactory(TypeID baseType)
: baseType_(baseType)
, nullLabel_(0)
{
}
virtual ~IClassFactory() { }
virtual size_t size() const = 0;
virtual const TypeDescription* descriptionByIndex(int index) const = 0;
virtual const TypeDescription* descriptionByRegisteredName(const char* typeName) const = 0;
virtual const char* findAnnotation(const char* registeredTypeName, const char* annotationName) const = 0;
virtual void serializeNewByIndex(IArchive& ar, int index, const char* name, const char* label) = 0;
bool setNullLabel(const char* label){ nullLabel_ = label ? label : ""; return true; }
const char* nullLabel() const{ return nullLabel_; }
protected:
TypeID baseType_;
const char* nullLabel_;
IClassFactory* m_next = nullptr;
};
struct TypeNameWithFactory
{
string registeredName;
IClassFactory* factory;
TypeNameWithFactory(const char* _registeredName, IClassFactory* _factory = 0)
: registeredName(_registeredName)
, factory(_factory)
{
}
};
bool Serialize(Serialization::IArchive& ar, Serialization::TypeNameWithFactory& value, const char* name, const char* label);
}
// vim:ts=4 sw=4:
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_ICLASSFACTORY_H
@@ -0,0 +1,46 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_ITEXTINPUTARCHIVE_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_ITEXTINPUTARCHIVE_H
#pragma once
#include "Serialization/IArchive.h"
#include "CryExtension/ICryUnknown.h"
#include "CryExtension/CryCreateClassInstance.h"
namespace Serialization {
class ITextInputArchive
: public ICryUnknown
, public IArchive
{
public:
CRYINTERFACE_DECLARE(ITextInputArchive, 0x1845738b1dcc4168, 0xb440dba776b460c9)
using IArchive::operator();
virtual bool LoadFileUsingCRT(const char* filename) = 0;
virtual bool AttachMemory(const char* buffer, size_t size) = 0;
protected:
ITextInputArchive(int caps)
: IArchive(caps) {}
};
inline AZStd::shared_ptr<ITextInputArchive> CreateTextInputArchive()
{
AZStd::shared_ptr<ITextInputArchive> pArchive;
CryCreateClassInstance(MAKE_CRYGUID(0x7a83a1c890054608, 0x9f8447a4b0ad6c3b), pArchive);
return pArchive;
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_ITEXTINPUTARCHIVE_H
@@ -0,0 +1,55 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_ITEXTOUTPUTARCHIVE_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_ITEXTOUTPUTARCHIVE_H
#pragma once
#include "Serialization/IArchive.h"
#include "CryExtension/ICryUnknown.h"
#include "CryExtension/CryCreateClassInstance.h"
namespace Serialization {
class ITextOutputArchive
: public ICryUnknown
, public IArchive
{
CRYINTERFACE_DECLARE(ITextOutputArchive, 0xa273d6157a8b4f0d, 0x80ad6c8031bbfbf3)
public:
virtual bool SaveFileUsingCRT(const char* filename) = 0;
// use precise but less readable way to write float/double types
virtual void SetExponentFloatRepresentation(bool) = 0;
// buffer is a null-terminated string
virtual const char* GetBuffer() const = 0;
virtual size_t GetBufferLength() const = 0;
// by default nested structres are put in one line, unless the line length is
// longer than 'textWidth'
virtual void SetTextWidth(int textWidth) = 0;
using IArchive::operator();
protected:
ITextOutputArchive(int caps)
: IArchive(caps) {}
};
inline AZStd::shared_ptr<ITextOutputArchive> CreateTextOutputArchive()
{
AZStd::shared_ptr<ITextOutputArchive> pArchive;
CryCreateClassInstance(MAKE_CRYGUID(0xd1f14adbc4e74e49, 0x9cea55d80a55cbdb), pArchive);
return pArchive;
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_ITEXTOUTPUTARCHIVE_H
@@ -0,0 +1,175 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_IXMLARCHIVE_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_IXMLARCHIVE_H
#pragma once
#include "Serialization/IArchive.h"
#include "CryExtension/ICryUnknown.h"
#include "CryExtension/CryCreateClassInstance.h"
namespace Serialization
{
struct IXmlArchive
: public ICryUnknown
, public IArchive
{
public:
CRYINTERFACE_DECLARE(IXmlArchive, 0x1386c94ded174f96, 0xab14d20e1b616588);
using IArchive::operator();
virtual void SetXmlNode(XmlNodeRef pRootNode) = 0;
virtual XmlNodeRef GetXmlNode() const = 0;
protected:
IXmlArchive(int caps)
: IArchive(caps | IArchive::NO_EMPTY_NAMES) {}
};
typedef AZStd::shared_ptr< IXmlArchive > IXmlArchivePtr;
inline IXmlArchivePtr CreateXmlInputArchive()
{
IXmlArchivePtr pArchive;
CryCreateClassInstance("CXmlIArchive", pArchive);
return pArchive;
}
inline IXmlArchivePtr CreateXmlInputArchive(XmlNodeRef pXmlNode)
{
if (pXmlNode)
{
IXmlArchivePtr pArchive = CreateXmlInputArchive();
if (pArchive)
{
pArchive->SetXmlNode(pXmlNode);
}
return pArchive;
}
return IXmlArchivePtr();
}
inline IXmlArchivePtr CreateXmlInputArchive(const char* const filename)
{
XmlNodeRef pXmlNode = gEnv->pSystem->LoadXmlFromFile(filename);
return CreateXmlInputArchive(pXmlNode);
}
inline IXmlArchivePtr CreateXmlOutputArchive()
{
IXmlArchivePtr pArchive;
CryCreateClassInstance("CXmlOArchive", pArchive);
return pArchive;
}
inline IXmlArchivePtr CreateXmlOutputArchive(XmlNodeRef pXmlNode)
{
if (pXmlNode)
{
IXmlArchivePtr pArchive = CreateXmlOutputArchive();
if (pArchive)
{
pArchive->SetXmlNode(pXmlNode);
}
return pArchive;
}
return IXmlArchivePtr();
}
inline IXmlArchivePtr CreateXmlOutputArchive(const char* const xmlRootElementName)
{
XmlNodeRef pXmlNode = gEnv->pSystem->CreateXmlNode(xmlRootElementName);
return CreateXmlOutputArchive(pXmlNode);
}
template< typename T >
bool StructFromXml(const char* const filename, T& dataOut)
{
Serialization::IXmlArchivePtr pXmlArchive = Serialization::CreateXmlInputArchive(filename);
if (pXmlArchive)
{
Serialization::SStruct serializer = Serialization::SStruct(dataOut);
const bool success = serializer(*pXmlArchive);
return success;
}
return false;
}
template< typename T >
bool StructFromXml(XmlNodeRef pXmlNode, T& dataOut)
{
Serialization::IXmlArchivePtr pXmlArchive = Serialization::CreateXmlInputArchive(pXmlNode);
if (pXmlArchive)
{
Serialization::SStruct serializer = Serialization::SStruct(dataOut);
const bool success = serializer(*pXmlArchive);
return success;
}
return false;
}
template< typename T >
XmlNodeRef StructToXml(const char* const xmlRootElementName, const T& dataIn)
{
Serialization::IXmlArchivePtr pXmlArchive = Serialization::CreateXmlOutputArchive(xmlRootElementName);
if (pXmlArchive)
{
Serialization::SStruct serializer = Serialization::SStruct(const_cast< T& >(dataIn));
const bool success = serializer(*pXmlArchive);
if (success)
{
return pXmlArchive->GetXmlNode();
}
}
return XmlNodeRef();
}
template< typename T >
bool StructToXml(XmlNodeRef pXmlNode, const T& dataIn)
{
Serialization::IXmlArchivePtr pXmlArchive = Serialization::CreateXmlOutputArchive(pXmlNode);
if (pXmlArchive)
{
Serialization::SStruct serializer = Serialization::SStruct(const_cast< T& >(dataIn));
const bool success = serializer(*pXmlArchive);
return success;
}
return false;
}
template< typename T >
bool StructToXml(const char* const filename, const char* const xmlRootElementName, const T& dataIn)
{
XmlNodeRef pXmlNode = Serialization::StructToXml(xmlRootElementName, dataIn);
if (pXmlNode)
{
return pXmlNode->saveToFile(filename);
}
return false;
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_IXMLARCHIVE_H
@@ -0,0 +1,99 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_INTRUSIVEFACTORY_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_INTRUSIVEFACTORY_H
#pragma once
#include <StlUtils.h>
template<class TBase>
class CIntrusiveFactory
{
private:
struct ICreator
{
virtual TBase* Create() const = 0;
};
public:
template<class TDerived>
struct SCreator
: ICreator
{
SCreator() { CIntrusiveFactory<TBase>::Instance().RegisterType<TDerived>(this); }
TBase* Create() const override { return new TDerived(); }
};
static CIntrusiveFactory& Instance() { static CIntrusiveFactory instance; return instance; }
TBase* Create(const char* keyType) const
{
TCreatorByType::const_iterator it = m_creators.find(keyType);
if (it == m_creators.end() || it->second == 0)
{
return 0;
}
else
{
return it->second->Create();
}
}
struct SSerializer
{
_smart_ptr<TBase>& pointer;
SSerializer(_smart_ptr<TBase>& pointer)
: pointer(pointer) {}
void Serialize(Serialization::IArchive& ar);
};
private:
template<class TDerived>
void RegisterType(ICreator* creator)
{
const char* type = TDerived::GetType();
m_creators[type] = creator;
}
typedef std::map<const char*, ICreator*, stl::less_strcmp<const char*> > TCreatorByType;
TCreatorByType m_creators;
};
template<class TBase>
void CIntrusiveFactory<TBase>::SSerializer::Serialize(Serialization::IArchive & ar)
{
string type = pointer.get() ? pointer->GetInstanceType() : "";
string oldType = type;
ar(type, "type", "Type");
if (ar.IsInput())
{
if (oldType != type)
{
pointer.reset(CIntrusiveFactory<TBase>::Instance().Create(type.c_str()));
}
}
if (pointer)
{
pointer->Serialize(ar);
}
}
#define REGISTER_IN_INTRUSIVE_FACTORY(BaseType, DerivedType) namespace { CIntrusiveFactory<BaseType>::SCreator<DerivedType> baseType##DerivedType##_Creator; }
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_INTRUSIVEFACTORY_H
@@ -0,0 +1,37 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_KEYVALUE_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_KEYVALUE_H
#pragma once
namespace Serialization {
class IArchive;
class IKeyValue
: IString
{
public:
virtual const char* get() const = 0;
virtual void set(const char* key) = 0;
virtual bool serializeValue(IArchive& ar, const char* name, const char* label) = 0;
template<class TArchive>
void Serialize(TArchive& ar)
{
ar(*(IString*)this, "", "^");
serializeValue(ar, "", "^");
}
};
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_KEYVALUE_H
@@ -0,0 +1,166 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// This header extends serialization to support common geometrical types.
// It allows serialization of mentioned below types simple passing them to archive.
// For example:
//
// #include <Serialization/Math.h>
// #include <Serialization/IArchive.h>
//
// Serialization::IArchive& ar;
//
// Vec3 v;
// ar(v, "v");
//
// QuatT q;
// ar(q, "q");
//
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATH_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATH_H
#pragma once
namespace Serialization {
class IArchive;
}
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct Vec2_tpl<T>& v, const char* name, const char* label);
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct Vec3_tpl<T>& v, const char* name, const char* label);
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct Vec4_tpl<T>& v, const char* name, const char* label);
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct Quat_tpl<T>& q, const char* name, const char* label);
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct QuatT_tpl<T>& qt, const char* name, const char* label);
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct Ang3_tpl<T>& a, const char* name, const char* label);
template<class T>
bool Serialize(Serialization::IArchive& ar, struct Matrix34_tpl<T>& value, const char* name, const char* label);
bool Serialize(Serialization::IArchive& ar, struct AABB& aabb, const char* name, const char* label);
// ---------------------------------------------------------------------------
// RadiansAsDeg allows to present radian values as degrees to the user in the
// editor.
//
// Example:
// ...
// float radians;
// ar(RadiansAsDeg(radians), "degrees", "Degrees");
//
// Ang3 euler;
// ar(RadiansAsDeg(euler), "eulerDegrees", "Euler Degrees");
//
namespace Serialization
{
template<class T>
struct SRadianAng3AsDeg
{
Ang3_tpl<T>* ang3;
SRadianAng3AsDeg(Ang3_tpl<T>* _ang3)
: ang3(_ang3) {}
};
template<class T>
SRadianAng3AsDeg<T> RadiansAsDeg(Ang3_tpl<T>& radians)
{
return SRadianAng3AsDeg<T>(&radians);
}
template<class T>
struct SRadiansAsDeg
{
T* radians;
SRadiansAsDeg(T* _radians)
: radians(_radians) {}
};
template<class T>
SRadiansAsDeg<T> RadiansAsDeg(T& radians)
{
return SRadiansAsDeg<T>(&radians);
}
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::SRadiansAsDeg<T>& value, const char* name, const char* label);
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::SRadianAng3AsDeg<T>& value, const char* name, const char* label);
// ---------------------------------------------------------------------------
// QuatAsAng3 provides a wrapper that allows editing of quaternions as Ang3 (in degrees).
//
// Example:
// ...
// Quat q;
// ar(QuatAsAng3(q), "orientation", "Orientation");
//
template<class T>
struct QuatAsAng3
{
Quat_tpl<T>* quat;
QuatAsAng3(Quat_tpl<T>& _quat)
: quat(&_quat) {}
};
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::QuatAsAng3<T>& value, const char* name, const char* label);
// ---------------------------------------------------------------------------
// QuatTAsVec3Ang3 provides a wrapper that allows editing of transforms as Vec3 and Ang3 (in degrees).
//
// Example:
// ...
// QuatT trans;
// ar(QuatTAsVec3Ang3(trans), "transform", "Transform");
//
template<class T>
struct QuatTAsVec3Ang3
{
QuatT_tpl<T>* trans;
QuatTAsVec3Ang3(QuatT_tpl<T>& _trans)
: trans(&_trans) {}
};
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::QuatTAsVec3Ang3<T>& value, const char* name, const char* label);
// ---------------------------------------------------------------------------
// Helper functions for Ang3
//
// Example:
// ...
// Quat q;
// QuatT trans;
// ar(AsAng3(q),"orientation","Orientation");
// ar(AsAnge(trans),"transform", "Transform");
//
template<class T>
inline QuatAsAng3<T> AsAng3(Quat_tpl<T>& q){ return QuatAsAng3<T>(q); }
template<class T>
inline QuatTAsVec3Ang3<T> AsAng3(QuatT_tpl<T>& trans){ return QuatTAsVec3Ang3<T>(trans); }
}
#include "MathImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATH_H
@@ -0,0 +1,207 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATHIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATHIMPL_H
#pragma once
#include "Serialization/IArchive.h"
#include "Cry_Vector2.h"
#include "Cry_Vector3.h"
#include "Cry_Vector4.h"
#include "Cry_Quat.h"
#include "Cry_Matrix34.h"
#include "Cry_Geo.h"
template<typename T>
bool Serialize(Serialization::IArchive& ar, Vec2_tpl<T>& value, const char* name, const char* label)
{
typedef T (& Array)[2];
return ar((Array)value, name, label);
}
template<typename T>
bool Serialize(Serialization::IArchive& ar, Vec3_tpl<T>& value, const char* name, const char* label)
{
typedef T (& Array)[3];
return ar((Array)value, name, label);
}
template<typename T>
inline bool Serialize(Serialization::IArchive& ar, struct Vec4_tpl<T>& v, const char* name, const char* label)
{
typedef T (& Array)[4];
return ar((Array)v, name, label);
}
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct Quat_tpl<T>& value, const char* name, const char* label)
{
typedef T (& Array)[4];
return ar((Array)value, name, label);
}
template<typename T>
struct SerializableQuatT
: QuatT_tpl<T>
{
void Serialize(Serialization::IArchive& ar)
{
ar(this->q, "q", "Quaternion");
ar(this->t, "t", "Translation");
}
};
template<typename T>
bool Serialize(Serialization::IArchive& ar, struct QuatT_tpl<T>& value, const char* name, const char* label)
{
return Serialize(ar, static_cast<SerializableQuatT<T>&>(value), name, label);
}
struct SerializableAABB
: AABB
{
void Serialize(Serialization::IArchive& ar)
{
ar(this->min, "min", "Min");
ar(this->max, "max", "Max");
}
};
inline bool Serialize(Serialization::IArchive& ar, struct AABB& value, const char* name, const char* label)
{
return Serialize(ar, static_cast<SerializableAABB&>(value), name, label);
}
template<typename T>
bool Serialize(Serialization::IArchive& ar, Matrix34_tpl<T>& value, const char* name, const char* label)
{
typedef T (& Array)[3][4];
return ar((Array)value, name, label);
}
//////////////////////////////////////////////////////////////////////////
namespace Serialization
{
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::SRadiansAsDeg<T>& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
float degrees = RAD2DEG(*value.radians);
float oldDegrees = degrees;
if (!ar(degrees, name, label))
{
return false;
}
if (oldDegrees != degrees)
{
*value.radians = DEG2RAD(degrees);
}
return true;
}
else
{
return ar(*value.radians, name, label);
}
}
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::SRadianAng3AsDeg<T>& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
Ang3 degrees(RAD2DEG(value.ang3->x), RAD2DEG(value.ang3->y), RAD2DEG(value.ang3->z));
Ang3 oldDegrees = degrees;
if (!ar(degrees, name, label))
{
return false;
}
if (oldDegrees != degrees)
{
*value.ang3 = Ang3(DEG2RAD(degrees.x), DEG2RAD(degrees.y), DEG2RAD(degrees.z));
}
return true;
}
else
{
return ar(*value.ang3, name, label);
}
}
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
bool Serialize(Serialization::IArchive& ar, Ang3_tpl<T>& value, const char* name, const char* label)
{
typedef T (& Array)[3];
return ar((Array)value, name, label);
}
//////////////////////////////////////////////////////////////////////////
namespace Serialization
{
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::QuatAsAng3<T>& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
Ang3 ang3(*value.quat);
Ang3 oldAng3 = ang3;
if (!ar(Serialization::RadiansAsDeg(ang3), name, label))
{
return false;
}
if (ang3 != oldAng3)
{
*value.quat = Quat(ang3);
}
return true;
}
else
{
return ar(*value.quat, name, label);
}
}
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::QuatTAsVec3Ang3<T>& value, const char* name, const char* label)
{
if (ar.IsEdit())
{
if (!ar.OpenBlock(name, label))
{
return false;
}
ar(QuatAsAng3<T>((value.trans)->q), "rot", "Rotation");
ar.Doc("Euler Angles in degrees");
ar((value.trans)->t, "t", "Translation");
ar.CloseBlock();
return true;
}
else
{
return ar(*(value.trans), name, label);
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_MATHIMPL_H
@@ -0,0 +1,27 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#ifndef CRYINCLUDE_CRYCOMMON_CRYSCRIPTSYSTEM_NETSCRIPTSERIALIZE_H
#define CRYINCLUDE_CRYCOMMON_CRYSCRIPTSYSTEM_NETSCRIPTSERIALIZE_H
namespace Serialization
{
class INetScriptMarshaler
{
public:
virtual TSerialize FindSerializer(const char* name) = 0;
virtual bool CommitSerializer(const char* name, TSerialize serializer) = 0;
virtual int GetMaxServerProperties() const = 0;
};
}
#endif
@@ -0,0 +1,153 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_OBJECT_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_OBJECT_H
#pragma once
#include "Serializer.h"
// ---------------------------------------------------------------------------
namespace Serialization {
typedef int(* AddRefFunc)(void*);
typedef int(* DecRefFunc)(void*);
// represents a reference to the persistent object
class Object
{
public:
Object()
: address_(0)
, addRefFunc_(0)
, decRefFunc_(0)
, serializeFunc_(0)
{
}
Object(const Object& o)
: address_(o.address_)
, type_(o.type_)
, addRefFunc_(o.addRefFunc_)
, decRefFunc_(o.decRefFunc_)
, serializeFunc_(o.serializeFunc_)
{
addRef();
}
Object(const SStruct& ser)
: address_(ser.pointer())
, type_(ser.type())
, addRefFunc_(0)
, decRefFunc_(0)
, serializeFunc_(ser.serializeFunc())
{
}
Object(void* address, const TypeID& type, AddRefFunc addRefFunc, DecRefFunc decRefFunc, SerializeStructFunc serializeFunc)
: address_(address)
, type_(type)
, addRefFunc_(addRefFunc)
, decRefFunc_(decRefFunc)
, serializeFunc_(serializeFunc)
{
addRef();
}
~Object()
{
if (address_)
{
decRef();
address_ = 0;
}
}
void* address() const{ return address_; }
const TypeID& type() const{ return type_; }
bool isSet() { return serializeFunc_ != 0; }
int addRef()
{
if (!addRefFunc_)
{
return 1;
}
if (!address_)
{
return -1;
}
return addRefFunc_(address_);
}
int decRef()
{
if (!decRefFunc_)
{
return 1;
}
if (!address_)
{
return -1;
}
return decRefFunc_(address_);
}
bool operator()(IArchive& ar) const
{
if (!serializeFunc_ || !address_)
{
return false;
}
return serializeFunc_(address_, ar);
}
SStruct serializer() const
{
return SStruct(type_, address_, 0, serializeFunc_);
}
Object& operator=(const Object& o)
{
if (this == &o)
{
return *this;
}
if (address_)
{
decRef();
}
address_ = o.address_;
type_ = o.type_;
addRefFunc_ = o.addRefFunc_;
decRefFunc_ = o.decRefFunc_;
serializeFunc_ = o.serializeFunc_;
addRef();
return *this;
}
private:
void* address_;
TypeID type_;
AddRefFunc addRefFunc_;
DecRefFunc decRefFunc_;
SerializeStructFunc serializeFunc_;
};
}
// ---------------------------------------------------------------------------
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_OBJECT_H
@@ -0,0 +1,52 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_STL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_STL_H
#pragma once
#include <vector>
#include <list>
#include <map>
#include "Serialization/Serializer.h"
namespace Serialization {
class IArchive;
}
namespace std
{
template<class K, class V, class Alloc>
bool Serialize(Serialization::IArchive& ar, std::pair<K, V>& pair, const char* name, const char* label);
template<class T, class Alloc>
bool Serialize(Serialization::IArchive& ar, std::vector<T, Alloc>& container, const char* name, const char* label);
template<class T, class Alloc>
bool Serialize(Serialization::IArchive& ar, std::list<T, Alloc>& container, const char* name, const char* label);
template<class K, class V, class C, class Alloc>
bool Serialize(Serialization::IArchive& ar, std::map<K, V, C, Alloc>& container, const char* name, const char* label);
}
namespace Serialization
{
bool Serialize(Serialization::IArchive& ar, Serialization::string& value, const char* name, const char* label);
bool Serialize(Serialization::IArchive& ar, Serialization::wstring& value, const char* name, const char* label);
}
#include "STLImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_STL_H
@@ -0,0 +1,251 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_STLIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_STLIMPL_H
#pragma once
#include "Serialization/IArchive.h"
#include "Serialization/Serializer.h"
namespace Serialization {
template<class Container, class Element>
class ContainerSTL
: public IContainer /*{{{*/
{
public:
explicit ContainerSTL(Container* container = 0)
: container_(container)
, it_(container->begin())
, size_(container->size())
{
YASLI_ASSERT(container_ != 0);
}
template<class T, class A>
void resizeHelper(size_t _size, std::vector<T, A>* _v) const
{
_v->resize(_size);
}
void resizeHelper(size_t _size, ...) const
{
while (size_t(container_->size()) > _size)
{
typename Container::iterator it = container_->end();
--it;
container_->erase(it);
}
while (size_t(container_->size()) < _size)
{
container_->insert(container_->end(), Element());
}
}
// from ContainerSerializationInterface
size_t size() const
{
YASLI_ESCAPE(container_ != 0, return 0);
return container_->size();
}
size_t resize(size_t size)
{
YASLI_ESCAPE(container_ != 0, return 0);
resizeHelper(size, container_);
it_ = container_->begin();
size_ = size;
return size;
}
void* pointer() const{ return reinterpret_cast<void*>(container_); }
TypeID elementType() const{ return TypeID::get<Element>(); }
TypeID containerType() const{ return TypeID::get<Container>(); }
bool next()
{
YASLI_ESCAPE(container_ && it_ != container_->end(), return false);
++it_;
return it_ != container_->end();
}
void* elementPointer() const { return &*it_; }
size_t elementSize() const { return sizeof(typename Container::value_type); }
bool operator()(IArchive& ar, const char* name, const char* label)
{
YASLI_ESCAPE(container_, return false);
if (it_ == container_->end())
{
it_ = container_->insert(container_->end(), Element());
return ar(*it_, name, label);
}
else
{
return ar(*it_, name, label);
}
}
operator bool() const{
return container_ != 0;
}
void serializeNewElement(IArchive& ar, const char* name = "", const char* label = 0) const
{
Element element;
ar(element, name, label);
}
// ^^^
protected:
Container* container_;
typename Container::iterator it_;
size_t size_;
};/*}}}*/
}
namespace std
{
template<class T, class Alloc>
bool Serialize(Serialization::IArchive& ar, std::vector<T, Alloc>& container, const char* name, const char* label)
{
Serialization::ContainerSTL<std::vector<T, Alloc>, T> ser(&container);
return ar(static_cast<Serialization::IContainer&>(ser), name, label);
}
template<class T, class Alloc>
bool Serialize(Serialization::IArchive& ar, std::list<T, Alloc>& container, const char* name, const char* label)
{
Serialization::ContainerSTL<std::list<T, Alloc>, T> ser(&container);
return ar(static_cast<Serialization::IContainer&>(ser), name, label);
}
template<class K, class V, class C, class Alloc>
bool Serialize(Serialization::IArchive& ar, std::map<K, V, C, Alloc>& container, const char* name, const char* label)
{
std::vector<std::pair<K, V> > temp;
if (ar.IsOutput())
{
temp.assign(container.begin(), container.end());
}
if (!ar(temp, name, label))
{
return false;
}
if (ar.IsInput())
{
container.clear();
container.insert(temp.begin(), temp.end());
}
return true;
}
}
// ---------------------------------------------------------------------------
namespace Serialization {
class StringSTL
: public IString
{
public:
StringSTL(string& str)
: str_(str) { }
void set(const char* value) { str_ = value; }
const char* get() const { return str_.c_str(); }
const void* handle() const { return &str_; }
TypeID type() const { return TypeID::get<string>(); }
private:
string& str_;
};
inline bool Serialize(Serialization::IArchive& ar, Serialization::string& value, const char* name, const char* label)
{
Serialization::StringSTL str(value);
return ar(static_cast<Serialization::IString&>(str), name, label);
}
// ---------------------------------------------------------------------------
class WStringSTL
: public IWString
{
public:
WStringSTL(Serialization::wstring& str)
: str_(str) { }
void set(const wchar_t* value) { str_ = value; }
const wchar_t* get() const { return str_.c_str(); }
const void* handle() const { return &str_; }
TypeID type() const { return TypeID::get<wstring>(); }
private:
wstring& str_;
};
inline bool Serialize(Serialization::IArchive& ar, Serialization::wstring& value, const char* name, const char* label)
{
Serialization::WStringSTL str(value);
return ar(static_cast<Serialization::IWString&>(str), name, label);
}
// ---------------------------------------------------------------------------
template <class K, class V>
struct StdPair
{
StdPair(std::pair<K, V>& pair)
: pair_(pair) {}
void Serialize(Serialization::IArchive& ar)
{
ar(pair_.first, "key", "Key");
ar(pair_.second, "value", "Value");
}
std::pair<K, V>& pair_;
};
template<class V>
struct StdStringPair
: Serialization::IKeyValue
{
const char* get() const { return pair_.first.c_str(); }
void set(const char* key) { pair_.first.assign(key); }
const void* handle() const { return &pair_; }
Serialization::TypeID type() const { return Serialization::TypeID::get<string>(); }
bool serializeValue(Serialization::IArchive& ar, const char* name, const char* label)
{
return ar(pair_.second, name, label);
}
StdStringPair(std::pair<string, V>& pair)
: pair_(pair)
{
}
std::pair<string, V>& pair_;
};
}
namespace std
{
template<class K, class V>
bool Serialize(Serialization::IArchive& ar, std::pair<K, V>& pair, const char* name, const char* label)
{
Serialization::StdPair<K, V> keyValue(pair);
return ar(keyValue, name, label);
}
template<class V>
bool Serialize(Serialization::IArchive& ar, std::pair<string, V>& pair, const char* name, const char* label)
{
Serialization::StdStringPair<V> keyValue(pair);
return ar(static_cast<Serialization::IKeyValue&>(keyValue), name, label);
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_STLIMPL_H
@@ -0,0 +1,268 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_SERIALIZER_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_SERIALIZER_H
#pragma once
#include <vector>
#include "Assert.h"
#include "TypeID.h"
namespace Serialization {
class IArchive;
class IClassFactory;
typedef bool(* SerializeStructFunc)(void*, IArchive&);
typedef bool(* SerializeContainerFunc)(void*, IArchive&, size_t index);
typedef size_t(* ContainerResizeFunc)(void*, size_t size);
typedef size_t(* ContainerSizeFunc)(void*);
// Struct serializer.
//
// This type is used to pass needed struct/class type information through abstract interface.
// Most importantly it captures:
// - pointer to object
// - reference to serialize method (indirectly through pointer to static func.)
// - TypeID
struct SStruct/*{{{*/
{
friend class IArchive;
public:
SStruct()
: object_(0)
, size_(0)
, serializeFunc_(0)
{
}
SStruct(TypeID type, void* object, size_t size, SerializeStructFunc Serialize)
: type_(type)
, object_(object)
, size_(size)
, serializeFunc_(Serialize)
{
YASLI_ASSERT(object != 0);
}
SStruct(const SStruct& _original)
: type_(_original.type_)
, object_(_original.object_)
, size_(_original.size_)
, serializeFunc_(_original.serializeFunc_)
{
}
template<class T>
explicit SStruct(const T& object)
{
type_ = TypeID::get<T>();
object_ = (void*)(&object);
size_ = sizeof(T);
serializeFunc_ = &SStruct::serializeRaw<T>;
}
template<class T>
explicit SStruct(const T& object, TypeID type)
{
type_ = type;
object_ = (void*)(&object);
size_ = sizeof(T);
serializeFunc_ = &SStruct::serializeRaw<T>;
}
// This constructs SStruct from an object that doesn't have Serialize method.
// Such SStruct can not be serialized but conveys object reference and type
// information that is needed for Property-archives. Used for decorators.
template<class T>
static SStruct ForEdit(const T& object)
{
SStruct r;
r.type_ = TypeID::get<T>();
r.object_ = (void*)&object;
r.size_ = sizeof(T);
r.serializeFunc_ = 0;
return r;
}
bool operator()(IArchive& ar, const char* name, const char* label) const;
bool operator()(IArchive& ar) const;
operator bool() const{
return object_ != 0;
}
bool operator==(const SStruct& rhs) const{ return object_ == rhs.object_ && serializeFunc_ == rhs.serializeFunc_; }
bool operator!=(const SStruct& rhs) const{ return !operator==(rhs); }
void* pointer() const{ return object_; }
void setPointer(void* p) { object_ = p; }
TypeID type() const{ return type_; }
void setType(const TypeID& type) { type_ = type; }
size_t size() const{ return size_; }
SerializeStructFunc serializeFunc() const{ return serializeFunc_; }
template<class T>
static bool serializeRaw(void* rawPointer, IArchive& ar)
{
YASLI_ESCAPE(rawPointer, return false);
// If you're getting compile error here, most likely, you have one of the following situations:
// - The type you're trying to serialize doesn't have Serialize _method_ implemented.
// - Type is supposed to be serialized with non-member Serialize function and this function is out of scope.
((T*)(rawPointer))->Serialize(ar);
return true;
}
template<class T>
T* cast() const
{
if (type_ == Serialization::TypeID::get<T>())
{
return (T*)object_;
}
else
{
return 0;
}
}
private:
TypeID type_;
void* object_;
size_t size_;
SerializeStructFunc serializeFunc_;
};/*}}}*/
typedef std::vector<SStruct> SStructs;
// ---------------------------------------------------------------------------
// This type is used to generalize access to specific container types.
// It is used by concrete IArchive implementations.
class IContainer
{
public:
virtual ~IContainer() { }
virtual size_t size() const = 0;
virtual size_t resize(size_t size) = 0;
virtual bool isFixedSize() const{ return false; }
virtual void* pointer() const = 0;
virtual bool next() = 0;
virtual TypeID containerType() const = 0;
virtual TypeID elementType() const = 0;
virtual void* elementPointer() const = 0;
virtual size_t elementSize() const = 0;
virtual bool operator()(IArchive& ar, const char* name, const char* label) = 0;
virtual operator bool() const = 0;
virtual void serializeNewElement(IArchive& ar, const char* name = "", const char* label = 0) const = 0;
};
template<class T>
class ContainerArray
: public IContainer /*{{{*/
{
friend class IArchive;
public:
explicit ContainerArray(T* array = 0, int size = 0)
: array_(array)
, index_(0)
, size_(size)
{
}
// from ContainerSerializationInterface:
size_t size() const{ return size_; }
size_t resize([[maybe_unused]] size_t size)
{
index_ = 0;
return size_;
}
void* pointer() const{ return reinterpret_cast<void*>(array_); }
TypeID containerType() const{ return TypeID::get<T>(); }
TypeID elementType() const{ return TypeID::get<T>(); }
void* elementPointer() const { return &array_[index_]; }
size_t elementSize() const { return sizeof(T); }
virtual bool isFixedSize() const{ return true; }
bool operator()(IArchive& ar, const char* name, const char* label)
{
YASLI_ESCAPE(size_t(index_) < size_, return false);
return ar(array_[index_], name, label);
}
operator bool() const{
return array_ != 0;
}
bool next()
{
++index_;
return size_t(index_) < size_;
}
void serializeNewElement(IArchive& ar, const char* name, const char* label) const
{
T element;
ar(element, name, label);
}
// ^^^
private:
T* array_;
int index_;
size_t size_;
};/*}}}*/
// Generialized interface over owning polymorphic pointers.
// Used by concrete IArchive implementations.
class IPointer
{
public:
virtual ~IPointer() { }
virtual const char* registeredTypeName() const = 0;
virtual void create(const char* registedTypeName) const = 0;
virtual TypeID baseType() const = 0;
virtual SStruct serializer() const = 0;
virtual void* get() const = 0;
virtual const void* handle() const = 0;
virtual TypeID pointerType() const = 0;
virtual IClassFactory* factory() const = 0;
void Serialize(IArchive& ar) const;
};
class IString
{
public:
virtual ~IString() { }
virtual void set(const char* value) = 0;
virtual const char* get() const = 0;
virtual const void* handle() const = 0;
virtual TypeID type() const = 0;
};
class IWString
{
public:
virtual ~IWString() { }
virtual void set(const wchar_t* value) = 0;
virtual const wchar_t* get() const = 0;
virtual const void* handle() const = 0;
virtual TypeID type() const = 0;
};
}
// vim:ts=4 sw=4:
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_SERIALIZER_H
@@ -0,0 +1,95 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_SERIALIZERIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_SERIALIZERIMPL_H
#pragma once
#include "Serializer.h"
#include "IClassFactory.h"
#include "ClassFactory.h"
// IArchive.h is supposed to be pre-included
namespace Serialization {
inline bool SStruct::operator()(IArchive& ar) const
{
YASLI_ESCAPE(serializeFunc_ && object_, return false);
return serializeFunc_(object_, ar);
}
inline bool SStruct::operator()(IArchive& ar, const char* name, const char* label) const
{
return ar(*this, name, label);
}
inline void IPointer::Serialize(IArchive& ar) const
{
const bool noEmptyNames = ar.GetCaps(IArchive::NO_EMPTY_NAMES);
const char* const typePropertyName = noEmptyNames ? "type" : "";
const char* const dataPropertyName = noEmptyNames ? "data" : "";
TypeID baseTypeID = baseType();
const char* oldRegisteredName = registeredTypeName();
if (!oldRegisteredName)
{
oldRegisteredName = "";
}
IClassFactory* factory = this->factory();
if (ar.IsOutput())
{
if (oldRegisteredName[0] != '\0')
{
TypeNameWithFactory pair(oldRegisteredName, factory);
if (ar(pair, typePropertyName))
{
ar(serializer(), dataPropertyName);
}
else
{
ar.Warning(pair, "Unable to write typeID!");
}
}
}
else
{
TypeNameWithFactory pair("", factory);
if (!ar(pair, typePropertyName))
{
if (oldRegisteredName[0] != '\0')
{
create(""); // 0
}
return;
}
if (oldRegisteredName[0] != '\0' && (pair.registeredName.empty() || (pair.registeredName != oldRegisteredName)))
{
create(""); // 0
}
if (!pair.registeredName.empty())
{
if (!get())
{
create(pair.registeredName.c_str());
}
ar(serializer(), dataPropertyName);
}
}
}
}
// vim:sw=4 ts=4:
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_SERIALIZERIMPL_H
@@ -0,0 +1,31 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_SMARTPTR_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_SMARTPTR_H
#pragma once
template <class T>
class _smart_ptr;
namespace Serialization
{
class IArchive;
};
template<class T>
bool Serialize(Serialization::IArchive& ar, _smart_ptr<T>& ptr, const char* name, const char* label);
#include "SmartPtrImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_SMARTPTR_H
@@ -0,0 +1,73 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_SMARTPTRIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_SMARTPTRIMPL_H
#pragma once
#include "SmartPtr.h"
#include <Serialization/Serializer.h>
#include "ClassFactory.h"
// Exposes _smart_ptr<> as serializeable type for Serialization::IArchive
template<class T>
class SmartPtrSerializer
: public Serialization::IPointer
{
public:
SmartPtrSerializer(_smart_ptr<T>& ptr)
: m_ptr(ptr)
{}
const char* registeredTypeName() const override
{
if (m_ptr)
{
return Serialization::ClassFactory<T>::the().getRegisteredTypeName(m_ptr.get());
}
else
{
return "";
}
}
void create(const char* registeredTypeName) const override
{
CRY_ASSERT(!m_ptr || m_ptr->NumRefs() == 1);
if (registeredTypeName && registeredTypeName[0] != '\0')
{
m_ptr.reset(Serialization::ClassFactory<T>::the().create(registeredTypeName));
}
else
{
m_ptr.reset((T*)0);
}
}
Serialization::TypeID baseType() const{ return Serialization::TypeID::get<T>(); }
virtual Serialization::SStruct serializer() const{ return Serialization::SStruct(*m_ptr); }
void* get() const{ return reinterpret_cast<void*>(m_ptr.get()); }
const void* handle() const { return &m_ptr; }
Serialization::TypeID pointerType() const { return Serialization::TypeID::get<_smart_ptr<T> >(); }
Serialization::IClassFactory* factory() const{ return &Serialization::ClassFactory<T>::the(); }
protected:
_smart_ptr<T>& m_ptr;
};
template<class T>
bool Serialize(Serialization::IArchive& ar, _smart_ptr<T>& ptr, const char* name, const char* label)
{
SmartPtrSerializer<T> serializer(ptr);
return ar(static_cast<Serialization::IPointer&>(serializer), name, label);
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_SMARTPTRIMPL_H
@@ -0,0 +1,301 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGLIST_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGLIST_H
#pragma once
#include <vector>
#include "Serialization/Strings.h"
#include "Serialization/DynArray.h"
#include <string.h>
#include "Serialization/Assert.h"
#ifndef SERIALIZATION_STANDALONE
#include <CryArray.h>
#endif
#include <AzCore/std/containers/fixed_vector.h>
namespace Serialization {
class IArchive;
class StringListStatic
#ifdef SERIALIZATION_STANDALONE
: public std::vector<const char*>
{
#else
: public AZStd::fixed_vector<const char*, 64> {
#endif
public:
enum
{
npos = -1
};
int find(const char* value) const
{
int numItems = int(size());
for (int i = 0; i < numItems; ++i)
{
if (strcmp((*this)[i], value) == 0)
{
return i;
}
}
return npos;
}
};
class StringListStaticValue
{
public:
StringListStaticValue(const StringListStaticValue& original)
: stringList_(original.stringList_)
, index_(original.index_)
{
handle_ = this;
}
StringListStaticValue()
: stringList_(0)
, index_(StringListStatic::npos)
{
handle_ = this;
}
StringListStaticValue(const StringListStatic& stringList, int value)
: stringList_(&stringList)
, index_(value)
{
handle_ = this;
}
StringListStaticValue(const StringListStatic& stringList, int value, const void* handle, const Serialization::TypeID& type)
: stringList_(&stringList)
, index_(value)
, handle_(handle)
, type_(type)
{
}
StringListStaticValue(const StringListStatic& stringList, const char* value, const void* handle, const Serialization::TypeID& type)
: stringList_(&stringList)
, index_(stringList.find(value))
, handle_(handle)
, type_(type)
{
YASLI_ASSERT(index_ != StringListStatic::npos);
}
StringListStaticValue& operator=(const char* value)
{
index_ = stringList_->find(value);
return *this;
}
StringListStaticValue& operator=(int value)
{
YASLI_ASSERT(value >= 0 && size_t(value) < size_t(stringList_->size()));
YASLI_ASSERT(this != 0);
index_ = value;
return *this;
}
StringListStaticValue& operator=(const StringListStaticValue& rhs)
{
stringList_ = rhs.stringList_;
index_ = rhs.index_;
return *this;
}
const char* c_str() const
{
if (index_ >= 0 && size_t(index_) < size_t(stringList_->size()))
{
return (*stringList_)[index_];
}
else
{
return "";
}
}
int index() const{ return index_; }
const void* handle() const{ return handle_; }
Serialization::TypeID type() const { return type_; }
const StringListStatic& stringList() const{ return *stringList_; }
template<class IArchive>
void Serialize(IArchive& ar)
{
ar(index_, "index");
}
protected:
const StringListStatic* stringList_;
int index_;
const void* handle_;
Serialization::TypeID type_;
};
class StringList
#ifdef SERIALIZATION_STANDALONE
: public std::vector<string>
{
#else
: public DynArray<string>{
#endif
public:
StringList() {}
StringList(const StringList& rhs)
{
*this = rhs;
}
StringList& operator=(const StringList& rhs)
{
// As StringList crosses dll boundaries it is important to copy strings
// rather than reference count them to be sure that stored CryString uses
// proper allocator.
resize(rhs.size());
for (size_t i = 0; i < size_t(size()); ++i)
{
(*this)[i] = rhs[i].c_str();
}
return *this;
}
StringList(const StringListStatic& rhs)
{
const int size = int(rhs.size());
resize(size);
for (int i = 0; i < int(size); ++i)
{
(*this)[i] = rhs[i];
}
}
enum
{
npos = -1
};
int find(const char* value) const
{
const int numItems = int(size());
for (int i = 0; i < numItems; ++i)
{
if ((*this)[i] == value)
{
return i;
}
}
return npos;
}
};
class StringListValue
{
public:
explicit StringListValue(const StringListStaticValue& value)
{
stringList_.resize(value.stringList().size());
for (size_t i = 0; i < size_t(stringList_.size()); ++i)
{
stringList_[i] = value.stringList()[i];
}
index_ = value.index();
}
StringListValue(const StringListValue& value)
{
stringList_ = value.stringList_;
index_ = value.index_;
}
StringListValue()
: index_(StringList::npos)
{
handle_ = this;
}
StringListValue(const StringList& stringList, int value)
: stringList_(stringList)
, index_(value)
{
handle_ = this;
}
StringListValue(const StringList& stringList, int value, const void* handle, const Serialization::TypeID& typeId)
: stringList_(stringList)
, index_(value)
, handle_(handle)
, type_(typeId)
{
}
StringListValue(const StringList& stringList, const char* value)
: stringList_(stringList)
, index_(stringList.find(value))
{
handle_ = this;
YASLI_ASSERT(index_ != StringList::npos);
}
StringListValue(const StringList& stringList, const char* value, const void* handle, const Serialization::TypeID& typeId)
: stringList_(stringList)
, index_(stringList.find(value))
, handle_(handle)
, type_(typeId)
{
YASLI_ASSERT(index_ != StringList::npos);
}
StringListValue(const StringListStatic& stringList, const char* value)
: stringList_(stringList)
, index_(stringList.find(value))
{
handle_ = this;
YASLI_ASSERT(index_ != StringList::npos);
}
StringListValue& operator=(const char* value)
{
index_ = stringList_.find(value);
return *this;
}
StringListValue& operator=(int value)
{
YASLI_ASSERT(value >= 0 && size_t(value) < size_t(stringList_.size()));
YASLI_ASSERT(this != 0);
index_ = value;
return *this;
}
const char* c_str() const
{
if (index_ >= 0 && size_t(index_) < size_t(stringList_.size()))
{
return stringList_[index_].c_str();
}
else
{
return "";
}
}
int index() const{ return index_; }
const void* handle() const { return handle_; }
Serialization::TypeID type() const { return type_; }
const StringList& stringList() const{ return stringList_; }
template<class IArchive>
void Serialize(IArchive& ar)
{
ar(index_, "index");
ar(stringList_, "stringList");
}
protected:
StringList stringList_;
int index_;
const void* handle_;
Serialization::TypeID type_;
};
class IArchive;
void splitStringList(StringList* result, const char* str, char sep);
void joinStringList(string* result, const StringList& stringList, char sep);
void joinStringList(string* result, const StringListStatic& stringList, char sep);
bool Serialize(Serialization::IArchive& ar, Serialization::StringList& value, const char* name, const char* label);
bool Serialize(Serialization::IArchive& ar, Serialization::StringListValue& value, const char* name, const char* label);
bool Serialize(Serialization::IArchive& ar, Serialization::StringListStaticValue& value, const char* name, const char* label);
}
#include "StringListImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGLIST_H
@@ -0,0 +1,126 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGLISTIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGLISTIMPL_H
#pragma once
#include "StringList.h"
#include "IArchive.h"
#include "DynArray.h"
#include "STL.h"
namespace Serialization {
// ---------------------------------------------------------------------------
inline void splitStringList(StringList* result, const char* str, char delimeter)
{
result->clear();
const char* ptr = str;
for (; *ptr; ++ptr)
{
if (*ptr == delimeter)
{
result->push_back(string(str, ptr));
str = ptr + 1;
}
}
result->push_back(string(str, ptr));
}
inline void joinStringList(string* result, const StringList& stringList, char sep)
{
YASLI_ESCAPE(result != 0, return );
result->clear();
for (StringList::const_iterator it = stringList.begin(); it != stringList.end(); ++it)
{
if (!result->empty())
{
result += sep;
}
result->append(*it);
}
}
inline void joinStringList(string* result, const StringListStatic& stringList, char sep)
{
YASLI_ESCAPE(result != 0, return );
result->clear();
for (StringListStatic::const_iterator it = stringList.begin(); it != stringList.end(); ++it)
{
if (!result->empty())
{
(*result) += sep;
}
YASLI_ESCAPE(*it != 0, continue);
result->append(*it);
}
}
inline bool Serialize(Serialization::IArchive& ar, Serialization::StringList& value, const char* name, const char* label)
{
#ifdef SERIALIZATION_STANDALONE
return ar(static_cast<std::vector<Serialization::string>&>(value), name, label);
#else
return ar(static_cast<DynArray<Serialization::string>&>(value), name, label);
#endif
}
inline bool Serialize(Serialization::IArchive& ar, Serialization::StringListValue& value, const char* name, const char* label)
{
using Serialization::string;
if (ar.IsEdit())
{
return ar(Serialization::SStruct(value), name, label);
}
else
{
string str;
if (ar.IsOutput())
{
str = value.c_str();
}
if (ar(str, name, label) && ar.IsInput())
{
value = str.c_str();
return true;
}
return false;
}
}
inline bool Serialize(Serialization::IArchive& ar, Serialization::StringListStaticValue& value, const char* name, const char* label)
{
using Serialization::string;
if (ar.IsEdit())
{
return ar(Serialization::SStruct(value), name, label);
}
else
{
string str;
if (ar.IsOutput())
{
str = value.c_str();
}
if (ar(str, name, label) && ar.IsInput())
{
value = str.c_str();
return true;
}
return true;
}
}
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGLISTIMPL_H
@@ -0,0 +1,32 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGS_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGS_H
#pragma once
#ifdef SERIALIZATION_STANDALONE
#include <string>
namespace Serialization {
using std::string;
using std::wstring;
}
#else
#include <platform.h>
namespace Serialization {
typedef CryStringT<char> string;
typedef CryStringT<wchar_t> wstring;
}
#endif // SERIALIZATION_STANDALONE
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_STRINGS_H
@@ -0,0 +1,290 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEID_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEID_H
#pragma once
#include "Serialization/Assert.h"
#include "Serialization/Strings.h"
#include <string.h>
namespace Serialization {
class IArchive;
struct TypeInfo;
class TypeID
{
public:
TypeID()
: typeInfo_(0)
, module_(0) {}
TypeID(const TypeID& original)
: typeInfo_(original.typeInfo_)
, module_(original.module_)
{
}
operator bool() const{
return *this != TypeID();
}
template<class T>
static TypeID get();
std::size_t sizeOf() const;
const char* name() const;
bool operator==(const TypeID& rhs) const;
bool operator!=(const TypeID& rhs) const;
bool operator<(const TypeID& rhs) const;
private:
TypeInfo* typeInfo_;
void* module_;
friend struct TypeInfo;
friend class TypeDescription;
};
struct TypeInfo
{
TypeID id;
size_t size;
char name[128];
// We are trying to minimize type names here. Stripping namespaces,
// whitespaces and S/C/E/I prefixes. Why namespaces? Type names are usually
// used in two contexts: for unique name within factory context, where
// collision is unlikely, or for filtering in PropertyTree where concise
// name is much more useful.
static void cleanTypeName(char*& d, const char* dend, const char*& s, const char* send)
{
if (strncmp(s, "class ", 6) == 0)
{
s += 6;
}
else if (strncmp(s, "struct ", 7) == 0)
{
s += 7;
}
while (*s == ' ' && s != send)
{
++s;
}
// strip C/S/I/E prefixes
if ((*s == 'C' || *s == 'S' || *s == 'I' || *s == 'E') && s[1] >= 'A' && s[1] <= 'Z')
{
++s;
}
if (s >= send)
{
return;
}
char* startd = d;
while (d != dend && s != send)
{
while (*s == ' ' && s != send)
{
++s;
}
if (s == send)
{
break;
}
if (*s == ':' && s[1] == ':')
{
// strip namespaces
s += 2;
d = startd;
if ((*s == 'C' || *s == 'S' || *s == 'I' || *s == 'E') && s[1] >= 'A' && s[1] <= 'Z')
{
++s;
}
}
if (s >= send)
{
break;
}
if (*s == '<')
{
* d = '<';
++d;
++s;
cleanTypeName(d, dend, s, send);
}
else if (*s == '>')
{
* d = '\0';
return;
}
* d = *s;
++s;
++d;
}
}
template<size_t nameLen>
static void extractTypeName(char (&name)[nameLen], const char* funcName)
{
#ifdef __clang__
// "static yasli::TypeID yasli::TypeID::get() [T = ActualTypeName]"
const char* s = strstr(funcName, "[T = ");
if (s)
{
s += 5;
}
const char* send = strrchr(funcName, ']');
#elif __GNUC__ >= 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
// "static yasli::TypeID yasli::TypeID::get() [with T = ActualTypeName]"
const char* s = strstr(funcName, "[with T = ");
if (s)
{
s += 9;
}
const char* send = strrchr(funcName, ']');
#else
// "static yasli::TypeID yasli::TypeID::get<ActualTypeName>()"
const char* s = strchr(funcName, '<');
const char* send = strrchr(funcName, '>');
YASLI_ASSERT(s != 0 && send != 0);
if (s != send)
{
++s;
}
#endif
YASLI_ASSERT(s != 0 && send != 0);
char* d = name;
const char* dend = name + sizeof(name) - 1;
cleanTypeName(d, dend, s, send);
* d = '\0';
// This assertion is not critical, but may result in collision as
// stripped name wil be used, e.g. for lookup in factory.
YASLI_ASSERT(s == send && "Type name does not fit into the buffer");
}
TypeInfo(size_t _size, const char* templatedFunctionName)
: size(_size)
{
extractTypeName(name, templatedFunctionName);
id.typeInfo_ = this;
static int moduleSpecificSymbol;
id.module_ = &moduleSpecificSymbol;
}
bool operator==(const TypeInfo& rhs) const
{
return size == rhs.size && strcmp(name, rhs.name) == 0;
}
bool operator<(const TypeInfo& rhs) const
{
if (size == rhs.size)
{
return strcmp(name, rhs.name) < 0;
}
else
{
return size < rhs.size;
}
}
};
template<class T>
TypeID TypeID::get()
{
#ifdef _MSC_VER
static TypeInfo typeInfo(sizeof(T), __FUNCSIG__);
#else
static TypeInfo typeInfo(sizeof(T), __PRETTY_FUNCTION__);
#endif
return typeInfo.id;
}
inline const char* TypeID::name() const
{
if (typeInfo_)
{
return typeInfo_->name;
}
else
{
return "";
}
}
inline size_t TypeID::sizeOf() const
{
if (typeInfo_)
{
return typeInfo_->size;
}
else
{
return 0;
}
}
inline bool TypeID::operator==(const TypeID& rhs) const
{
if (typeInfo_ == rhs.typeInfo_)
{
return true;
}
else if (!typeInfo_ || !rhs.typeInfo_)
{
return false;
}
else if (module_ == rhs.module_)
{
return false;
}
else
{
return *typeInfo_ == *rhs.typeInfo_;
}
}
inline bool TypeID::operator!=(const TypeID& rhs) const
{
return !operator==(rhs);
}
inline bool TypeID::operator<(const TypeID& rhs) const
{
if (!typeInfo_)
{
return rhs.typeInfo_ != 0;
}
else if (!rhs.typeInfo_)
{
return false;
}
else
{
return *typeInfo_ < *rhs.typeInfo_;
}
}
template<class T>
T* createDerivedClass(TypeID typeID);
}
//bool Serialize(Serialization::IArchive& ar, Serialization::TypeID& typeID, const char* name, const char* label);
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEID_H
@@ -0,0 +1,46 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEINFO_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEINFO_H
#pragma once
namespace Serialization {
class IArchive;
}
struct STypeInfoInstance
{
template<class T>
STypeInfoInstance(T& obj)
: m_pTypeInfo(&TypeInfo(&obj))
, m_pObject(&obj)
{
}
STypeInfoInstance(const CTypeInfo* typeInfo, void* object)
: m_pTypeInfo(typeInfo)
, m_pObject(object)
{
}
inline void Serialize(Serialization::IArchive& ar);
const CTypeInfo* m_pTypeInfo;
void* m_pObject;
std::set<string> m_persistentStrings;
};
#include "TypeInfoImpl.h"
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEINFO_H
@@ -0,0 +1,245 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEINFOIMPL_H
#define CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEINFOIMPL_H
#pragma once
#include "CryTypeInfo.h"
#include "Serialization/Decorators/Range.h"
#include "Serialization/Enum.h"
#include "ISplines.h"
#include <StringUtils.h>
#include "Serialization/Color.h"
#include "Cry_Color.h"
#include "Decorators/Resources.h"
struct SPrivateTypeInfoInstanceLevel
{
SPrivateTypeInfoInstanceLevel(const CTypeInfo* typeInfo, void* object, STypeInfoInstance* instance)
: m_pTypeInfo(typeInfo)
, m_pObject(object)
, m_instance(instance)
{
}
void Serialize(Serialization::IArchive& ar)
{
for AllSubVars(pVar, *m_pTypeInfo)
{
string group;
if (pVar->GetAttr("Group", group))
{
if (!m_sCurrentGroup.empty())
{
ar.CloseBlock();
}
const char* name = m_instance->m_persistentStrings.insert(group).first->c_str();
ar.OpenBlock(name, name);
m_sCurrentGroup = name;
}
else
{
const char* name = pVar->GetName();
if (!*name)
{
name = pVar->Type.Name;
}
const char* label = pVar->GetName();
if (!*label)
{
string n = "^";
n += pVar->GetName();
label = m_instance->m_persistentStrings.insert(n).first->c_str();
}
SerializeVariable(pVar, m_pObject, ar, name, label);
}
}
if (!m_sCurrentGroup.empty())
{
ar.CloseBlock();
m_sCurrentGroup.clear();
}
}
template <class T>
void SerializeT(const CTypeInfo::CVarInfo* pVar, void* pParentAddress, Serialization::IArchive& ar, const char* name, const char* label)
{
T value;
const CTypeInfo& type = pVar->Type;
type.ToValue(pVar->GetAddress(pParentAddress), value);
ar(value, name, label);
if (ar.IsInput())
{
type.FromValue(pVar->GetAddress(pParentAddress), value);
}
}
template <class T>
void SerializeNumericalT(const CTypeInfo::CVarInfo* pVar, void* pParentAddress, Serialization::IArchive& ar, const char* name, const char* label)
{
T value;
const CTypeInfo& type = pVar->Type;
type.ToValue(pVar->GetAddress(pParentAddress), value);
float limMin, limMax;
if (pVar->GetLimit(eLimit_Min, limMin) && pVar->GetLimit(eLimit_Max, limMax))
{
ar(Serialization::Range<T>(value, limMin, limMax), name, label);
}
else
{
ar(value, name, label);
}
if (ar.IsInput())
{
type.FromValue(pVar->GetAddress(pParentAddress), value);
}
}
void SerializeVariable(const CTypeInfo::CVarInfo* pVar, void* pParentAddress, Serialization::IArchive& ar, const char* name, const char* label)
{
const CTypeInfo& type = pVar->Type;
if (type.HasSubVars())
{
if (strcmp(name, "Color") == 0)
{
Color3F value;
const CTypeInfo& type = pVar->Type;
type.ToValue(pVar->GetAddress(pParentAddress), value);
ColorF colour = value;
ar(colour, name, label);
if (ar.IsInput())
{
value = Color3F(colour.r, colour.g, colour.b);
type.FromValue(pVar->GetAddress(pParentAddress), value);
}
}
else
{
// load params of sub-variables (variable is a struct or vector)
SPrivateTypeInfoInstanceLevel instance(&type, pVar->GetAddress(pParentAddress), m_instance);
ar(instance, name, label);
}
}
else
{
if (type.IsType<bool>())
{
SerializeT<bool>(pVar, pParentAddress, ar, name, label);
}
else if (type.IsType<unsigned char>())
{
SerializeNumericalT<unsigned char>(pVar, pParentAddress, ar, name, label);
}
else if (type.IsType<char>())
{
SerializeNumericalT<char>(pVar, pParentAddress, ar, name, label);
}
else if (type.IsType<int>())
{
SerializeNumericalT<int>(pVar, pParentAddress, ar, name, label);
}
else if (type.IsType<uint>())
{
SerializeNumericalT<uint>(pVar, pParentAddress, ar, name, label);
}
else if (type.IsType<float>())
{
SerializeNumericalT<float>(pVar, pParentAddress, ar, name, label);
}
else if (type.EnumElem(0))
{
Serialization::StringList stringList;
const char* enumType = type.EnumElem(0);
for (int i = 1; enumType; ++i)
{
stringList.push_back(enumType);
enumType = type.EnumElem(i);
}
string enumValue = pVar->ToString(pParentAddress);
int index = std::max(stringList.find(enumValue.c_str()), 0);
Serialization::StringListValue stringListValue(stringList, index);
ar(stringListValue, name, label);
if (ar.IsInput())
{
pVar->FromString(pParentAddress, stringListValue.c_str());
}
}
else
{
ISplineInterpolator* pSpline = 0;
if (type.ToValue(pVar->GetAddress(pParentAddress), pSpline))
{
// TODO: Curve field
}
else
{
string value;
value = pVar->ToString(pParentAddress);
if (strcmp(name, "Texture") == 0)
{
// TODO: Texture field
}
else if (strcmp(name, "Material") == 0)
{
// TODO: Material field
}
else if (strcmp(name, "Geometry") == 0)
{
ar(Serialization::ModelFilename(value), name, label);
}
else if (strcmp(name, "Sound") == 0)
{
ar(Serialization::SoundName(value), name, label);
}
else if (strcmp(name, "GeomCache") == 0)
{
// TODO: Geom cache field
}
else
{
ar(value, name, label);
}
if (ar.IsInput())
{
pVar->FromString(pParentAddress, value.c_str());
}
}
}
}
}
private:
const CTypeInfo* m_pTypeInfo;
void* m_pObject;
string m_sCurrentGroup;
STypeInfoInstance* m_instance;
};
//------------------------------
inline void STypeInfoInstance::Serialize(Serialization::IArchive& ar)
{
SPrivateTypeInfoInstanceLevel instance(m_pTypeInfo, m_pObject, this);
instance.Serialize(ar);
}
#endif // CRYINCLUDE_CRYCOMMON_SERIALIZATION_TYPEINFOIMPL_H