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,839 @@
/*
* 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.
#include "EditorCommon_precompiled.h"
#include "BinArchive.h"
#include <map>
#include "Serialization/ClassFactory.h"
namespace Serialization {
static const unsigned char SIZE16 = 254;
static const unsigned char SIZE32 = 255;
static const unsigned int BIN_MAGIC = 0xb1a4c17f;
//#ifdef _DEBUG
//typedef std::map<unsigned short, string> HashMap;
//static HashMap hashMap;
//#endif
BinOArchive::BinOArchive()
: IArchive(OUTPUT | BINARY)
{
clear();
}
void BinOArchive::clear()
{
stream_.clear();
stream_.write((const char*)&BIN_MAGIC, sizeof(BIN_MAGIC));
}
size_t BinOArchive::length() const
{
return stream_.position();
}
bool BinOArchive::save(const char* filename)
{
FILE* f = nullptr;
azfopen(&f, filename, "wb");
if (!f)
{
return false;
}
if (fwrite(buffer(), 1, length(), f) != length())
{
fclose(f);
return false;
}
fclose(f);
return true;
}
inline void BinOArchive::openNode(const char* name, bool size8)
{
if (!strlen(name))
{
return;
}
unsigned short hash = calcHash(name);
stream_.write(hash);
blockSizeOffsets_.push_back(int(stream_.position()));
stream_.write((unsigned char)0);
if (!size8)
{
stream_.write((unsigned short)0);
}
#ifdef _DEBUG
// HashMap::iterator i = hashMap.find(hash);
// if(i != hashMap.end() && i->second != name)
// ASSERT_STR(0, name);
// hashMap[hash] = name;
#endif
}
inline void BinOArchive::closeNode(const char* name, bool size8)
{
if (!strlen(name))
{
return;
}
unsigned int offset = blockSizeOffsets_.back();
unsigned int size = (unsigned int)(stream_.position() - offset - sizeof(unsigned char) - (size8 ? 0 : sizeof(unsigned short)));
blockSizeOffsets_.pop_back();
unsigned char* sizePtr = (unsigned char*)(stream_.buffer() + offset);
if (size < SIZE16)
{
*sizePtr = size;
if (!size8)
{
unsigned char* buffer = sizePtr + 3;
memmove(buffer - 2, buffer, size);
stream_.setPosition(stream_.position() - 2);
}
}
else
{
YASLI_ASSERT(!size8);
if (size < 0x10000)
{
*sizePtr = SIZE16;
*((unsigned short*)(sizePtr + 1)) = size;
}
else
{
unsigned char* buffer = sizePtr + 3;
stream_.write((unsigned short)0);
*sizePtr = SIZE32;
memmove(buffer + 2, buffer, size);
*((unsigned int*)(sizePtr + 1)) = size;
}
}
}
bool BinOArchive::operator()(bool& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(IString& value, const char* name, [[maybe_unused]] const char* label)
{
bool size8 = strlen(value.get()) + 1 < SIZE16;
openNode(name, size8);
stream_ << value.get();
stream_.write(char(0));
closeNode(name, size8);
return true;
}
bool BinOArchive::operator()(IWString& value, const char* name, [[maybe_unused]] const char* label)
{
bool size8 = (wcslen(value.get()) + 1) * 2 < SIZE16;
openNode(name, size8);
stream_ << value.get();
stream_.write(short(0));
closeNode(name, size8);
return true;
}
bool BinOArchive::operator()(float& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(double& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(int16& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(int8& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(uint8& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(char& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(uint16& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(int32& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(uint32& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(int64& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(uint64& value, const char* name, [[maybe_unused]] const char* label)
{
openNode(name);
stream_.write(value);
closeNode(name);
return true;
}
bool BinOArchive::operator()(const SStruct& ser, const char* name, [[maybe_unused]] const char* label)
{
openNode(name, false);
ser(*this);
closeNode(name, false);
return true;
}
bool BinOArchive::operator()(IContainer& ser, const char* name, [[maybe_unused]] const char* label)
{
openNode(name, false);
unsigned int size = (unsigned int)ser.size();
if (size < SIZE16)
{
stream_.write((unsigned char)size);
}
else if (size < 0x10000)
{
stream_.write(SIZE16);
stream_.write((unsigned short)size);
}
else
{
stream_.write(SIZE32);
stream_.write(size);
}
if (strlen(name))
{
if (size > 0)
{
int i = 0;
do
{
char elementName[16];
azitoa(i++, elementName, AZ_ARRAY_SIZE(elementName), 10);
ser(*this, elementName, "");
} while (ser.next());
}
closeNode(name, false);
}
else
{
if (size > 0)
{
do
{
ser(*this, "", "");
}
while (ser.next());
}
}
return true;
}
bool BinOArchive::operator()(IPointer& ptr, const char* name, [[maybe_unused]] const char* label)
{
openNode(name, false);
const char* typeName = ptr.registeredTypeName();
if (!typeName)
{
typeName = "";
}
if (ptr.get() && typeName[0] == '\0')
{
CRY_ASSERT_MESSAGE(0, "Writing unregistered class. Use SERIALIZATION_CLASS_NAME macro for registration.");
}
TypeID baseType = ptr.baseType();
if (ptr.get())
{
stream_ << typeName;
stream_.write(char(0));
ptr.serializer()(*this);
}
else
{
stream_.write(char(0));
}
closeNode(name, false);
return true;
}
//////////////////////////////////////////////////////////////////////////
BinIArchive::BinIArchive()
: IArchive(INPUT | BINARY)
, loadedData_(0)
{
}
BinIArchive::~BinIArchive()
{
close();
}
bool BinIArchive::load(const char* filename)
{
close();
FILE* f = nullptr;
azfopen(&f, filename, "rb");
if (!f)
{
return false;
}
fseek(f, 0, SEEK_END);
size_t length = ftell(f);
fseek(f, 0, SEEK_SET);
if (length == 0)
{
fclose(f);
return false;
}
loadedData_ = new char[length];
if (fread((void*)loadedData_, 1, length, f) != length || !open(loadedData_, length))
{
close();
fclose(f);
return false;
}
fclose(f);
return true;
}
bool BinIArchive::open(const char* buffer, size_t size)
{
if (size < sizeof(int))
{
return false;
}
if (*(unsigned*)(buffer) != BIN_MAGIC)
{
return false;
}
buffer += sizeof(unsigned int);
size -= sizeof(unsigned int);
blocks_.push_back(Block(buffer, (unsigned int)size));
return true;
}
void BinIArchive::close()
{
if (loadedData_)
{
delete [] loadedData_;
}
loadedData_ = 0;
}
bool BinIArchive::openNode(const char* name)
{
Block block(0, 0);
if (currentBlock().get(name, block))
{
blocks_.push_back(block);
return true;
}
return false;
}
void BinIArchive::closeNode([[maybe_unused]] const char* name, [[maybe_unused]] bool check)
{
YASLI_ASSERT(!check || currentBlock().validToClose());
blocks_.pop_back();
}
bool BinIArchive::operator()(bool& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(IString& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
string str;
read(str);
value.set(str.c_str());
return true;
}
if (!openNode(name))
{
return false;
}
string str;
read(str);
value.set(str.c_str());
closeNode(name);
return true;
}
bool BinIArchive::operator()(IWString& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
wstring str;
read(str);
value.set(str.c_str());
return true;
}
if (!openNode(name))
{
return false;
}
wstring str;
read(str);
value.set(str.c_str());
closeNode(name);
return true;
}
bool BinIArchive::operator()(float& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(double& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(int16& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(uint16& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(int32& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(uint32& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(int64& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(uint64& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(int8& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(uint8& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(char& value, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
read(value);
return true;
}
if (!openNode(name))
{
return false;
}
read(value);
closeNode(name);
return true;
}
bool BinIArchive::operator()(const SStruct& ser, const char* name, [[maybe_unused]] const char* label)
{
if (!strlen(name))
{
ser(*this);
return true;
}
if (!openNode(name))
{
return false;
}
ser(*this);
closeNode(name, false);
return true;
}
bool BinIArchive::operator()(IContainer& ser, const char* name, [[maybe_unused]] const char* label)
{
if (strlen(name))
{
if (!openNode(name))
{
return false;
}
size_t size = currentBlock().readPackedSize();
ser.resize(size);
if (size > 0)
{
int i = 0;
do
{
char elementName[16];
azitoa(i++, elementName, AZ_ARRAY_SIZE(elementName), 10);
ser(*this, elementName, "");
}
while (ser.next());
}
closeNode(name);
return true;
}
else
{
size_t size = currentBlock().readPackedSize();
ser.resize(size);
if (size > 0)
{
do
{
ser(*this, "", "");
}
while (ser.next());
}
return true;
}
}
bool BinIArchive::operator()(IPointer& ptr, const char* name, [[maybe_unused]] const char* label)
{
if (strlen(name) && !openNode(name))
{
return false;
}
string typeName;
read(typeName);
if (ptr.get() && (typeName.empty() || (typeName != ptr.registeredTypeName())))
{
ptr.create(""); // 0
}
if (!typeName.empty() && !ptr.get())
{
ptr.create(typeName.c_str());
}
if (SStruct ser = ptr.serializer())
{
ser(*this);
}
if (strlen(name))
{
closeNode(name);
}
return true;
}
unsigned int BinIArchive::Block::readPackedSize()
{
unsigned char size8;
read(size8);
if (size8 < SIZE16)
{
return size8;
}
if (size8 == SIZE16)
{
unsigned short size16;
read(size16);
return size16;
}
unsigned int size32;
read(size32);
return size32;
}
bool BinIArchive::Block::get(const char* name, Block& block)
{
if (begin_ == end_)
{
return false;
}
complex_ = true;
unsigned short hashName = calcHash(name);
const char* currInitial = curr_;
bool restarted = false;
for (;; )
{
if (curr_ >= end_)
{
return false;
}
unsigned short hash;
read(hash);
unsigned int size = readPackedSize();
const char* currPrev = curr_;
if ((curr_ += size) == end_)
{
if (restarted)
{
return false;
}
curr_ = begin_;
restarted = true;
}
//ASSERT(curr_ < end_);
if (hash == hashName)
{
block = Block(currPrev, size);
return true;
}
if (curr_ == currInitial)
{
return false;
}
}
}
}
@@ -0,0 +1,183 @@
/*
* 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.
// For tags 16-bit xor-hash is used, with check for uniquness in debug
// Block size is automatic: 8, 16 or 32 bits
#ifndef CRYINCLUDE_EDITORCOMMON_SERIALIZATION_BINARCHIVE_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_BINARCHIVE_H
#pragma once
#include "Serialization/IArchive.h"
#include "MemoryWriter.h"
#include "EditorCommonAPI.h"
namespace Serialization {
inline unsigned short calcHash(const char* str)
{
unsigned short hash = 0;
const unsigned short* p = (const unsigned short*)(str);
for (;; )
{
unsigned short w = *p++;
if (!(w & 0xff))
{
break;
}
hash ^= w;
if (!(w & 0xff00))
{
break;
}
}
return hash;
}
class BinOArchive
: public IArchive
{
public:
BinOArchive();
~BinOArchive() {}
void clear();
size_t length() const;
const char* buffer() const { return stream_.buffer(); }
bool save(const char* fileName);
bool operator()(bool& value, const char* name, const char* label);
bool operator()(IString& value, const char* name, const char* label);
bool operator()(IWString& value, const char* name, const char* label);
bool operator()(float& value, const char* name, const char* label);
bool operator()(double& value, const char* name, const char* label);
bool operator()(int32& value, const char* name, const char* label);
bool operator()(uint32& value, const char* name, const char* label);
bool operator()(int16& value, const char* name, const char* label);
bool operator()(uint16& value, const char* name, const char* label);
bool operator()(int64& value, const char* name, const char* label);
bool operator()(uint64& value, const char* name, const char* label);
bool operator()(int8& value, const char* name, const char* label);
bool operator()(uint8& value, const char* name, const char* label);
bool operator()(char& value, const char* name, const char* label);
bool operator()(const SStruct& ser, const char* name, const char* label);
bool operator()(IContainer& ser, const char* name, const char* label);
bool operator()(IPointer& ptr, const char* name, const char* label);
using IArchive::operator();
private:
void openContainer(const char* name, int size, const char* typeName);
void openNode(const char* name, bool size8 = true);
void closeNode(const char* name, bool size8 = true);
std::vector<unsigned int> blockSizeOffsets_;
MemoryWriter stream_;
};
//////////////////////////////////////////////////////////////////////////
class BinIArchive
: public IArchive
{
public:
BinIArchive();
~BinIArchive();
bool load(const char* fileName);
bool open(const char* buffer, size_t length); // doesn't copy the buffer
bool open(const BinOArchive& ar) { return open(ar.buffer(), ar.length()); }
void close();
bool operator()(bool& value, const char* name, const char* label);
bool operator()(IString& value, const char* name, const char* label);
bool operator()(IWString& value, const char* name, const char* label);
bool operator()(float& value, const char* name, const char* label);
bool operator()(double& value, const char* name, const char* label);
bool operator()(int16& value, const char* name, const char* label);
bool operator()(uint16& value, const char* name, const char* label);
bool operator()(int32& value, const char* name, const char* label);
bool operator()(uint32& value, const char* name, const char* label);
bool operator()(int64& value, const char* name, const char* label);
bool operator()(uint64& value, const char* name, const char* label);
bool operator()(int8& value, const char* name, const char* label);
bool operator()(uint8& value, const char* name, const char* label);
bool operator()(char& value, const char* name, const char* label);
bool operator()(const SStruct& ser, const char* name, const char* label);
bool operator()(IContainer& ser, const char* name, const char* label);
bool operator()(IPointer& ptr, const char* name, const char* label);
using IArchive::operator();
private:
class Block
{
public:
Block(const char* data, int size)
: begin_(data)
, curr_(data)
, end_(data + size)
, complex_(false) {}
bool get(const char* name, Block& block);
void read(void* data, int size)
{
YASLI_ASSERT(curr_ + size <= end_);
memcpy(data, curr_, size);
curr_ += size;
}
template<class T>
void read(T& x){ read(&x, sizeof(x)); }
void read(string& s)
{
YASLI_ASSERT(curr_ + strlen(curr_) < end_);
s = curr_;
curr_ += strlen(curr_) + 1;
}
void read(wstring& s)
{
YASLI_ASSERT(curr_ + sizeof(wchar_t) * wcslen((wchar_t*)curr_) < end_);
s = (wchar_t*)curr_;
curr_ += (wcslen((wchar_t*)curr_) + 1) * sizeof(wchar_t);
}
unsigned int readPackedSize();
bool validToClose() const { return complex_ || curr_ == end_; }
private:
const char* begin_;
const char* end_;
const char* curr_;
bool complex_;
};
typedef std::vector<Block> Blocks;
Blocks blocks_;
const char* loadedData_;
bool openNode(const char* name);
void closeNode(const char* name, bool check = true);
Block& currentBlock() { return blocks_.back(); }
template<class T>
void read(T& t) { currentBlock().read(t); }
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_BINARCHIVE_H
@@ -0,0 +1,76 @@
/*
* 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/Decorators/ActionButton.h>
#include <AzCore/std/functional.h>
namespace Serialization
{
typedef AZStd::function<void()> StdFunctionActionButtonCalback;
struct StdFunctionActionButton
: public IActionButton
{
StdFunctionActionButtonCalback callback;
string icon;
explicit StdFunctionActionButton(const StdFunctionActionButtonCalback& 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 StdFunctionActionButton(callback, icon.c_str()));
}
// ~IActionButton
};
inline bool Serialize(Serialization::IArchive& ar, StdFunctionActionButton& 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 StdFunctionActionButton ActionButton(const StdFunctionActionButtonCalback& callback, const char* icon = "")
{
return StdFunctionActionButton(callback, icon);
}
}
@@ -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_EDITORCOMMON_SERIALIZATION_DECORATORS_IGIZMOSINK_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_IGIZMOSINK_H
#pragma once
namespace Serialization {
struct LocalPosition;
struct LocalFrame;
struct LocalOrientation;
struct GizmoFlags
{
bool visible;
bool selected;
GizmoFlags()
: visible(true)
, selected(false) {}
};
struct IGizmoSink
{
virtual ~IGizmoSink() = default;
virtual int CurrentGizmoIndex() const = 0;
virtual int Write(const LocalPosition&, const GizmoFlags& flags, const void* handle) = 0;
virtual int Write(const LocalOrientation&, const GizmoFlags& flags, const void* handle) = 0;
virtual int Write(const LocalFrame&, const GizmoFlags& flags, const void* handle) = 0;
virtual void SkipRead() = 0;
virtual bool Read(LocalPosition* position, GizmoFlags* flags, const void* handle) = 0;
virtual bool Read(LocalOrientation* position, GizmoFlags* flags, const void* handle) = 0;
virtual bool Read(LocalFrame* position, GizmoFlags* flags, const void* handle) = 0;
virtual void Reset(const void* handle) = 0;
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_IGIZMOSINK_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_EDITORCOMMON_SERIALIZATION_DECORATORS_INAVIGATIONPROVIDER_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_INAVIGATIONPROVIDER_H
#pragma once
namespace Serialization
{
struct SNavigationContext
{
string path;
};
struct INavigationProvider
{
virtual ~INavigationProvider() = default;
virtual const char* GetIcon(const char* type, const char* path) const = 0;
virtual const char* GetFileSelectorMaskForType(const char* type) const = 0;
virtual const char* GetEngineTypeForInputType(const char* extension) const { return extension; }
virtual bool IsSelected(const char* type, const char* path, int index) const = 0;
virtual bool IsActive(const char* type, const char* path, int index) const = 0;
virtual bool IsModified(const char* type, const char* path, int index) const = 0;
virtual bool Select(const char* type, const char* path, int index) const = 0;
virtual bool CanSelect([[maybe_unused]] const char* type, [[maybe_unused]] const char* path, [[maybe_unused]] int index) const { return false; }
virtual bool CanPickFile([[maybe_unused]] const char* type, [[maybe_unused]] int index) const { return true; }
virtual bool CanCreate([[maybe_unused]] const char* type, [[maybe_unused]] int index) const { return false; }
virtual bool Create([[maybe_unused]] const char* type, [[maybe_unused]] const char* path, [[maybe_unused]] int index) const { return false; }
virtual bool IsRegistered([[maybe_unused]] const char* type) const { return false; }
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_INAVIGATIONPROVIDER_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_EDITORCOMMON_SERIALIZATION_DECORATORS_ICONXPM_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_ICONXPM_H
#pragma once
namespace Serialization {
class IArchive;
// Icon, stored in XPM format
struct IconXPM
{
const char* const* source;
int lineCount;
IconXPM()
: source(0)
, lineCount(0)
{
}
template<size_t Size>
explicit IconXPM(const char* (&xpm)[Size])
{
source = xpm;
lineCount = Size;
}
void Serialize([[maybe_unused]] Serialization::IArchive& ar) {}
bool operator<(const IconXPM& rhs) const { return source < rhs.source; }
};
struct IconXPMToggle
{
bool* variable_;
bool value_;
IconXPM iconTrue_;
IconXPM iconFalse_;
template<size_t Size1, size_t Size2>
IconXPMToggle(bool& variable, char* (&xpmTrue)[Size1], char* (&xpmFalse)[Size2])
: iconTrue_(xpmTrue)
, iconFalse_(xpmFalse)
, variable_(&variable)
, value_(variable)
{
}
IconXPMToggle(bool& variable, const IconXPM& iconTrue, const IconXPM& iconFalse)
: iconTrue_(iconTrue)
, iconFalse_(iconFalse)
, variable_(&variable)
, value_(variable)
{
}
IconXPMToggle(const IconXPMToggle& orig)
: variable_(0)
, value_(orig.value_)
, iconTrue_(orig.iconTrue_)
, iconFalse_(orig.iconFalse_)
{
}
IconXPMToggle()
: variable_(0)
{
}
IconXPMToggle& operator=(const IconXPMToggle& rhs)
{
value_ = rhs.value_;
return *this;
}
~IconXPMToggle()
{
if (variable_)
{
* variable_ = value_;
}
}
template<class TArchive>
void Serialize(TArchive& ar)
{
ar(value_, "value", "Value");
}
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_ICONXPM_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_EDITORCOMMON_SERIALIZATION_DECORATORS_TOGGLEBUTTON_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_TOGGLEBUTTON_H
#pragma once
namespace Serialization
{
class IArchive;
struct ToggleButton
{
bool* value;
ToggleButton(bool& value)
: value(&value)
{
}
};
struct RadioButton
{
int* value;
int buttonValue;
RadioButton(int& value, int buttonValue)
: value(&value)
, buttonValue(buttonValue)
{
}
};
bool Serialize(Serialization::IArchive& ar, Serialization::ToggleButton& button, const char* name, const char* label);
bool Serialize(Serialization::IArchive& ar, Serialization::RadioButton& button, const char* name, const char* label);
}
#include "ToggleButtonImpl.h"
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_TOGGLEBUTTON_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_EDITORCOMMON_SERIALIZATION_DECORATORS_TOGGLEBUTTONIMPL_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_TOGGLEBUTTONIMPL_H
#pragma once
namespace Serialization
{
inline bool Serialize(Serialization::IArchive& ar, Serialization::ToggleButton& button, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(button), name, label);
}
else
{
return ar(*button.value, name, label);
}
}
inline bool Serialize(Serialization::IArchive& ar, Serialization::RadioButton& button, const char* name, const char* label)
{
if (ar.IsEdit())
{
return ar(Serialization::SStruct::ForEdit(button), name, label);
}
else
{
return false;
}
}
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_DECORATORS_TOGGLEBUTTONIMPL_H
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,103 @@
/*
* 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_EDITORCOMMON_SERIALIZATION_JSONIARCHIVE_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_JSONIARCHIVE_H
#pragma once
#include "Pointers.h"
#include "Serialization/IArchive.h"
#include "Serialization/MemoryReader.h"
#include "Token.h"
#include "EditorCommonAPI.h"
#include <memory>
#include <AzCore/std/string/string.h>
namespace Serialization {
class MemoryReader;
class JSONIArchive
: public IArchive
{
public:
JSONIArchive();
~JSONIArchive();
bool load(const char* filename);
bool open(const char* buffer, size_t length, bool free = false);
// virtuals:
bool operator()(bool& value, const char* name = "", const char* label = 0);
bool operator()(IString& value, const char* name = "", const char* label = 0);
bool operator()(IWString& value, const char* name = "", const char* label = 0);
bool operator()(float& value, const char* name = "", const char* label = 0);
bool operator()(double& value, const char* name = "", const char* label = 0);
bool operator()(int16& value, const char* name = "", const char* label = 0);
bool operator()(uint16& value, const char* name = "", const char* label = 0);
bool operator()(int32& value, const char* name = "", const char* label = 0);
bool operator()(uint32& value, const char* name = "", const char* label = 0);
bool operator()(int64& value, const char* name = "", const char* label = 0);
bool operator()(uint64& value, const char* name = "", const char* label = 0);
bool operator()(int8& value, const char* name = "", const char* label = 0);
bool operator()(uint8& value, const char* name = "", const char* label = 0);
bool operator()(char& value, const char* name = "", const char* label = 0);
bool operator()(const SStruct& ser, const char* name = "", const char* label = 0);
bool operator()(const SBlackBox& ser, const char* name = "", const char* label = 0);
bool operator()(IContainer& ser, const char* name = "", const char* label = 0);
bool operator()(IKeyValue& ser, const char* name = "", const char* label = 0);
bool operator()(IPointer& ser, const char* name = "", const char* label = 0);
using IArchive::operator();
private:
bool findName(const char* name, Token* outName = 0);
bool openBracket();
bool closeBracket();
bool openContainerBracket();
bool closeContainerBracket();
void checkValueToken();
bool checkStringValueToken();
void readToken();
void putToken();
int line(const char* position) const;
bool isName(Token token) const;
bool expect(char token);
void skipBlock();
struct Level
{
const char* start;
const char* firstToken;
bool isContainer;
bool isKeyValue;
Level()
: isContainer(false)
, isKeyValue(false) {}
};
typedef std::vector<Level> Stack;
Stack stack_;
std::unique_ptr<MemoryReader> reader_;
Token token_;
std::vector<char> unescapeBuffer_;
AZStd::string filename_;
void* buffer_;
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_JSONIARCHIVE_H
@@ -0,0 +1,828 @@
/*
* 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.
#include "EditorCommon_precompiled.h"
#include "JSONOArchive.h"
#include "MemoryWriter.h"
#include "Serialization/KeyValue.h"
#include "Serialization/ClassFactory.h"
#include "Serialization/BlackBox.h"
#include <float.h>
namespace Serialization {
// Some of non-latin1 characters here are not escaped to
// keep compatibility with 8-bit local encoding (e.g. windows-1251)
static const char* escapeTable[256] = {
"\\0" /* 0x00: */,
"\\x01" /* 0x01: */,
"\\x02" /* 0x02: */,
"\\x03" /* 0x03: */,
"\\x04" /* 0x04: */,
"\\x05" /* 0x05: */,
"\\x06" /* 0x06: */,
"\\x07" /* 0x07: */,
"\\x08" /* 0x08: */,
"\\t" /* 0x09: \t */,
"\\n" /* 0x0A: \n */,
"\\x0B" /* 0x0B: */,
"\\x0C" /* 0x0C: */,
"\\r" /* 0x0D: */,
"\\x0E" /* 0x0E: */,
"\\x0F" /* 0x0F: */,
"\\x10" /* 0x10: */,
"\\x11" /* 0x11: */,
"\\x12" /* 0x12: */,
"\\x13" /* 0x13: */,
"\\x14" /* 0x14: */,
"\\x15" /* 0x15: */,
"\\x16" /* 0x16: */,
"\\x17" /* 0x17: */,
"\\x18" /* 0x18: */,
"\\x19" /* 0x19: */,
"\\x1A" /* 0x1A: */,
"\\x1B" /* 0x1B: */,
"\\x1C" /* 0x1C: */,
"\\x1D" /* 0x1D: */,
"\\x1E" /* 0x1E: */,
"\\x1F" /* 0x1F: */,
" " /* 0x20: */,
"!" /* 0x21: ! */,
"\\\"" /* 0x22: " */,
"#" /* 0x23: # */,
"$" /* 0x24: $ */,
"%" /* 0x25: % */,
"&" /* 0x26: & */,
"'" /* 0x27: ' */,
"(" /* 0x28: ( */,
")" /* 0x29: ) */,
"*" /* 0x2A: * */,
"+" /* 0x2B: + */,
"," /* 0x2C: , */,
"-" /* 0x2D: - */,
"." /* 0x2E: . */,
"/" /* 0x2F: / */,
"0" /* 0x30: 0 */,
"1" /* 0x31: 1 */,
"2" /* 0x32: 2 */,
"3" /* 0x33: 3 */,
"4" /* 0x34: 4 */,
"5" /* 0x35: 5 */,
"6" /* 0x36: 6 */,
"7" /* 0x37: 7 */,
"8" /* 0x38: 8 */,
"9" /* 0x39: 9 */,
":" /* 0x3A: : */,
";" /* 0x3B: ; */,
"<" /* 0x3C: < */,
"=" /* 0x3D: = */,
">" /* 0x3E: > */,
"?" /* 0x3F: ? */,
"@" /* 0x40: @ */,
"A" /* 0x41: A */,
"B" /* 0x42: B */,
"C" /* 0x43: C */,
"D" /* 0x44: D */,
"E" /* 0x45: E */,
"F" /* 0x46: F */,
"G" /* 0x47: G */,
"H" /* 0x48: H */,
"I" /* 0x49: I */,
"J" /* 0x4A: J */,
"K" /* 0x4B: K */,
"L" /* 0x4C: L */,
"M" /* 0x4D: M */,
"N" /* 0x4E: N */,
"O" /* 0x4F: O */,
"P" /* 0x50: P */,
"Q" /* 0x51: Q */,
"R" /* 0x52: R */,
"S" /* 0x53: S */,
"T" /* 0x54: T */,
"U" /* 0x55: U */,
"V" /* 0x56: V */,
"W" /* 0x57: W */,
"X" /* 0x58: X */,
"Y" /* 0x59: Y */,
"Z" /* 0x5A: Z */,
"[" /* 0x5B: [ */,
"\\\\" /* 0x5C: \ */,
"]" /* 0x5D: ] */,
"^" /* 0x5E: ^ */,
"_" /* 0x5F: _ */,
"`" /* 0x60: ` */,
"a" /* 0x61: a */,
"b" /* 0x62: b */,
"c" /* 0x63: c */,
"d" /* 0x64: d */,
"e" /* 0x65: e */,
"f" /* 0x66: f */,
"g" /* 0x67: g */,
"h" /* 0x68: h */,
"i" /* 0x69: i */,
"j" /* 0x6A: j */,
"k" /* 0x6B: k */,
"l" /* 0x6C: l */,
"m" /* 0x6D: m */,
"n" /* 0x6E: n */,
"o" /* 0x6F: o */,
"p" /* 0x70: p */,
"q" /* 0x71: q */,
"r" /* 0x72: r */,
"s" /* 0x73: s */,
"t" /* 0x74: t */,
"u" /* 0x75: u */,
"v" /* 0x76: v */,
"w" /* 0x77: w */,
"x" /* 0x78: x */,
"y" /* 0x79: y */,
"z" /* 0x7A: z */,
"{" /* 0x7B: { */,
"|" /* 0x7C: | */,
"}" /* 0x7D: } */,
"~" /* 0x7E: ~ */,
"\x7F" /* 0x7F: */, // for utf-8
"\x80" /* 0x80: */,
"\x81" /* 0x81: */,
"\x82" /* 0x82: */,
"\x83" /* 0x83: */,
"\x84" /* 0x84: */,
"\x85" /* 0x85: */,
"\x86" /* 0x86: */,
"\x87" /* 0x87: */,
"\x88" /* 0x88: */,
"\x89" /* 0x89: */,
"\x8A" /* 0x8A: */,
"\x8B" /* 0x8B: */,
"\x8C" /* 0x8C: */,
"\x8D" /* 0x8D: */,
"\x8E" /* 0x8E: */,
"\x8F" /* 0x8F: */,
"\x90" /* 0x90: */,
"\x91" /* 0x91: */,
"\x92" /* 0x92: */,
"\x93" /* 0x93: */,
"\x94" /* 0x94: */,
"\x95" /* 0x95: */,
"\x96" /* 0x96: */,
"\x97" /* 0x97: */,
"\x98" /* 0x98: */,
"\x99" /* 0x99: */,
"\x9A" /* 0x9A: */,
"\x9B" /* 0x9B: */,
"\x9C" /* 0x9C: */,
"\x9D" /* 0x9D: */,
"\x9E" /* 0x9E: */,
"\x9F" /* 0x9F: */,
"\xA0" /* 0xA0: */,
"\xA1" /* 0xA1: */,
"\xA2" /* 0xA2: */,
"\xA3" /* 0xA3: */,
"\xA4" /* 0xA4: */,
"\xA5" /* 0xA5: */,
"\xA6" /* 0xA6: */,
"\xA7" /* 0xA7: */,
"\xA8" /* 0xA8: */,
"\xA9" /* 0xA9: */,
"\xAA" /* 0xAA: */,
"\xAB" /* 0xAB: */,
"\xAC" /* 0xAC: */,
"\xAD" /* 0xAD: */,
"\xAE" /* 0xAE: */,
"\xAF" /* 0xAF: */,
"\xB0" /* 0xB0: */,
"\xB1" /* 0xB1: */,
"\xB2" /* 0xB2: */,
"\xB3" /* 0xB3: */,
"\xB4" /* 0xB4: */,
"\xB5" /* 0xB5: */,
"\xB6" /* 0xB6: */,
"\xB7" /* 0xB7: */,
"\xB8" /* 0xB8: */,
"\xB9" /* 0xB9: */,
"\xBA" /* 0xBA: */,
"\xBB" /* 0xBB: */,
"\xBC" /* 0xBC: */,
"\xBD" /* 0xBD: */,
"\xBE" /* 0xBE: */,
"\xBF" /* 0xBF: */,
"\xC0" /* 0xC0: */,
"\xC1" /* 0xC1: */,
"\xC2" /* 0xC2: */,
"\xC3" /* 0xC3: */,
"\xC4" /* 0xC4: */,
"\xC5" /* 0xC5: */,
"\xC6" /* 0xC6: */,
"\xC7" /* 0xC7: */,
"\xC8" /* 0xC8: */,
"\xC9" /* 0xC9: */,
"\xCA" /* 0xCA: */,
"\xCB" /* 0xCB: */,
"\xCC" /* 0xCC: */,
"\xCD" /* 0xCD: */,
"\xCE" /* 0xCE: */,
"\xCF" /* 0xCF: */,
"\xD0" /* 0xD0: */,
"\xD1" /* 0xD1: */,
"\xD2" /* 0xD2: */,
"\xD3" /* 0xD3: */,
"\xD4" /* 0xD4: */,
"\xD5" /* 0xD5: */,
"\xD6" /* 0xD6: */,
"\xD7" /* 0xD7: */,
"\xD8" /* 0xD8: */,
"\xD9" /* 0xD9: */,
"\xDA" /* 0xDA: */,
"\xDB" /* 0xDB: */,
"\xDC" /* 0xDC: */,
"\xDD" /* 0xDD: */,
"\xDE" /* 0xDE: */,
"\xDF" /* 0xDF: */,
"\xE0" /* 0xE0: */,
"\xE1" /* 0xE1: */,
"\xE2" /* 0xE2: */,
"\xE3" /* 0xE3: */,
"\xE4" /* 0xE4: */,
"\xE5" /* 0xE5: */,
"\xE6" /* 0xE6: */,
"\xE7" /* 0xE7: */,
"\xE8" /* 0xE8: */,
"\xE9" /* 0xE9: */,
"\xEA" /* 0xEA: */,
"\xEB" /* 0xEB: */,
"\xEC" /* 0xEC: */,
"\xED" /* 0xED: */,
"\xEE" /* 0xEE: */,
"\xEF" /* 0xEF: */,
"\xF0" /* 0xF0: */,
"\xF1" /* 0xF1: */,
"\xF2" /* 0xF2: */,
"\xF3" /* 0xF3: */,
"\xF4" /* 0xF4: */,
"\xF5" /* 0xF5: */,
"\xF6" /* 0xF6: */,
"\xF7" /* 0xF7: */,
"\xF8" /* 0xF8: */,
"\xF9" /* 0xF9: */,
"\xFA" /* 0xFA: */,
"\xFB" /* 0xFB: */,
"\xFC" /* 0xFC: */,
"\xFD" /* 0xFD: */,
"\xFE" /* 0xFE: */,
"\xFF" /* 0xFF: */
};
static void escapeString(MemoryWriter& dest, const char* begin, const char* end)
{
while (begin != end)
{
const char* str = escapeTable[(unsigned char)(*begin)];
dest.write(str);
++begin;
}
}
// ---------------------------------------------------------------------------
static const int TAB_WIDTH = 2;
JSONOArchive::JSONOArchive(int textWidth, const char* header)
: IArchive(OUTPUT | TEXT)
, header_(header)
, textWidth_(textWidth)
, compactOffset_(0)
{
buffer_.reset(new MemoryWriter(1024, true));
if (header_)
{
(*buffer_) << header_;
}
YASLI_ASSERT(stack_.empty());
stack_.push_back(Level(false, 0, 0));
}
JSONOArchive::~JSONOArchive()
{
}
bool JSONOArchive::save(const char* fileName)
{
YASLI_ESCAPE(fileName && strlen(fileName) > 0, return false);
YASLI_ESCAPE(stack_.size() == 1, return false);
YASLI_ESCAPE(buffer_.get() != 0, return false);
YASLI_ESCAPE(buffer_->position() <= buffer_->size(), return false);
stack_.pop_back();
FILE* file = nullptr;
azfopen(&file, fileName, "wb");
if (file)
{
if (fwrite(buffer_->c_str(), 1, buffer_->position(), file) != buffer_->position())
{
fclose(file);
return false;
}
fclose(file);
return true;
}
else
{
return false;
}
}
const char* JSONOArchive::c_str() const
{
return buffer_->c_str();
}
size_t JSONOArchive::length() const
{
return buffer_->position();
}
void JSONOArchive::openBracket()
{
*buffer_ << "{";
}
void JSONOArchive::closeBracket()
{
*buffer_ << "}";
}
void JSONOArchive::openContainerBracket()
{
*buffer_ << "[";
}
void JSONOArchive::closeContainerBracket()
{
*buffer_ << "]";
}
void JSONOArchive::placeName(const char* name)
{
if (stack_.back().isKeyValue)
{
return;
}
if ((name[0] != '\0' || !stack_.back().isContainer) && stack_.size() > 1)
{
*buffer_ << "\"";
*buffer_ << name;
*buffer_ << "\": ";
stack_.back().nameIndex += 1;
}
}
void JSONOArchive::placeIndent(bool putComma)
{
if (stack_.back().isKeyValue)
{
return;
}
if (putComma && stack_.back().elementIndex > 0)
{
*buffer_ << ",";
}
if (buffer_->position() > 0)
{
*buffer_ << "\n";
}
int count = int(stack_.size() - 1);
stack_.back().indentCount += count;
stack_.back().elementIndex += 1;
for (int i = 0; i < count; ++i)
{
*buffer_ << "\t";
}
compactOffset_ = 0;
}
void JSONOArchive::placeIndentCompact(bool putComma)
{
if (stack_.back().isKeyValue)
{
return;
}
if (putComma && stack_.back().elementIndex > 0)
{
*buffer_ << ",";
}
if ((compactOffset_ % 32) != 0 && stack_.back().isContainer)
{
*buffer_ << " ";
compactOffset_ += 1;
stack_.back().elementIndex += 1;
}
else if (buffer_->size())
{
*buffer_ << "\n";
int count = int(stack_.size() - 1);
stack_.back().indentCount += count /* * TAB_WIDTH*/;
stack_.back().elementIndex += 1;
for (int i = 0; i < count; ++i)
{
*buffer_ << "\t";
}
compactOffset_ = 1;
}
}
bool JSONOArchive::operator()(bool& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndent();
placeName(name);
*buffer_ << (value ? "true" : "false");
return true;
}
bool JSONOArchive::operator()(IString& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndent();
placeName(name);
(*buffer_) << "\"";
const char* str = value.get();
escapeString(*buffer_, str, str + strlen(value.get()));
(*buffer_) << "\"";
return true;
}
inline char* writeUtf16ToUtf8(char* s, unsigned int ch)
{
const unsigned char byteMark = 0x80;
const unsigned char byteMask = 0xBF;
size_t len;
if (ch < 0x80)
{
len = 1;
}
else if (ch < 0x800)
{
len = 2;
}
else if (ch < 0x10000)
{
len = 3;
}
else if (ch < 0x200000)
{
len = 4;
}
else
{
return s;
}
s += len;
const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
switch (len)
{
case 4:
*--s = (char)((ch | byteMark) & byteMask);
ch >>= 6;
case 3:
*--s = (char)((ch | byteMark) & byteMask);
ch >>= 6;
case 2:
*--s = (char)((ch | byteMark) & byteMask);
ch >>= 6;
case 1:
*--s = (char)(ch | firstByteMark[len]);
}
return s + len;
}
bool JSONOArchive::operator()(IWString& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndent();
placeName(name);
(*buffer_) << "\"";
const wchar_t* in = value.get();
for (; *in; ++in)
{
char buf[6];
escapeString(*buffer_, buf, writeUtf16ToUtf8(buf, *in));
}
(*buffer_) << "\"";
return true;
}
bool JSONOArchive::operator()(float& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(double& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(int32& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(uint32& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(int16& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(uint16& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(int64& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(uint64& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(uint8& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(int8& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(char& value, const char* name, [[maybe_unused]] const char* label)
{
placeIndentCompact();
placeName(name);
(*buffer_) << value;
return true;
}
bool JSONOArchive::operator()(const SStruct& ser, const char* name, [[maybe_unused]] const char* label)
{
placeIndent();
placeName(name);
std::size_t position = buffer_->position();
openBracket();
stack_.push_back(Level(false, position, int(strlen(name) + 2 * (name[0] & 1) + (stack_.size() - 1) * TAB_WIDTH + 2)));
YASLI_ASSERT(ser);
ser(*this);
bool joined = joinLinesIfPossible();
bool noNames = stack_.back().nameIndex == 0;
if (noNames)
{
if (stack_.size() != 2)
{
buffer_->buffer()[stack_.back().startPosition] = '[';
}
}
stack_.pop_back();
if (!joined)
{
placeIndent(false);
}
else
{
*buffer_ << " ";
}
if (noNames)
{
closeContainerBracket();
}
else
{
closeBracket();
}
return true;
}
bool JSONOArchive::operator()(const SBlackBox& box, const char* name, [[maybe_unused]] const char* label)
{
if (strcmp(box.format, "json") != 0)
{
return false;
}
if (box.size == 0)
{
return false;
}
placeIndent();
placeName(name);
return buffer_->write(box.data, box.size);
}
bool JSONOArchive::operator()(IKeyValue& keyValue, [[maybe_unused]] const char* name, [[maybe_unused]] const char* label)
{
placeIndent();
*buffer_ << "\"";
*buffer_ << keyValue.get();
*buffer_ << "\": ";
stack_.back().nameIndex += 1;
stack_.back().isKeyValue = true;
keyValue.serializeValue(*this, "", 0);
stack_.back().isKeyValue = false;
if (stack_.back().isContainer)
{
stack_.back().isDictionary = true;
}
return true;
}
bool JSONOArchive::operator()(IPointer& ser, const char* name, [[maybe_unused]] const char* label)
{
placeIndent();
placeName(name);
openBracket();
const char* registeredTypeName = ser.registeredTypeName();
if (registeredTypeName && registeredTypeName[0] != '\0')
{
*buffer_ << " ";
placeName(registeredTypeName);
stack_.back().isKeyValue = true;
operator()(ser.serializer(), "");
stack_.back().isKeyValue = false;
*buffer_ << " ";
}
closeBracket();
return true;
}
bool JSONOArchive::operator()(IContainer& ser, const char* name, [[maybe_unused]] const char* label)
{
placeIndent();
placeName(name);
std::size_t position = buffer_->position();
openContainerBracket();
stack_.push_back(Level(true, position, int(strlen(name) + 2 * (name[0] & 1) + stack_.size() - 1 * TAB_WIDTH + 2)));
std::size_t size = ser.size();
if (size > 0)
{
do
{
ser(*this, "", "");
} while (ser.next());
}
bool joined = joinLinesIfPossible();
bool isDictionary = stack_.back().isDictionary;
if (isDictionary)
{
buffer_->buffer()[stack_.back().startPosition] = '{';
}
stack_.pop_back();
if (!joined)
{
placeIndent(false);
}
else
{
*buffer_ << " ";
}
if (isDictionary)
{
closeBracket();
}
else
{
closeContainerBracket();
}
return true;
}
static char* joinLines(char* start, char* end)
{
YASLI_ASSERT(start <= end);
char* next = start;
while (next != end)
{
if (*next != '\t' && *next != '\r')
{
if (*next != '\n')
{
*start = *next;
}
else
{
*start = ' ';
}
++start;
}
++next;
}
return start;
}
bool JSONOArchive::joinLinesIfPossible()
{
YASLI_ASSERT(!stack_.empty());
std::size_t startPosition = stack_.back().startPosition;
YASLI_ASSERT(startPosition < buffer_->size());
int indentCount = stack_.back().indentCount;
//YASLI_ASSERT(startPosition >= indentCount);
if (buffer_->position() - startPosition - indentCount < std::size_t(textWidth_))
{
char* buffer = buffer_->buffer();
char* start = buffer + startPosition;
char* end = buffer + buffer_->position();
end = joinLines(start, end);
std::size_t newPosition = end - buffer;
YASLI_ASSERT(newPosition <= buffer_->position());
buffer_->setPosition(newPosition);
return true;
}
return false;
}
}
// vim:ts=4 sw=4:
@@ -0,0 +1,108 @@
/*
* 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_EDITORCOMMON_SERIALIZATION_JSONOARCHIVE_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_JSONOARCHIVE_H
#pragma once
#include "Serialization/IArchive.h"
#include "Serialization/MemoryWriter.h"
#include "EditorCommonAPI.h"
#include <memory>
namespace Serialization {
class MemoryWriter;
class JSONOArchive
: public IArchive
{
public:
// header = 0 - default header, use "" to omit
JSONOArchive(int textWidth = 80, const char* header = 0);
~JSONOArchive();
bool save(const char* fileName);
const char* c_str() const;
const char* buffer() const { return c_str(); }
size_t length() const;
// from Archive:
bool operator()(bool& value, const char* name = "", const char* label = 0);
bool operator()(IString& value, const char* name = "", const char* label = 0);
bool operator()(IWString& value, const char* name = "", const char* label = 0);
bool operator()(float& value, const char* name = "", const char* label = 0);
bool operator()(double& value, const char* name = "", const char* label = 0);
bool operator()(int16& value, const char* name = "", const char* label = 0);
bool operator()(uint16& value, const char* name = "", const char* label = 0);
bool operator()(int32& value, const char* name = "", const char* label = 0);
bool operator()(uint32& value, const char* name = "", const char* label = 0);
bool operator()(int64& value, const char* name = "", const char* label = 0);
bool operator()(uint64& value, const char* name = "", const char* label = 0);
bool operator()(char& value, const char* name = "", const char* label = 0);
bool operator()(int8& value, const char* name = "", const char* label = 0);
bool operator()(uint8& value, const char* name = "", const char* label = 0);
bool operator()(const SStruct& ser, const char* name = "", const char* label = 0);
bool operator()(const SBlackBox& box, const char* name = "", const char* label = 0);
bool operator()(IContainer& ser, const char* name = "", const char* label = 0);
bool operator()(IKeyValue& keyValue, const char* name = "", const char* label = 0);
bool operator()(IPointer& ser, const char* name = "", const char* label = 0);
// ^^^
using IArchive::operator();
private:
void openBracket();
void closeBracket();
void openContainerBracket();
void closeContainerBracket();
void placeName(const char* name);
void placeIndent(bool putComma = true);
void placeIndentCompact(bool putComma = true);
bool joinLinesIfPossible();
struct Level
{
Level(bool _isContainer, std::size_t position, int column)
: isContainer(_isContainer)
, isKeyValue(false)
, isDictionary(false)
, startPosition(position)
, indentCount(-column)
, elementIndex(0)
, nameIndex(0)
{}
bool isKeyValue;
bool isContainer;
bool isDictionary;
std::size_t startPosition;
int nameIndex;
int elementIndex;
int indentCount;
};
typedef std::vector<Level> Stack;
Stack stack_;
std::unique_ptr<MemoryWriter> buffer_;
const char* header_;
int textWidth_;
string fileName_;
int compactOffset_;
bool isKeyValue_;
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_JSONOARCHIVE_H
@@ -0,0 +1,92 @@
/*
* 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.
#include "EditorCommon_precompiled.h"
#include <platform.h>
#include "Serialization/Assert.h"
#include "MemoryReader.h"
#include <stdlib.h>
#include <memory.h>
namespace Serialization {
MemoryReader::MemoryReader()
: size_(0)
, position_(0)
, memory_(0)
, ownedMemory_(false)
{
}
MemoryReader::MemoryReader(const void* memory, std::size_t size, bool ownAndFree)
: size_(size)
, position_((const char*)(memory))
, memory_((const char*)(memory))
, ownedMemory_(ownAndFree)
{
}
MemoryReader::~MemoryReader()
{
if (ownedMemory_)
{
free(const_cast<char*>(memory_));
memory_ = 0;
size_ = 0;
}
}
void MemoryReader::setPosition(const char* position)
{
position_ = position;
}
void MemoryReader::read(void* data, std::size_t size)
{
YASLI_ASSERT(memory_ && position_);
YASLI_ASSERT(position_ - memory_ + size <= size_);
memcpy(data, position_, size);
position_ += size;
}
bool MemoryReader::checkedRead(void* data, std::size_t size)
{
if (!memory_ || !position_)
{
return false;
}
if (position_ - memory_ + size > size_)
{
return false;
}
memcpy(data, position_, size);
position_ += size;
return true;
}
bool MemoryReader::checkedSkip(std::size_t size)
{
if (!memory_ || !position_)
{
return false;
}
if (position_ - memory_ + size > size_)
{
return false;
}
position_ += size;
return true;
}
}
@@ -0,0 +1,62 @@
/*
* 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_EDITORCOMMON_SERIALIZATION_MEMORYREADER_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_MEMORYREADER_H
#pragma once
#include <cstddef>
namespace Serialization {
class MemoryReader
{
public:
MemoryReader();
MemoryReader(const void* memory, size_t size, bool ownAndFree = false);
~MemoryReader();
void setPosition(const char* position);
const char* position() { return position_; }
template<class T>
void read(T& value)
{
read(reinterpret_cast<void*>(&value), sizoef(value));
}
void read(void* data, size_t size);
bool checkedSkip(size_t size);
bool checkedRead(void* data, size_t size);
template<class T>
bool checkedRead(T& t)
{
return checkedRead((void*)&t, sizeof(t));
}
const char* buffer() const { return memory_; }
size_t size() const { return size_; }
const char* begin() const { return memory_; }
const char* end() const { return memory_ + size_; }
private:
size_t size_;
const char* position_;
const char* memory_;
bool ownedMemory_;
};
}
// vim:ts=4 sw=4:
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_MEMORYREADER_H
@@ -0,0 +1,275 @@
/*
* 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.
#include "EditorCommon_precompiled.h"
#include <platform.h>
#include "Serialization/Assert.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#ifdef _MSC_VER
# include <float.h>
# define isnan _isnan
#endif
#include "MemoryWriter.h"
#undef YASLI_ASSERT
#define YASLI_ASSERT(x)
namespace Serialization {
MemoryWriter::MemoryWriter(std::size_t size, bool reallocate)
: size_(size)
, reallocate_(reallocate)
, digits_(5)
{
allocate(size);
}
MemoryWriter::~MemoryWriter()
{
position_ = 0;
free(memory_);
}
void MemoryWriter::allocate(std::size_t initialSize)
{
memory_ = (char*)malloc(initialSize + 1);
position_ = memory_;
}
void MemoryWriter::reallocate(std::size_t newSize)
{
YASLI_ASSERT(newSize > size_);
std::size_t pos = position();
memory_ = (char*)realloc(memory_, newSize + 1);
YASLI_ASSERT(memory_ != 0);
position_ = memory_ + pos;
size_ = newSize;
}
MemoryWriter& MemoryWriter::operator<<(int value)
{
// TODO: optimize
char buffer[12];
sprintf_s(buffer, "%i", value);
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(long value)
{
// TODO: optimize
char buffer[12];
#ifdef _MSC_VER
sprintf_s(buffer, "%i", value);
#else
sprintf_s(buffer, "%li", value);
#endif
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(unsigned long value)
{
// TODO: optimize
char buffer[12];
#ifdef _MSC_VER
sprintf_s(buffer, "%u", value);
#else
sprintf_s(buffer, "%lu", value);
#endif
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(long long value)
{
// TODO: optimize
char buffer[24];
#ifdef _MSC_VER
sprintf_s(buffer, "%I64i", value);
#else
sprintf_s(buffer, "%lli", value);
#endif
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(unsigned long long value)
{
// TODO: optimize
char buffer[24];
#ifdef _MSC_VER
sprintf_s(buffer, "%I64u", value);
#else
sprintf_s(buffer, "%llu", value);
#endif
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(unsigned int value)
{
// TODO: optimize
char buffer[12];
sprintf_s(buffer, "%u", value);
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(char value)
{
char buffer[12];
sprintf_s(buffer, "%i", int(value));
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(unsigned char value)
{
char buffer[12];
sprintf_s(buffer, "%i", int(value));
return operator<<((const char*)buffer);
}
MemoryWriter& MemoryWriter::operator<<(signed char value)
{
char buffer[12];
sprintf_s(buffer, "%i", int(value));
return operator<<((const char*)buffer);
}
inline void cutRightZeros(const char* str)
{
for (char* p = (char*)str + strlen(str) - 1; p >= str; --p)
{
if (*p == '0')
{
*p = 0;
}
else
{
return;
}
}
}
MemoryWriter& MemoryWriter::operator<<(double value)
{
// YASLI_ASSERT(!isnan(value)); disabled, because physics data is not always initialized
int point = 0;
int sign = 0;
#ifdef _MSC_VER
char buf[_CVTBUFSIZE];
_fcvt_s(buf, value, digits_, &point, &sign);
#else
const char* buf = fcvt(value, digits_, &point, &sign);
#endif
if (sign != 0)
{
write("-");
}
if (point <= 0)
{
cutRightZeros(buf);
if (strlen(buf))
{
write("0.");
while (point < 0)
{
write("0");
++point;
}
write(buf);
}
else
{
write("0");
}
*position_ = '\0';
}
else
{
write(buf, point);
write(".");
cutRightZeros(buf + point);
operator<<(buf + point);
}
return *this;
}
MemoryWriter& MemoryWriter::operator<<(const char* value)
{
write((void*)value, strlen(value));
YASLI_ASSERT(position() < size());
*position_ = '\0';
return *this;
}
MemoryWriter& MemoryWriter::operator<<(const wchar_t* value)
{
write((void*)value, wcslen(value) * sizeof(wchar_t));
YASLI_ASSERT(position() < size());
*position_ = '\0';
return *this;
}
void MemoryWriter::setPosition(std::size_t pos)
{
YASLI_ASSERT(pos < size_);
YASLI_ASSERT(memory_ + pos <= position_);
position_ = memory_ + pos;
}
void MemoryWriter::write(const char* value)
{
write((void*)value, strlen(value));
}
bool MemoryWriter::write(const void* data, std::size_t size)
{
YASLI_ASSERT(memory_ <= position_);
YASLI_ASSERT(position() < this->size());
if (size_ - position() > size)
{
memcpy(position_, data, size);
position_ += size;
}
else
{
if (!reallocate_)
{
return false;
}
reallocate(size_ * 2);
write(data, size);
}
YASLI_ASSERT(position() < this->size());
return true;
}
void MemoryWriter::write(char c)
{
if (size_ - position() > 1)
{
*(char*)(position_) = c;
++position_;
}
else
{
YASLI_ESCAPE(reallocate_, return );
reallocate(size_ * 2);
write(c);
}
YASLI_ASSERT(position() < this->size());
}
}
@@ -0,0 +1,80 @@
/*
* 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_EDITORCOMMON_SERIALIZATION_MEMORYWRITER_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_MEMORYWRITER_H
#pragma once
#include <cstddef>
#include "Pointers.h"
#include "EditorCommonAPI.h"
namespace Serialization {
class MemoryWriter
: public RefCounter
{
public:
MemoryWriter(std::size_t size = 128, bool reallocate = true);
~MemoryWriter();
const char* c_str() { return memory_; };
const wchar_t* w_str() { return (wchar_t*)memory_; };
char* buffer() { return memory_; }
const char* buffer() const { return memory_; }
std::size_t size() const{ return size_; }
void clear() { position_ = memory_; }
// String interface (after this calls '\0' is always written)
MemoryWriter& operator<<(int value);
MemoryWriter& operator<<(long value);
MemoryWriter& operator<<(unsigned long value);
MemoryWriter& operator<<(unsigned int value);
MemoryWriter& operator<<(long long value);
MemoryWriter& operator<<(unsigned long long value);
MemoryWriter& operator<<(float value) { return (*this) << double(value); }
MemoryWriter& operator<<(double value);
MemoryWriter& operator<<(signed char value);
MemoryWriter& operator<<(unsigned char value);
MemoryWriter& operator<<(char value);
MemoryWriter& operator<<(const char* value);
MemoryWriter& operator<<(const wchar_t* value);
// Binary interface (does not writes trailing '\0')
template<class T>
void write(const T& value)
{
write(reinterpret_cast<const T*>(&value), sizeof(value));
}
void write(char c);
void write(const char* str);
bool write(const void* data, std::size_t size);
std::size_t position() const { return position_ - memory_; }
void setPosition(std::size_t pos);
MemoryWriter& setDigits(int digits) { digits_ = (unsigned char)digits; return *this; }
private:
void allocate(std::size_t initialSize);
void reallocate(std::size_t newSize);
std::size_t size_;
char* position_;
char* memory_;
bool reallocate_;
unsigned char digits_;
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_MEMORYWRITER_H
@@ -0,0 +1,265 @@
/*
* 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_EDITORCOMMON_SERIALIZATION_POINTERS_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_POINTERS_H
#pragma once
#include "Serialization/Assert.h"
namespace Serialization {
class RefCounter
{
public:
RefCounter()
: refCounter_(0)
{}
~RefCounter() {};
int refCount() const { return refCounter_; }
void acquire() { ++refCounter_; }
int release() { return --refCounter_; }
private:
int refCounter_;
};
class PolyRefCounter
: public RefCounter
{
public:
virtual ~PolyRefCounter() {}
};
class PolyPtrBase
{
public:
PolyPtrBase()
: ptr_(0)
{
}
void release()
{
if (ptr_)
{
if (!ptr_->release())
{
delete ptr_;
}
ptr_ = 0;
}
}
void set(PolyRefCounter* const ptr)
{
if (ptr_ != ptr)
{
release();
ptr_ = ptr;
if (ptr_)
{
ptr_->acquire();
}
}
}
protected:
PolyRefCounter* ptr_;
};
template<class T>
class PolyPtr
: public PolyPtrBase
{
public:
PolyPtr()
: PolyPtrBase()
{
}
PolyPtr(PolyRefCounter* ptr)
{
set(ptr);
}
template<class U>
PolyPtr(U* ptr)
{
// TODO: replace with static_assert
YASLI_ASSERT("PolyRefCounter must be a first base when used with multiple inheritance." &&
static_cast<PolyRefCounter*>(ptr) == reinterpret_cast<PolyRefCounter*>(ptr));
set(static_cast<PolyRefCounter*>(ptr));
}
PolyPtr(const PolyPtr& ptr)
: PolyPtrBase()
{
set(ptr.ptr_);
}
~PolyPtr()
{
release();
}
operator T*() const {
return get();
}
template<class U>
operator PolyPtr<U>() const {
return PolyPtr<U>(get());
}
operator bool() const {
return ptr_ != 0;
}
PolyPtr& operator=(const PolyPtr& ptr)
{
set(ptr.ptr_);
return *this;
}
T* get() const { return reinterpret_cast<T*>(ptr_); }
T& operator*() const
{
return *get();
}
T* operator->() const { return get(); }
};
class IArchive;
template<class T>
class SharedPtr
{
public:
SharedPtr()
: ptr_(0) {}
SharedPtr(T* const ptr)
: ptr_(0)
{
set(ptr);
}
SharedPtr(const SharedPtr& ptr)
: ptr_(0)
{
set(ptr.ptr_);
}
~SharedPtr()
{
release();
}
operator T*() const {
return get();
}
template<class U>
operator SharedPtr<U>() const {
return SharedPtr<U>(get());
}
SharedPtr& operator=(const SharedPtr& ptr)
{
set(ptr.ptr_);
return *this;
}
T* get() { return ptr_; }
T* get() const { return ptr_; }
T& operator*()
{
return *get();
}
T* operator->() const { return get(); }
void release()
{
if (ptr_)
{
if (!ptr_->release())
{
delete ptr_;
}
ptr_ = 0;
}
}
template<class _T>
void set(_T* const ptr) { reset(ptr); }
template<class _T>
void reset(_T* const ptr)
{
if (ptr_ != ptr)
{
release();
ptr_ = ptr;
if (ptr_)
{
ptr_->acquire();
}
}
}
protected:
T* ptr_;
};
template<class T>
class AutoPtr
{
public:
AutoPtr()
: ptr_(0)
{
}
AutoPtr(T* ptr)
: ptr_(0)
{
set(ptr);
}
~AutoPtr()
{
release();
}
AutoPtr& operator=(T* ptr)
{
set(ptr);
return *this;
}
void set(T* ptr)
{
if (ptr_ && ptr_ != ptr)
{
release();
}
ptr_ = ptr;
}
T* get() const { return ptr_; }
operator T*() const {
return get();
}
void detach()
{
ptr_ = 0;
}
void release()
{
delete ptr_;
ptr_ = 0;
}
T& operator*() const { return *get(); }
T* operator->() const { return get(); }
private:
T* ptr_;
};
class IArchive;
}
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::SharedPtr<T>& ptr, const char* name, const char* label);
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::PolyPtr<T>& ptr, const char* name, const char* label);
#include <Serialization/PointersImpl.h>
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_POINTERS_H
@@ -0,0 +1,140 @@
/*
* 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_EDITORCOMMON_SERIALIZATION_POINTERSIMPL_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_POINTERSIMPL_H
#pragma once
#include "Pointers.h"
#include "Serialization/IClassFactory.h"
#include "Serialization/ClassFactory.h"
namespace Serialization {
template<class T>
class SharedPtrSerializer
: public IPointer
{
public:
SharedPtrSerializer(SharedPtr<T>& ptr)
: ptr_(ptr)
{}
const char* registeredTypeName() const
{
if (ptr_)
{
return ClassFactory<T>::the().getRegisteredTypeName(ptr_.get());
}
else
{
return "";
}
}
void create(const char* typeName) const
{
YASLI_ASSERT(!ptr_ || ptr_->refCount() == 1);
if (typeName && typeName[0] != '\0')
{
ptr_.set(factory()->create(typeName));
}
else
{
ptr_.set((T*)0);
}
}
TypeID baseType() const { return TypeID::get<T>(); }
virtual SStruct serializer() const
{
return SStruct(*ptr_);
}
void* get() const
{
return reinterpret_cast<void*>(ptr_.get());
}
const void* handle() const
{
return &ptr_;
}
TypeID pointerType() const
{
return TypeID::get<SharedPtr<T> >();
}
virtual ClassFactory<T>* factory() const{ return &ClassFactory<T>::the(); }
protected:
SharedPtr<T>& ptr_;
};
template<class T>
class PolyPtrSerializer
: public IPointer
{
public:
PolyPtrSerializer(PolyPtr<T>& ptr)
: ptr_(ptr)
{}
TypeID type() const
{
if (ptr_)
{
return TypeID::get(ptr_.get());
}
else
{
return TypeID();
}
}
void create(TypeID type) const
{
// YASLI_ASSERT(!ptr_ || ptr_->refCount() == 1); not necessary to be true
if (type)
{
ptr_.set(ClassFactory<T>::the().create(type));
}
else
{
ptr_.set((T*)0);
}
}
TypeID baseType() const { return TypeID::get<T>(); }
virtual SStruct serializer() const
{
return SStruct(*ptr_);
}
void* get() const
{
return reinterpret_cast<void*>(ptr_.get());
}
IClassFactory* factory() const { return &ClassFactory<T>::the(); }
protected:
PolyPtr<T>& ptr_;
};
}
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::SharedPtr<T>& ptr, const char* name, const char* label)
{
return ar(static_cast<Serialization::IPointer&>(Serialization::SharedPtrSerializer<T>(ptr)), name, label);
}
template<class T>
bool Serialize(Serialization::IArchive& ar, Serialization::PolyPtr<T>& ptr, const char* name, const char* label)
{
return ar(static_cast<Serialization::IPointer&>(Serialization::PolyPtrSerializer<T>(ptr)), name, label);
}
// vim:sw=4 ts=4:
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_POINTERSIMPL_H
@@ -0,0 +1,393 @@
/*
* 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.
#include "EditorCommon_precompiled.h"
#include "EditorCommonAPI.h"
#include "Serialization/Serializer.h"
#include "Serialization/Qt.h"
#include "Serialization/STL.h"
#include "Serialization/IArchive.h"
#include <QSplitter>
#include <QString>
#include <QTreeView>
#include <QHeaderView>
#include <QPalette>
class StringQt
: public Serialization::IWString
{
public:
StringQt(QString& str)
: str_(str) {}
void set(const wchar_t* value) { str_.setUnicode((const QChar*)value, (int)wcslen(value)); }
const wchar_t* get() const { return (wchar_t*)str_.data(); }
const void* handle() const { return &str_; }
Serialization::TypeID type() const{ return Serialization::TypeID::get<QString>(); }
private:
QString& str_;
};
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QString& value, const char* name, const char* label)
{
StringQt str(value);
return ar(static_cast<Serialization::IWString&>(str), name, label);
}
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QByteArray& byteArray, const char* name, const char* label)
{
std::vector<unsigned char> temp(byteArray.begin(), byteArray.end());
if (!ar(temp, name, label))
{
return false;
}
if (ar.IsInput())
{
byteArray = QByteArray(temp.empty() ? (char*)0 : (char*)&temp[0], (int)temp.size());
}
return true;
}
QString GetIndexPath(QAbstractItemModel* model, const QModelIndex& index)
{
QString path;
QModelIndex cur = index;
while (cur.isValid() && cur != QModelIndex())
{
if (!path.isEmpty())
{
path = QString("|") + path;
}
path = model->data(cur).toString() + path;
cur = model->parent(cur);
}
return path;
}
QModelIndex FindIndexChildByText(QAbstractItemModel* model, const QModelIndex& parent, const QString& text)
{
int rowCount = model->rowCount(parent);
for (int i = 0; i < rowCount; ++i)
{
QModelIndex child = model->index(i, 0, parent);
QString childText = model->data(child).toString();
if (childText == text)
{
return child;
}
}
return QModelIndex();
}
QModelIndex GetIndexByPath(QAbstractItemModel* model, const QString& path)
{
QStringList items = path.split('|');
QModelIndex cur = QModelIndex();
for (int i = 0; i < items.size(); ++i)
{
cur = FindIndexChildByText(model, cur, items[i]);
if (!cur.isValid())
{
return QModelIndex();
}
}
return cur;
}
std::vector<QString> GetIndexPaths(QAbstractItemModel* model, const QModelIndexList& indices)
{
std::vector<QString> result;
for (int i = 0; i < indices.size(); ++i)
{
QString path = GetIndexPath(model, indices[i]);
if (!path.isEmpty())
{
result.push_back(path);
}
}
return result;
}
QModelIndexList GetIndicesByPath(QAbstractItemModel* model, const std::vector<QString>& paths)
{
QModelIndexList result;
for (int i = 0; i < paths.size(); ++i)
{
QModelIndex index = GetIndexByPath(model, paths[i]);
if (index.isValid())
{
result.push_back(index);
}
}
return result;
}
struct QTreeViewStateSerializer
{
QTreeView* treeView;
QTreeViewStateSerializer(QTreeView* treeView)
: treeView(treeView) {}
void Serialize(Serialization::IArchive& ar)
{
QAbstractItemModel* model = treeView->model();
std::vector<QString> expandedItems;
if (ar.IsOutput())
{
std::vector<QModelIndex> stack;
stack.push_back(QModelIndex());
while (!stack.empty())
{
QModelIndex index = stack.back();
stack.pop_back();
int rowCount = model->rowCount(index);
for (int i = 0; i < rowCount; ++i)
{
QModelIndex child = model->index(i, 0, index);
if (treeView->isExpanded(child))
{
stack.push_back(child);
expandedItems.push_back(GetIndexPath(model, child));
}
}
}
}
ar(expandedItems, "expandedItems");
if (ar.IsInput())
{
treeView->collapseAll();
for (size_t i = 0; i < expandedItems.size(); ++i)
{
QModelIndex index = GetIndexByPath(model, expandedItems[i]);
if (index.isValid())
{
treeView->expand(index);
}
}
}
std::vector<QString> selectedItems;
if (ar.IsOutput())
{
selectedItems = GetIndexPaths(model, treeView->selectionModel()->selectedIndexes());
}
ar(selectedItems, "selectedItems");
if (ar.IsInput())
{
QModelIndexList indices = GetIndicesByPath(model, selectedItems);
if (!indices.empty())
{
treeView->selectionModel()->select(QModelIndex(), QItemSelectionModel::ClearAndSelect);
for (int i = 0; i < indices.size(); ++i)
{
treeView->selectionModel()->select(indices[i], QItemSelectionModel::Select);
}
}
}
QString currentItem;
if (ar.IsOutput())
{
currentItem = GetIndexPath(model, treeView->selectionModel()->currentIndex());
}
ar(currentItem, "currentItem");
if (ar.IsInput())
{
QModelIndex currentIndex = GetIndexByPath(model, currentItem);
treeView->scrollTo(currentIndex, QAbstractItemView::PositionAtCenter);
treeView->selectionModel()->setCurrentIndex(currentIndex, QItemSelectionModel::Current);
}
std::vector<int> sectionsHidden;
std::vector<int> sectionsVisible;
if (ar.IsOutput())
{
for (int i = 0; i < treeView->model()->columnCount(); ++i)
{
if (treeView->header()->isSectionHidden(i))
{
sectionsHidden.push_back(i);
}
else
{
sectionsVisible.push_back(i);
}
}
}
ar(sectionsHidden, "sectionsHidden");
ar(sectionsVisible, "sectionsVisible");
if (ar.IsInput())
{
int columnCount = treeView->model()->columnCount();
for (int i = 0; i < sectionsHidden.size(); ++i)
{
int section = sectionsHidden[i];
if (section >= 0 && section < columnCount)
{
treeView->header()->hideSection(section);
}
}
for (int i = 0; i < sectionsVisible.size(); ++i)
{
int section = sectionsVisible[i];
if (section >= 0 && section < columnCount)
{
treeView->header()->showSection(section);
}
}
}
}
};
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QTreeView* treeView, const char* name, const char* label)
{
return ar(QTreeViewStateSerializer(treeView), name, label);
}
static const char* g_paletteColorGroupNames[QPalette::NColorGroups] = {
"Active", "Disabled", "Inactive"
};
static const char* g_paletteColorRoleNames[QPalette::NColorRoles] = {
"WindowText", "Button", "Light", "Midlight", "Dark", "Mid",
"Text", "BrightText", "ButtonText", "Base", "Window", "Shadow",
"Highlight", "HighlightedText",
"Link", "LinkVisited",
"AlternateBase",
"NoRole",
"ToolTipBase", "ToolTipText",
#if !defined(AZ_PLATFORM_LINUX)
"PlaceholderText",
#endif // !defined(AZ_PLATFORM_LINUX)
};
struct QPaletteSerializable
{
QPalette& palette;
QPaletteSerializable(QPalette& palette)
: palette(palette)
{
}
struct SRole
{
int role;
QPalette& palette;
SRole(QPalette& palette, int role)
: palette(palette)
, role(role)
{
}
void Serialize(Serialization::IArchive& ar)
{
for (int group = 0; group < QPalette::NColorGroups; ++group)
{
QColor color = palette.color(QPalette::ColorGroup(group), QPalette::ColorRole(role));
ar(color, g_paletteColorGroupNames[group], g_paletteColorGroupNames[group]);
if (ar.IsInput())
{
palette.setColor(QPalette::ColorGroup(group), QPalette::ColorRole(role), color);
}
}
}
};
void Serialize(Serialization::IArchive& ar)
{
for (int roleIndex = 0; roleIndex < QPalette::NColorRoles; ++roleIndex)
{
SRole role(palette, roleIndex);
ar(role, g_paletteColorRoleNames[roleIndex], g_paletteColorRoleNames[roleIndex]);
}
}
};
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QPalette& palette, const char* name, const char* label)
{
QPaletteSerializable serializer(palette);
return ar(serializer, name, label);
}
struct QColorSerializable
{
QColor& color;
QColorSerializable(QColor& color)
: color(color) {}
void Serialize(Serialization::IArchive& ar)
{
// this is not comprehensive, as QColor can store color components
// in diffrent models, depending on the way they were specified
unsigned char r = color.red();
unsigned char g = color.green();
unsigned char b = color.blue();
unsigned char a = color.alpha();
ar(r, "r", "^R");
ar(g, "g", "^G");
ar(b, "b", "^B");
ar(a, "a", "^A");
if (ar.IsInput())
{
color.setRed(r);
color.setGreen(g);
color.setBlue(b);
color.setAlpha(a);
}
}
};
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QColor& color, const char* name, const char* label)
{
QColorSerializable serializer(color);
return ar(serializer, name, label);
}
struct QSplitterSerializer
{
QSplitter& splitter;
QSplitterSerializer(QSplitter& splitter)
: splitter(splitter) {}
void Serialize(Serialization::IArchive& ar)
{
QList<int> qsizes = splitter.sizes();
std::vector<int> sizes(qsizes.begin(), qsizes.end());
ar(sizes, "sizes", "Sizes");
if (ar.IsInput())
{
qsizes.clear();
for (int i = 0; i < sizes.size(); ++i)
{
qsizes.push_back(sizes[i]);
}
splitter.setSizes(qsizes);
}
}
};
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QSplitter* splitter, const char* name, const char* label)
{
if (!splitter)
{
return false;
}
QSplitterSerializer serializer(*splitter);
return ar(serializer, name, label);
}
@@ -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.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_EDITORCOMMON_SERIALIZATION_QT_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_QT_H
#pragma once
#include "EditorCommonAPI.h"
class QByteArray;
class QColor;
class QPalette;
class QSplitter;
class QString;
class QTreeView;
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QSplitter* splitter, const char* name, const char* label);
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QByteArray& value, const char* name, const char* label);
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QString& value, const char* name, const char* label);
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QTreeView* treeViewState, const char* name, const char* label);
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QPalette& palette, const char* name, const char* label);
bool EDITOR_COMMON_API Serialize(Serialization::IArchive& ar, QColor& color, const char* name, const char* label);
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_QT_H
@@ -0,0 +1,24 @@
/*
* 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_EDITORCOMMON_SERIALIZATION_QTIMPL_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_QTIMPL_H
#pragma once
#include "Serialization/Serializer.h"
namespace Serialization {
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_QTIMPL_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_EDITORCOMMON_SERIALIZATION_TOKEN_H
#define CRYINCLUDE_EDITORCOMMON_SERIALIZATION_TOKEN_H
#pragma once
#include <string.h>
#include "Serialization/Strings.h"
namespace Serialization {
struct Token
{
Token(const char* _str = 0)
: start(_str)
, end(_str ? _str + strlen(_str) : 0)
{
}
Token(const char* _str, size_t _len)
: start(_str)
, end(_str + _len) {}
Token(const char* _start, const char* _end)
: start(_start)
, end(_end) {}
void set(const char* _start, const char* _end) { start = _start; end = _end; }
std::size_t length() const{ return end - start; }
bool operator==(const Token& rhs) const
{
if (length() != rhs.length())
{
return false;
}
return memcmp(start, rhs.start, length()) == 0;
}
bool operator==(const string& rhs) const
{
if (length() != rhs.size())
{
return false;
}
return memcmp(start, rhs.c_str(), length()) == 0;
}
bool operator==(const char* text) const
{
if (strncmp(text, start, length()) == 0)
{
return text[length()] == '\0';
}
return false;
}
bool operator!=(const char* text) const
{
if (strncmp(text, start, length()) == 0)
{
return text[length()] != '\0';
}
return true;
}
bool operator==(char c) const
{
return length() == 1 && *start == c;
}
bool operator!=(char c) const
{
return length() != 1 || *start != c;
}
operator bool() const{
return start != end;
}
string str() const{ return string(start, end); }
const char* start;
const char* end;
};
}
#endif // CRYINCLUDE_EDITORCOMMON_SERIALIZATION_TOKEN_H
@@ -0,0 +1,49 @@
Portions based on WWidgets and Yasli Serialization Library
wWidgets - Lightweight UI Toolkit.
Copyright (C) 2009-2011 Evgeny Andreeshchev <eugene.andreeshchev@gmail.com>
Alexander Kotliar <alexander.kotliar@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Yasli Serialization Library
Copyright (c) 2007 Eugene Andreeshchev
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.