MD5JSON.h
#pragma once
#include "include/json/json.h"
#include "include/md5/md5.h"
#include "xml/tinyxml/tinystr.h"
#include "xml/tinyxml/tinyxml.h"
#include <string>
using namespace std;
#pragma comment(lib,"md5_JSON\include\bin\json_vc71_libmtd.lib")
#define MJ MD5JSON::getInstance()
#define JSON Json
#define XM XML::getInstance()
// //多线程调试 (/MTd)
class MD5JSON
{
//md5
md5_state_t m_context;
unsigned char m_Digest[16];
char m_outstr[256];
//json
char *buf;
Json::Reader reader;
Json::Value root;
string m_jsonfilename;
Json::Value jsonItem;
public:
///////////////////////// MD5
static MD5JSON *getInstance();
bool setmd5(const char *data);
bool setmd5(const char *data, char *buffer, int bufferLen);
bool setmd5(const char *data, int datalen);
bool setmd5(string data);
bool setmd5(string data, char *buffer, int bufferLen);
void print();
void print(char *data);
void print(string data);
void print(const char *data);
char *getmd5() { return m_outstr; }
public:
///////////////////////// JSON
bool createJSONFile(const char *filename);
bool createJSONFile(string filename);
string getFileName() { return m_jsonfilename; }
Json::Value getRoot() { return this->root; }
Json::Value getItem() { return this->jsonItem; }
bool readJSONFile(const char *filename);
bool readJSONFile(string filename);
//直接写入文件
bool insertData(const char *data);
//json 方法写入并baocun
bool insertData();
//如果相同则覆盖
//==================================================
bool addChild(const char *key,const char *value);
bool addChild(string key, string value);
//MD5JSON::insertData(); 内部已经调用
void addChildEnd();
//==================================================
char *getJSONData() { return buf; }
//在加载文件时此函数就已经调用
bool parseJSON();
//这里只有在一个root下才有效
int get_int(const char *key);
string get_string(const char *key);
unsigned int get_uint(const char *key);
double get_double(const char *key);
bool get_bool(const char *key);
const char *get_const_string(const char *key);
//清楚整个文件数据
void clear();
//遍历
void ergodicObject(Json::Value::Members &object);
void ergodicObject(Json::Value &root, Json::Value::Members &object);
//数组遍历
void ergodicArray(Json::Value &root);
private:
//f30992da54715e5a0c4a7eaf29889641 //vico
MD5JSON()
{
this->m_context = { 0 };
memset(this->m_Digest, 0, sizeof(this->m_Digest));
memset(this->m_outstr, 0, sizeof(this->m_outstr));
}
~MD5JSON()
{
if (buf)
{
delete[] buf;
buf = NULL;
}
}
};
class XML
{
string name;
TiXmlDocument* Doc;
public:
static XML *getInstance();
string setXMLName(string name);
bool createXML();
bool createXML(string name);
bool loadXML(string name);
//Accout Password
bool insert(