Files
Tools_CPP/lib/inifile.h
2024-11-01 12:23:13 +05:00

88 lines
3.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* inifile.h
*
* Created on: 17 дек. 2014 г.
* Author: ivanov.i
*/
#ifndef INIFILE_H_
#define INIFILE_H_
#include <list>
#include <string>
//------------------------------------------------------------------------------
//чтение и запись ini файлов
/*struct TIniStruct
{
TIniStruct *next;
std::string section;
std::string ident;
std::string value;
};*/
//------------------------------------------------------------------------------
//чтение и запись ini файлов
struct TIniWStruct
{
TIniWStruct *next;
std::wstring section;
std::wstring ident;
std::wstring value;
};
//------------------------------------------------------------------------------
class TIniFile
{
private:
std::string path; //Полный путь к файлу
TIniWStruct *first;
TIniWStruct *last;
public:
TIniFile();
virtual ~TIniFile();
TIniWStruct* getFirst() { return first; };
bool Load(std::string path);
bool Load(std::wstring path);
bool Save(); //Сортировка и сохранение
bool getSection(std::string Section); //Есть ли заданая секция в iti файле
std::list<std::string> getIdents(std::string Section);
std::wstring ReadString(std::wstring Section, std::wstring Ident, std::wstring Default);
std::string ReadString(std::string Section, std::string Ident, std::string Default);
std::string ReadString(const char* Section, const char* Ident, const char* Default) { return ReadString(std::string(Section), std::string(Ident), std::string(Default)); };
long ReadLong(std::string Section, std::string Ident, std::string Default);
long ReadLong(const char* Section, const char* Ident, const char* Default);
unsigned int ReadUInt(std::string Section, std::string Ident, std::string Default);
unsigned int ReadUInt(const char* Section, const char* Ident, const char* Default) { return ReadUInt(std::string(Section), std::string(Ident), std::string(Default)); };
float ReadFloat(std::string Section, std::string Ident, std::string Default);
bool ReadBool(std::string Section, std::string Ident, std::string Default); //Default: "0" или "1"
void WriteString(std::string Section, std::string Ident, std::string Value);
void WriteString(std::wstring Section, std::wstring Ident, std::wstring Value);
void WriteString(const char* Section, const char* Ident, const char* Value) { WriteString(std::string(Section), std::string(Ident), std::string(Value)); };
void WriteUInt(std::string Section, std::string Ident, unsigned int Value);
void WriteUInt(const char* Section, const char* Ident, unsigned int Value) { WriteUInt(std::string(Section), std::string(Ident), Value); };
void WriteLong(std::string Section, std::string Ident, long Value);
void WriteBool(std::string Section, std::string Ident, bool Value);
void WriteBase64(std::string Section, std::string Ident, char* Value, int size);
void WriteFloat(std::string Section,std::string Ident,float Value);
void WriteDouble(std::string Section,std::string Ident,double Value);
};
//------------------------------------------------------------------------------
//Простой JSON парсер без вложенности
class JSON
{
private:
TIniWStruct *first;
TIniWStruct *last;
public:
JSON(std::wstring data);
std::wstring ReadString(std::wstring Ident,std::wstring Default);
std::string ReadAString(std::wstring Ident,std::wstring Default);
char ReadChar(std::wstring Ident,std::wstring Default);
long ReadLong(std::wstring Ident,std::wstring Default);
double ReadDouble(std::wstring Ident,std::wstring Default);
};
#endif /* INIFILE_H_ */