added ability to get default value if is needed
This commit is contained in:
parent
b03a370bd0
commit
7df098eafa
2 changed files with 65 additions and 2 deletions
1
Makefile
1
Makefile
|
|
@ -2,5 +2,6 @@ CC=clang++
|
||||||
CFLAGS=-std=c++23
|
CFLAGS=-std=c++23
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
rm -rf /usr/include/tiny/
|
||||||
mkdir -p /usr/include/tiny/
|
mkdir -p /usr/include/tiny/
|
||||||
cp inc/*.h /usr/include/tiny/
|
cp inc/*.h /usr/include/tiny/
|
||||||
66
inc/tdf.h
66
inc/tdf.h
|
|
@ -352,10 +352,8 @@ struct TDF_FILE{
|
||||||
throw TDF_ERR(FILE_NOT_FOUND,filepath,{});
|
throw TDF_ERR(FILE_NOT_FOUND,filepath,{});
|
||||||
}
|
}
|
||||||
NULLPOINTER:
|
NULLPOINTER:
|
||||||
//tiny::fatal("NULL POINTER of selector %c",CCHAR);
|
|
||||||
throw TDF_ERR(NULL_POINTER,filepath,{std::string(1,CCHAR),std::to_string(INDEX)});
|
throw TDF_ERR(NULL_POINTER,filepath,{std::string(1,CCHAR),std::to_string(INDEX)});
|
||||||
FAILTOPARSE:
|
FAILTOPARSE:
|
||||||
//tiny::fatal("FAILED TO PARSE LINE %i OF FILE %s",INDEX,filepath);
|
|
||||||
throw TDF_ERR(FAILED_TO_PARSE,filepath,{std::to_string(INDEX)});
|
throw TDF_ERR(FAILED_TO_PARSE,filepath,{std::to_string(INDEX)});
|
||||||
delete data;
|
delete data;
|
||||||
data=nullptr;
|
data=nullptr;
|
||||||
|
|
@ -373,6 +371,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool defined(std::vector<std::string>path,bool defaultval){
|
||||||
|
try {
|
||||||
|
return defined(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
bool getbool(std::vector<std::string>path){
|
bool getbool(std::vector<std::string>path){
|
||||||
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
||||||
for(size_t i=0;i<path.size();i++){
|
for(size_t i=0;i<path.size();i++){
|
||||||
|
|
@ -387,6 +393,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
||||||
}
|
}
|
||||||
|
bool getbool(std::vector<std::string>path,bool defaultval){
|
||||||
|
try {
|
||||||
|
return getbool(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
int getint(std::vector<std::string>path){
|
int getint(std::vector<std::string>path){
|
||||||
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
||||||
for(size_t i=0;i<path.size();i++){
|
for(size_t i=0;i<path.size();i++){
|
||||||
|
|
@ -401,6 +415,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
||||||
}
|
}
|
||||||
|
int getint(std::vector<std::string>path,int defaultval){
|
||||||
|
try {
|
||||||
|
return getint(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
std::string getstring(std::vector<std::string>path){
|
std::string getstring(std::vector<std::string>path){
|
||||||
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
||||||
for(size_t i=0;i<path.size();i++){
|
for(size_t i=0;i<path.size();i++){
|
||||||
|
|
@ -415,6 +437,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
||||||
}
|
}
|
||||||
|
std::string getstring(std::vector<std::string>path,std::string defaultval){
|
||||||
|
try {
|
||||||
|
return getstring(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
std::vector<std::string> getpointer(std::vector<std::string>path){
|
std::vector<std::string> getpointer(std::vector<std::string>path){
|
||||||
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
||||||
for(size_t i=0;i<path.size();i++){
|
for(size_t i=0;i<path.size();i++){
|
||||||
|
|
@ -429,6 +459,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
||||||
}
|
}
|
||||||
|
std::vector<std::string> getpointer(std::vector<std::string>path,std::vector<std::string> defaultval){
|
||||||
|
try {
|
||||||
|
return getpointer(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
char getchar(std::vector<std::string>path){
|
char getchar(std::vector<std::string>path){
|
||||||
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
||||||
for(size_t i=0;i<path.size();i++){
|
for(size_t i=0;i<path.size();i++){
|
||||||
|
|
@ -443,6 +481,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
||||||
}
|
}
|
||||||
|
char getchar(std::vector<std::string>path,char defaultval){
|
||||||
|
try {
|
||||||
|
return getchar(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
float getfloat(std::vector<std::string>path){
|
float getfloat(std::vector<std::string>path){
|
||||||
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
||||||
for(size_t i=0;i<path.size();i++){
|
for(size_t i=0;i<path.size();i++){
|
||||||
|
|
@ -457,6 +503,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
||||||
}
|
}
|
||||||
|
float getfloat(std::vector<std::string>path,float defaultval){
|
||||||
|
try {
|
||||||
|
return getfloat(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
boost::unordered_map<std::string,TDF_DATA>* getclass(std::vector<std::string>path){
|
boost::unordered_map<std::string,TDF_DATA>* getclass(std::vector<std::string>path){
|
||||||
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
boost::unordered_map<std::string,TDF_DATA>*current=data;
|
||||||
for(size_t i=0;i<path.size();i++){
|
for(size_t i=0;i<path.size();i++){
|
||||||
|
|
@ -471,6 +525,14 @@ struct TDF_FILE{
|
||||||
}
|
}
|
||||||
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
throw TDF_ERR(PATH_NOT_FOUND,filepath,path);
|
||||||
}
|
}
|
||||||
|
boost::unordered_map<std::string,TDF_DATA>* getclass(std::vector<std::string>path,boost::unordered_map<std::string,TDF_DATA>* defaultval){
|
||||||
|
try {
|
||||||
|
return getclass(path);}
|
||||||
|
catch(TDF_ERR e) {
|
||||||
|
warning((char*)e.what());
|
||||||
|
return defaultval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//set
|
//set
|
||||||
void setbool(std::vector<std::string>path,bool value){
|
void setbool(std::vector<std::string>path,bool value){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue