Add GetWorld to Actor. Integrate google test. Add Model manager class. Rename *.h to *.hpp files
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include "IResource.hpp"
|
||||
#include <mutex>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
class Resource final
|
||||
{
|
||||
static std::mutex mStringResource;
|
||||
static const char* StringResources;
|
||||
|
||||
static std::mutex mIntResource;
|
||||
static const char* IntResources;
|
||||
|
||||
static std::mutex mLongResource;
|
||||
static const char* LongResources;
|
||||
|
||||
static std::mutex mDoubleResource;
|
||||
static const char* DoubleResources;
|
||||
|
||||
static std::mutex mObjectResource;
|
||||
static const char* ObjectResources;
|
||||
|
||||
// throw: std::runtime_error("Can't find resource") если ресурса не существует
|
||||
static std::string GetResourceData(const char* name, const char* file_name);
|
||||
|
||||
static void WriteResource(const char* name, const char* file_name, const std::string& value);
|
||||
|
||||
public:
|
||||
/*
|
||||
* Устанавливает значение в ресурс
|
||||
* Не бросают исключений
|
||||
*/
|
||||
static void SetString(const char* name, const char* value);
|
||||
static void SetInt(const char* name, int value);
|
||||
static void SetLong(const char* name, long long value);
|
||||
static void SetDouble(const char* name, double value);
|
||||
static void SetObject(const char* name, IResource* object);
|
||||
|
||||
/*
|
||||
* Метуды получения значений по ключу
|
||||
* throw: std::runtime_error("Can't find resource") если ресурса не существует
|
||||
*/
|
||||
static std::string GetString(const char* name);
|
||||
static int GetInt(const char* name);
|
||||
static long long GetLong(const char* name);
|
||||
static double GetDouble(const char* name);
|
||||
template<class T>
|
||||
static T* GetObject(const char* name)
|
||||
{
|
||||
mObjectResource.lock();
|
||||
std::string data = GetResourceData(name, ObjectResources);
|
||||
mObjectResource.unlock();
|
||||
T* object = new T();
|
||||
object->deserialize(data);
|
||||
return object;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user