Commit 4a55e973 authored by Bkg2k's avatar Bkg2k

New metadata storage classes

parent 6141b48e
......@@ -5,6 +5,8 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/FileData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/FileSorts.h
${CMAKE_CURRENT_SOURCE_DIR}/src/MetaData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/MetadataDescriptor.h
${CMAKE_CURRENT_SOURCE_DIR}/src/MetadataFieldDescriptor.h
${CMAKE_CURRENT_SOURCE_DIR}/src/PlatformId.h
${CMAKE_CURRENT_SOURCE_DIR}/src/ScraperCmdLine.h
${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.h
......@@ -65,6 +67,8 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MameNameMap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MetaData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MetadataDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/MetadataFieldDescriptor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/PlatformId.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ScraperCmdLine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SystemData.cpp
......
This diff is collapsed.
This diff is collapsed.
//
// Created by bkg2k on 5/29/18.
//
#include "MetadataFieldDescriptor.h"
#pragma once
#include <string>
#include <stdexcept>
#include "MetadataDescriptor.h"
//! Method pointer to default value getters
typedef bool (MetadataDescriptor::*IsDefaultValueMethodType)() const;
//! Method pointer to string getters
typedef std::string (MetadataDescriptor::*GetValueMethodType)() const;
//! Method pointer to string setters
typedef void (MetadataDescriptor::*SetValueMethodType)(const std::string& value);
class MetadataFieldDescriptor
{
public:
//! Data type
enum class DataType
{
// Simple types
String, //!< std::string
PString, //!< Pointer to std::string
Int, //!< int
Bool, //!< bool
Float, //!< float
// Derived types
Text, //!< Multiline text (std::string)
PList, //!< Pointer to String list, space separated (std::string)
Path, //!< File path (std::string)
PPath, //!< Pointer to File path (std::string)
Rating, //!< Floating point value between 0.0 and 1.0 (float)
Date, //!< Epoc (int)
Range, //!< Integer range: LSW:from MSW:to
Crc32, //!< 4byte hash (int)
};
private:
std::string _Key; //!< Identifier
std::string _DefaultValue; //!< default value
std::string _DisplayName; //!< displayed as this in editors
std::string _DisplayPrompt; //!< phrase displayed in editors when prompted to enter value (currently only for strings)
int _Offset; //!< Offset of the real field in the target Metadata structure
DataType _Type; //!< Datatype
IsDefaultValueMethodType _IsDefaultValueMethod; //!< Is Default value?
GetValueMethodType _GetMethod; //!< String getter
SetValueMethodType _SetMethod; //!< String getter
bool _IsStatistic; //!< if true, ignore scraper values for this metadata
bool _IsMain; //!< if true, display on main metadata editor GUI, else in secondary
public:
// Public const accessors
const std::string& Key() const { return _Key; } //!< Identifier
const std::string& DefaultValue() const { return _DefaultValue; } //!< default value
const std::string& DisplayName() const { return _DisplayName; } //!< displayed as this in editors
const std::string& DisplayPrompt() const { return _DisplayPrompt; } //!< phrase displayed in editors when prompted to enter value (currently only for strings)
int Offset() const { return _Offset; } //!< Offset of the real field in the target Metadata structure
DataType Type() const { return _Type; } //!< Datatype
IsDefaultValueMethodType IsDefaultValueMethod() const { return _IsDefaultValueMethod; } //!< Is Default value?
GetValueMethodType GetValueMethod() const { return _GetMethod; } //!< String getter
SetValueMethodType SetValueMethod() const { return _SetMethod; } //!< String setter
bool IsStatistic() const { return _IsStatistic; } //!< if true, ignore scraper values for this metadata
bool IsMain() const { return _IsMain; } //!< if true, display on main metadata editor GUI, else in secondary
//! Constructor
MetadataFieldDescriptor(const std::string& key,
const std::string& defaultValue,
const std::string& displayName,
const std::string& displayPrompt,
int offset,
DataType type,
IsDefaultValueMethodType isDefaultValueMethod,
GetValueMethodType getMethod,
SetValueMethodType setMethod,
bool isStatistic,
bool isMain)
: _Key(key),
_DefaultValue(defaultValue),
_DisplayName(displayName),
_DisplayPrompt(displayPrompt),
_Offset(offset),
_Type(type),
_IsDefaultValueMethod(isDefaultValueMethod),
_GetMethod(getMethod),
_SetMethod(setMethod),
_IsStatistic(isStatistic),
_IsMain(isMain)
{
}
};
......@@ -63,6 +63,11 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureDataManager.h
# Datetime
${CMAKE_CURRENT_SOURCE_DIR}/src/datetime/DateTime.h
${CMAKE_CURRENT_SOURCE_DIR}/src/datetime/ISystemDateTimeInterface.h
${CMAKE_CURRENT_SOURCE_DIR}/src/datetime/TimeSpan.h
# Embedded assets (needed by ResourceManager)
${emulationstation-all_SOURCE_DIR}/data/Resources.h
)
......@@ -123,6 +128,11 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureResource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureDataManager.cpp
# Datetime
${CMAKE_CURRENT_SOURCE_DIR}/src/datetime/DateTime.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/datetime/SystemDateTimeInterface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/datetime/TimeSpan.cpp
)
set(EMBEDDED_ASSET_SOURCES
......
This diff is collapsed.
This diff is collapsed.
#pragma once
class ISystemDateTimeInterface
{
public:
// Required virtual destructor
virtual ~ISystemDateTimeInterface() {}
// Load stored TimeZone
virtual char LoadTimeZone() = 0;
// Store TimeZone
virtual void SaveTimeZone(char tz) = 0;
// Load RTC values
virtual bool LoadRTCValues(short& millis, short& year, char& month, char& day, char& hour, char& minute, char& second) = 0;
// Load RTC values
virtual void SaveRTCValues(short millis, short year, char month, char day, char hour, char minute, char second) = 0;
};
#include <sys/time.h>
#include "ISystemDateTimeInterface.h"
#include "DateTime.h"
static class SystemDateTimeInterface : public ISystemDateTimeInterface
{
private:
static bool Initialize();
public:
static bool Initialized;
char LoadTimeZone() override
{
time_t t = time(NULL);
struct tm* lt = localtime(&t);
return (char)((lt->tm_gmtoff / (60* 60)) * 4);
}
void SaveTimeZone(char tz) override
{
(void)tz; // Ignore
}
bool LoadRTCValues(short &millis, short &year, char &month, char &day, char &hour, char &minute, char &second) override
{
time_t t = time(NULL);
struct tm* lt = localtime(&t);
millis = 0;
second = (char)lt->tm_sec;
minute = (char)lt->tm_min;
hour = (char)lt->tm_hour;
day = (char)lt->tm_mday;
month = (char)(lt->tm_mon + 1);
year = (short)(lt->tm_year + 1900);
return true;
}
void SaveRTCValues(short millis, short year, char month, char day, char hour, char minute, char second) override
{
(void)millis;
(void)year;
(void)month;
(void)day;
(void)hour;
(void)minute;
(void)second;
}
} SystemDateTime;
bool SystemDateTimeInterface::Initialize()
{
DateTime::SetSystemInterface(&SystemDateTime);
return true;
}
bool SystemDateTimeInterface::Initialized = SystemDateTimeInterface::Initialize();
#include "DateTime.h"
#include "TimeSpan.h"
TimeSpan& TimeSpan::Build(long long ms)
{
Units._Millis = (int)(ms % 1000LL); ms /= 1000LL;
Units._Seconds = (int)(ms % 60LL); ms /= 60LL;
Units._Minutes = (int)(ms % 60LL); ms /= 60LL;
Units._Hours = (int)ms;
return *this;
}
TimeSpan::TimeSpan(const DateTime& start, const DateTime& stop)
{
long long epochStop = (stop.ToEpochTime()) * 1000LL + (long long)stop.Millisecond();
long long epochStart = (start.ToEpochTime()) * 1000LL + (long long)start.Millisecond();
Build(epochStop - epochStart);
}
std::string TimeSpan::ToStringFormat(const char* format) const
{
std::string result;
bool Escaped = false;
for (int index = 0; format[index] != 0;)
{
char c = format[index];
if (c == '\\')
{
Escaped = true;
index++;
continue;
}
if ((c != '%') || Escaped)
{
result += c;
Escaped = false;
index++;
continue;
}
// c is '%', get first format char
c = format[++index];
int repeat = 0;
if (format[++index] == c)
{
repeat++;
if (format[++index] == c)
{
repeat++;
if (format[++index] == c)
{
repeat++;
index++;
}
}
}
switch (c)
{
case 'd':
{
if (repeat == 0) result += (Units._Hours / 24);
break;
}
case 'H':
{
if (repeat == 0) result +=(Units._Hours);
else if (repeat == 1) { result += ((char) ('0' + (((Units._Hours % 24) / 10) % 10))); result += ((char) ('0' + ((Units._Hours % 24) % 10))); }
break;
}
case 'm':
{
if (repeat == 0) result += (Units._Minutes);
else if (repeat == 1) { result += ((char) ('0' + ((Units._Minutes / 10) % 10))); result += ((char) ('0' + (Units._Minutes % 10))); }
else if (repeat == 3) result+= (TotalMinutes());
break;
}
case 's':
{
if (repeat == 0) result += (Units._Seconds);
else if (repeat == 1) { result += ((char) ('0' + ((Units._Seconds / 10) % 10))); result += ((char) ('0' + (Units._Seconds % 10))); }
else if (repeat == 3) result += (TotalSeconds());
break;
}
case 'f':
{
if (repeat == 0) result += (Units._Millis);
else if (repeat == 2) { result += ((char) ('0' + ((Units._Millis / 100) % 10))); result += ((char) ('0' + ((Units._Millis / 10) % 10))); result += ((char) ('0' + (Units._Millis % 10))); }
else if (repeat == 3) result += (TotalMilliseconds());
break;
}
case '%':
{
result.append(repeat, '%');
break;
}
default:
{
result += ("<Unk:");
result.append(repeat + 1, c);
result += ('>');
break;
}
}
}
return std::move(result);
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment