/* * 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. * */ #pragma once #include #include namespace Metastream { class DataCache { public: DataCache() {} void AddToCache(const std::string & tableName, const std::string & key, const char *value); void AddToCache(const std::string & tableName, const std::string & key, bool value); void AddToCache(const std::string & tableName, const std::string & key, const Vec3 &value); void AddToCache(const std::string & tableName, const std::string & key, double value); void AddToCache(const std::string & tableName, const std::string & key, AZ::u64 value); void AddToCache(const std::string & tableName, const std::string & key, AZ::s64 value); void AddToArray(const std::string & tableName, const std::string & arrayName, const char* value); void AddToArray(const std::string & tableName, const std::string & arrayName, bool value); void AddToArray(const std::string & tableName, const std::string & arrayName, const Vec3 & value); void AddToArray(const std::string & tableName, const std::string & arrayName, double value); void AddToArray(const std::string & tableName, const std::string & arrayName, AZ::u64 value); void AddToArray(const std::string & tableName, const std::string & arrayName, AZ::s64 value); void AddToObject(const std::string & tableName, const std::string & objName, const std::string & key, const char* value); void AddToObject(const std::string & tableName, const std::string & objName, const std::string & key, bool value); void AddToObject(const std::string & tableName, const std::string & objName, const std::string & key, const Vec3 & value); void AddToObject(const std::string & tableName, const std::string & objName, const std::string & key, double value); void AddToObject(const std::string & tableName, const std::string & objName, const std::string & key, AZ::u64 value); void AddToObject(const std::string & tableName, const std::string & objName, const std::string & key, AZ::s64 value); void AddArrayToCache(const std::string & tableName, const std::string & key, const std::string & arrayName); void AddObjectToCache(const std::string & tableName, const std::string & key, const std::string & objectName); void AddArrayToObject(const std::string & tableName, const std::string & destObjName, const std::string & key, const std::string & srcArrayName); void AddObjectToArray(const std::string & tableName, const std::string & destArrayName, const std::string & srcObjectName); void AddObjectToObject(const std::string & tableName, const std::string & destObjName, const std::string & key, const std::string & srcObjName); std::string GetDatabasesJSON() const; std::string GetTableKeysJSON(const std::string& tableName) const; std::string GetTableKeyValuesJSON(const std::string& tableName, const std::vector& keyList) const; void ClearCache(); private: class Document { public: Document(); virtual ~Document(); std::string GetKeysJSON() const; std::string GetKeyValuesJSON(const std::vector& keyList) const; std::string GetJSON() const; void Add(const std::string & key, rapidjson::Value & value); void AddToArray(const std::string & arrayName, rapidjson::Value & value); void AddToObject(const std::string & objName, const std::string & keyName, rapidjson::Value & value); void AddArray(const std::string & key, const std::string & arrayName); void AddObject(const std::string & key, const std::string & objectName); void AddArrayToObject(const std::string & destObjName, const std::string & key, const std::string & srcArrayName); void AddObjectToObject(const std::string & destObjName, const std::string & key, const std::string & srcObjName); void AddObjectToArray(const std::string & destArrayName, const std::string & srcObjectName); rapidjson::Value ToJson(const std::string & value); rapidjson::Value ToJson(const char * value); rapidjson::Value ToJson(bool value); rapidjson::Value ToJson(const Vec3 & value); rapidjson::Value ToJson(double value); rapidjson::Value ToJson(AZ::u64 value); rapidjson::Value ToJson(AZ::s64 value); private: typedef std::shared_ptr rapidJsonValuePtr; typedef std::map JsonValueMap; enum class ValueType {Array, Object}; rapidJsonValuePtr FindValue(const std::string & name, ValueType type); void RemoveValue(const std::string &objectName, ValueType type); private: mutable AZStd::mutex m_mutex; mutable AZStd::mutex m_mutexJsonArray; rapidjson::Document m_jsonDoc; rapidjson::Document::AllocatorType & m_allocator; JsonValueMap m_jsonValues; }; typedef std::shared_ptr DocumentPtr; typedef std::map Database; DocumentPtr FindDoc(const std::string & tableName); private: mutable AZStd::mutex m_mutexDatabase; Database m_database; }; } // namespace Metastream