Fix indexing and use _ identifiers to please the compiler

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/28/head
Nic0Nic0Nii 1 year ago
parent 11aa50105c
commit 68393d2b07
  1. 23
      Crawler/Crawler.cpp
  2. 16
      Crawler/Crawler.h
  3. 75
      Crawler/olcUTIL_DataFile.h

@ -42,11 +42,12 @@ Crawler::Crawler()
utils::datafile::Read(DATA,"assets/config/configuration.txt"); utils::datafile::Read(DATA,"assets/config/configuration.txt");
std::string CONFIG_PATH = "config_path"S; std::string CONFIG_PATH = "config_path"_S;
std::string GFX_CONFIG = CONFIG_PATH + "gfx_config"S; std::string GFX_CONFIG = CONFIG_PATH + "gfx_config"_S;
utils::datafile::Read(DATA,GFX_CONFIG); utils::datafile::Read(DATA,GFX_CONFIG);
WINDOW_SIZE={"WINDOW_SIZE"i[0],"WINDOW_SIZE"i[1]}; WINDOW_SIZE={"WINDOW_SIZE"_i[0],"WINDOW_SIZE"_i[1]};
std::cout<<WINDOW_SIZE<<std::endl;
} }
bool Crawler::OnUserCreate(){ bool Crawler::OnUserCreate(){
@ -1138,34 +1139,34 @@ int main()
return 0; return 0;
} }
datafilestringdata operator ""s(const char*key,std::size_t len){ datafilestringdata operator ""_s(const char*key,std::size_t len){
return {DATA,std::string(key,len)}; return {DATA,std::string(key,len)};
} }
datafileintdata operator ""i(const char*key,std::size_t len){ datafileintdata operator ""_i(const char*key,std::size_t len){
return {DATA,std::string(key,len)}; return {DATA,std::string(key,len)};
} }
datafilefloatdata operator ""f(const char*key,std::size_t len){ datafilefloatdata operator ""_f(const char*key,std::size_t len){
return {DATA,std::string(key,len)}; return {DATA,std::string(key,len)};
} }
datafiledoubledata operator ""d(const char*key,std::size_t len){ datafiledoubledata operator ""_d(const char*key,std::size_t len){
return {DATA,std::string(key,len)}; return {DATA,std::string(key,len)};
} }
std::string operator ""S(const char*key,std::size_t len){ std::string operator ""_S(const char*key,std::size_t len){
return DATA.GetProperty(std::string(key,len)).GetString(); return DATA.GetProperty(std::string(key,len)).GetString();
} }
int operator ""I(const char*key,std::size_t len){ int operator ""_I(const char*key,std::size_t len){
return DATA.GetProperty(std::string(key,len)).GetInt(); return DATA.GetProperty(std::string(key,len)).GetInt();
} }
float operator ""F(const char*key,std::size_t len){ float operator ""_F(const char*key,std::size_t len){
return DATA.GetProperty(std::string(key,len)).GetReal(); return DATA.GetProperty(std::string(key,len)).GetReal();
} }
double operator ""D(const char*key,std::size_t len){ double operator ""_D(const char*key,std::size_t len){
return DATA.GetProperty(std::string(key,len)).GetReal(); return DATA.GetProperty(std::string(key,len)).GetReal();
} }

@ -110,18 +110,18 @@ public:
}; };
//Read a string array from the config. //Read a string array from the config.
datafilestringdata operator ""s(const char*key,std::size_t len); datafilestringdata operator ""_s(const char*key,std::size_t len);
//Read an int array from the config. //Read an int array from the config.
datafileintdata operator ""i(const char*key,std::size_t len); datafileintdata operator ""_i(const char*key,std::size_t len);
//Read a float array from the config. //Read a float array from the config.
datafilefloatdata operator ""f(const char*key,std::size_t len); datafilefloatdata operator ""_f(const char*key,std::size_t len);
//Read a double array from the config. //Read a double array from the config.
datafiledoubledata operator ""d(const char*key,std::size_t len); datafiledoubledata operator ""_d(const char*key,std::size_t len);
//Read a string key from the config. //Read a string key from the config.
std::string operator ""S(const char*key,std::size_t len); std::string operator ""_S(const char*key,std::size_t len);
//Read an integer key from the config. //Read an integer key from the config.
int operator ""I(const char*key,std::size_t len); int operator ""_I(const char*key,std::size_t len);
//Read a float key from the config. //Read a float key from the config.
float operator ""F(const char*key,std::size_t len); float operator ""_F(const char*key,std::size_t len);
//Read a double key from the config. //Read a double key from the config.
double operator ""D(const char*key,std::size_t len); double operator ""_D(const char*key,std::size_t len);

@ -64,42 +64,6 @@ David Barr, aka javidx9, <EFBFBD>OneLoneCoder 2019, 2020, 2021, 2022
namespace olc::utils namespace olc::utils
{ {
class datafilestringdata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafilestringdata(datafile&dat,std::string key)
:data(dat),key(key){};
std::string operator[](int index){data.get().GetIndexedProperty(key,index).GetString();};
};
class datafileintdata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafileintdata(datafile&dat,std::string key)
:data(dat),key(key){};
int operator[](int index){data.get().GetIndexedProperty(key,index).GetInt();};
};
class datafilefloatdata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafilefloatdata(datafile&dat,std::string key)
:data(dat),key(key){};
float operator[](int index){data.get().GetIndexedProperty(key,index).GetReal();};
};
class datafiledoubledata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafiledoubledata(datafile&dat,std::string key)
:data(dat),key(key){};
double operator[](int index){data.get().GetIndexedProperty(key,index).GetReal();};
};
class datafile class datafile
{ {
public: public:
@ -473,4 +437,43 @@ namespace olc::utils
// Used to identify if a property is a comment or not, not user facing // Used to identify if a property is a comment or not, not user facing
bool m_bIsComment = false; bool m_bIsComment = false;
}; };
class datafilestringdata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafilestringdata(datafile&dat,std::string key)
:data(dat),key(key){};
std::string operator[](int index){return data.get().GetProperty(key).GetString(index);};
};
class datafileintdata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafileintdata(datafile&dat,std::string key)
:data(dat),key(key){};
int operator[](int index){
return data.get().GetProperty(key).GetInt(index);
};
};
class datafilefloatdata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafilefloatdata(datafile&dat,std::string key)
:data(dat),key(key){};
float operator[](int index){return data.get().GetProperty(key).GetReal(index);};
};
class datafiledoubledata
{
std::reference_wrapper<datafile>data;
std::string key;
public:
inline datafiledoubledata(datafile&dat,std::string key)
:data(dat),key(key){};
double operator[](int index){return data.get().GetProperty(key).GetReal(index);};
};
} }
Loading…
Cancel
Save