first add files

This commit is contained in:
2019-11-29 11:58:31 +08:00
parent 9c86489a35
commit 15db8e01c7
16 changed files with 677 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
#ifndef HGL_COMMAND_LINE_PARSE_INCLUDE
#define HGL_COMMAND_LINE_PARSE_INCLUDE
#include<hgl/type/StringList.h>
namespace hgl
{
namespace util
{
/**
* 命令行参数解晰辅助类
*/
class CmdParse ///命令行参数解晰辅助类
{
OSStringList args;
public:
CmdParse(const OSStringList &);
virtual ~CmdParse();
int Find(const OSString &)const; ///<查找一个指定字串开头的参数是否存在
bool GetInteger(const OSString &,int *)const; ///<取得一个数值参数
bool GetString(const OSString &,OSString &)const; ///<取得一个字符串参数
};//class CmdParse
}//namespace util
}//namespace hgl
#endif//HGL_COMMAND_LINE_PARSE_INCLUDE

View File

@@ -0,0 +1,19 @@
#pragma once
#include<json/json.h>
#include<hgl/type/BaseString.h>
namespace hgl
{
/**
* 转换Json数据类型到普通UTF8字符串
*/
bool JsonToString(const Json::Value &jv_root,UTF8String &str,OSString &error_info);
/**
* 解释一个json数据流
*/
bool ParseJson(Json::Value &root,const char *str,const int size,OSString &error_info);
bool LoadJson(Json::Value &,const hgl::OSString &filename,OSString &error_info);
bool SaveJson(Json::Value &,const hgl::OSString &filename,OSString &error_info);
};//

38
inc/hgl/util/time/Timer.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef HGL_TIMER_INCLUDE
#define HGL_TIMER_INCLUDE
#include<hgl/type/DataType.h>
#include<hgl/object/Object.h>
namespace hgl
{
/**
* 计时器是一个简单封装的组件。通过操作OnTimer事件通知应用程序时间到了
* 注意如果间隔时间为0那表示不使用定时器但这样不如将Enable设为false更为高效。
*/
class Timer:public Object ///计时器类
{
protected:
double inter;
double next;
double GetInterval(){return inter;}
void SetInterval(double);
public: //属性
Property<double> Interval; ///<间隔时间虚拟变量,单位秒
public: //事件
DefEvent(void,OnTimer,(Object *)); ///<时间到了事件
public:
Timer(double=0);
virtual ~Timer()=default;
virtual void Update();
};//class Timer:public Object
}//namespace hgl
#endif//HGL_TIMER_INCLUDE

123
inc/hgl/util/xml/XMLParse.h Normal file
View File

@@ -0,0 +1,123 @@
#ifndef HGL_XML_PARSE_INCLUDE
#define HGL_XML_PARSE_INCLUDE
#include<hgl/type/BaseString.h>
extern "C"
{
/**
* 该XML解晰器使用Expat实现,根据MIT协议取得免费授权,授权协议参见 doc/license/MIT.txt
* Expat官方网站http://expat.sourceforge.net/
*/
struct XML_ParserStruct;
typedef struct XML_ParserStruct *XML_Parser;
}
namespace hgl
{
namespace io
{
class InputStream;
}//namespace io
/**
* XML解析器(虚拟函数版)<br>
*/
class XMLParse
{
protected:
XML_Parser xml;
virtual void StartParse();
public:
virtual void StartElement(const char *element_name,const char **atts)=0;
virtual void CharData(const char *str,int str_length){};
virtual void EndElement(const char *element_name){};
public:
XMLParse();
virtual ~XMLParse();
virtual void Start();
virtual bool Parse(const char *buf,int len,bool isFin);
virtual bool Parse(io::InputStream *,bool isFin=true);
};//class XMLParse
bool XMLParseFile(XMLParse *xml,const OSString &filename);
/**
* XML解析器(回调函数版)
*/
class XMLParseCB:public XMLParse
{
protected:
virtual void StartParse();
public:
DefEvent(void,OnStartElement,(const char *,const char **));
DefEvent(void,OnCharData,(const char *,int));
DefEvent(void,OnEndElement,(const char *));
public:
XMLParseCB();
virtual ~XMLParseCB()=default;
};//class XMLParseCB
#define XML_START_PARSE(name) while(*name) \
{ \
const char *flag=*name;++name; \
const char *info=*name;++name;
#define XML_END_PARSE() LOG_ERROR(UTF8String(__FILE__)+U8_TEXT(":")+UTF8String(__LINE__)+U8_TEXT(" can't parse atts \"")+UTF8String(flag)+U8_TEXT("\" , info \"")+UTF8String(info)+U8_TEXT("\".")); \
}
#define XML_END_PARSE_SKIP() ;}
#define xml_parse_skip(name) if(hgl::strcmp(flag,#name)==0)continue;else
#define xml_parse_string_u16(name) if(hgl::strcmp(flag,#name)==0)name=to_u16(info);else
#define xml_parse_string_u8(name) if(hgl::strcmp(flag,#name)==0)name=info;else
#define xml_parse_int(name) if(hgl::strcmp(flag,#name)==0)hgl::stoi(info,name);else
#define xml_parse_uint(name) if(hgl::strcmp(flag,#name)==0)hgl::stou(info,name);else
#define xml_parse_float(name) if(hgl::strcmp(flag,#name)==0)hgl::stof(info,name);else
#define xml_parse_bool(name) if(hgl::strcmp(flag,#name)==0)hgl::stob(info,name);else
#define xml_parse_hexstr(name) if(hgl::strcmp(flag,#name)==0)hgl::ParseHexStr(name,info);else
#define xml_parse_to_string_u8(name,value) if(hgl::strcmp(flag,name)==0)value=info;else
#define xml_parse_to_int(name,value) if(hgl::strcmp(flag,name)==0)hgl::stoi(info,value);else
#define xml_parse_to_uint(name,value) if(hgl::strcmp(flag,name)==0)hgl::stou(info,value);else
#define xml_parse_to_float(name,value) if(hgl::strcmp(flag,name)==0)hgl::stof(info,value);else
#define xml_parse_to_bool(name,value) if(hgl::strcmp(flag,name)==0)hgl::stob(info,value);else
/** 使用范例:
<root>
<role name="Bill" sex="true" age="18"/>
<role name="Lucy" sex="false" age="17"/>
</root>
void StartElement(const char *element_name,const char **atts) override
{
if(strcmp(element_name,"role")==0)
{
std::string name;
bool sex;
int age;
XML_START_PARSE(atts)
xml_parse_string_u8(name)
xml_parse_bool(sex)
xml_parse_int(age)
XML_END_PARSE
}
}
*/
}//namespace hgl
#endif//HGL_XML_PARSE_INCLUDE