This commit is contained in:
2022-03-31 23:45:50 +08:00
13 changed files with 184 additions and 91 deletions

View File

@@ -116,11 +116,5 @@ namespace hgl
else \
return(false); \
}
template<typename EC> inline bool EnumClassRangeCheck(const EC &value){return(value>=EC::BEGIN_RANGE&&value<=EC::END_RANGE);}
#define ENUM_CLASS_RANGE_ERROR_RETURN(value,return_value) if(EnumClassRangeCheck(value))return(return_value);
#define ENUM_CLASS_RANGE_ERROR_RETURN_FALSE(value) if(!EnumClassRangeCheck(value))return(false);
#define ENUM_CLASS_RANGE_ERROR_RETURN_NULLPTR(value) if(!EnumClassRangeCheck(value))return(nullptr);
}//namespace hgl
#endif//HGL_MACRO_INCLUDE

View File

@@ -15,9 +15,7 @@ namespace hgl
template<typename T>
inline bool RangeCheck(const T &value)
{
if(value<T::BEGIN_RANGE)return(false);
if(value>T::END_RANGE)return(false);
return(true);
return (value>=T::BEGIN_RANGE&&value<=T::END_RANGE);
}
#define ENUM_CLASS_FOR(ECTYPE,ctype,value) \
@@ -25,6 +23,10 @@ namespace hgl
value<=(ctype)ECTYPE::END_RANGE; \
value++)
#define ENUM_CLASS_RANGE_ERROR_RETURN(value,return_value) if(EnumClassRangeCheck(value))return(return_value);
#define ENUM_CLASS_RANGE_ERROR_RETURN_FALSE(value) if(!EnumClassRangeCheck(value))return(false);
#define ENUM_CLASS_RANGE_ERROR_RETURN_NULLPTR(value) if(!EnumClassRangeCheck(value))return(nullptr);
#define HGL_CONVER_TO_MEM_ALIGN(x) ((((x)+HGL_MEM_ALIGN-1)/HGL_MEM_ALIGN)*HGL_MEM_ALIGN) //内存对齐转换宏
#ifndef NULL

View File

@@ -48,6 +48,19 @@ namespace hgl
bool GetCurrentProgramPath(OSString &); ///<取得当前程序所在路径
bool GetLocalAppdataPath(OSString &); ///<取得当前用户应用程序数据存放路径
bool GetOSLibararyPath(OSString &); ///<取得操作系统共用动态库路径
/**
* @param filename 要查找的文件名称
* @param user_data 用户自定义数据
* @param exist 文件是否存在
* @return 是否继续查找
*/
typedef bool (*OnFindedFileFUNC)(const OSString &filename,void *user_data,bool exist);
const uint FindFileOnPaths(const OSString &filename,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff); ///<在多个目录内查找一个文件
const uint FindFileOnPaths(const OSStringList &filenames,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff); ///<在多个目录内查找一个文件,这个文件可能有多个文件名
/**
* 文件名长度限制
*

View File

@@ -79,7 +79,7 @@ namespace hgl
* 根据离散的每一级目录名称和最终名称合成完整文件名
*/
template<typename T>
inline const String<T> ComboFilename(const StringList<String<T>> &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR)
inline const String<T> ComboFilename(const StringList<T> &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR)
{
T **str_list=AutoDeleteArray<T *>(sl.GetCount());
int *str_len=AutoDeleteArray<int>(sl.GetCount());

View File

@@ -17,12 +17,8 @@ namespace hgl
public:
PlugInManage(const OSString &n)
{
name=n;
}
virtual ~PlugInManage();
PlugInManage(const OSString &n);
virtual ~PlugInManage()=default;
bool RegistryPlugin(PlugIn *); ///<注册一个内置插件
uint UnregistryPlugin(const OSString &); ///<释放一个内置插件

View File

@@ -204,6 +204,7 @@ namespace hgl
}
T * get ()const{return sd?sd->data:0;}
const T * const_get ()const{return sd?sd->data:0;}
virtual bool valid ()const{return sd;}
int use_count ()const{return sd?sd->count:-1;}
bool only ()const{return sd?sd->count==1:true;}

View File

@@ -1061,21 +1061,7 @@ namespace hgl
--dst_size;
}
if(dst_size<=0||src_size<=0)
return(0);
if(src_size)
{
if(dst_size)
return chricmp(*src,*dst);
else
return 1;
}
if(dst_size)
return -1;
else
return 0;
return src_size-dst_size;
}
/**

View File

@@ -21,6 +21,10 @@ namespace hgl
SharedClass data; ///<字符串数据实例
public:
using CharType=T;
public:
String()=default;
@@ -629,10 +633,12 @@ namespace hgl
if(!data.valid())
return(bs.Length());
if(bs.Length()<=0)
const int len=bs.Length();
if(len<=0)
return 1;
return data->CaseComp(bs.data->c_str());
return data->CaseComp(bs.data->c_str(),len);
}
/**

View File

@@ -332,18 +332,6 @@ namespace hgl
return hgl::strcmp(buffer+pos,str,num);
}
/**
* 和一个字符串进行比较,英文不区分大小写
* @param sc 比较字符串
* @return <0 我方小
* @return 0 等同
* @return >0 我方大
*/
const int CaseComp(const SelfClass &sc)const
{
return hgl::stricmp(buffer,length,sc.buffer,sc.length);
}
/**
* 和那一个字符串进行比较,英文不区分大小写
* @param str 比较字符串

View File

@@ -5,6 +5,7 @@
#include<hgl/type/String.h>
#include<hgl/io/DataInputStream.h>
#include<hgl/io/DataOutputStream.h>
#include<initializer_list>
namespace hgl
{
@@ -15,28 +16,29 @@ namespace hgl
*/
template<typename T> class StringList ///字符串列表处理类
{
static T NullString;
using StringClass=String<T>;
static StringClass NullString;
protected:
ObjectList<T> Items;
ObjectList<StringClass> Items;
public: //属性
T **GetDataList()const{return Items.GetData();} ///<取得字符串列表指针数据
StringClass **GetDataList()const{return Items.GetData();} ///<取得字符串列表指针数据
const int GetCount()const{return Items.GetCount();} ///<字符串列表行数虚拟变量
T **begin() const{return Items.GetData();}
T **end() const{return Items.GetData()+Items.GetCount();}
StringClass **begin() const{return Items.GetData();}
StringClass **end() const{return Items.GetData()+Items.GetCount();}
public: //操作符重载
T &operator[](int n)const
StringClass &operator[](int n)const
{
if(n<0||n>=Items.GetCount())
return NullString;
T *result=Items[n];
StringClass *result=Items[n];
if(result)
return(*result);
@@ -44,12 +46,12 @@ namespace hgl
return NullString;
}
StringList<T> &operator = (const StringList<T> &sl)
StringList<StringClass> &operator = (const StringList<StringClass> &sl)
{
Clear();
const int n=sl.GetCount();
T *str;
StringClass *str;
for(int i=0;i<n;i++)
{
@@ -63,7 +65,13 @@ namespace hgl
public: //方法
StringList()=default; ///<本类构造函数
//注这里不要实现StringList(T &)或StringList(T *)之类
StringList(const std::initializer_list<T *> &lt)
{
for(T *str:lt)
Add(str);
}
//注这里不要实现StringList(StringClass &)或StringList(StringClass *)之类
virtual ~StringList(){Clear();} ///<本类析构函数
/**
@@ -71,17 +79,17 @@ namespace hgl
* @param str 要增加的字符串
* @return 增加字符串成功后的索引
*/
int Add(const T &str){return Items.Add(new T(str));} ///<添加字符串
int Add(const StringClass &str){return Items.Add(new StringClass(str));} ///<添加字符串
/**
* 增加一个字符串列表到当前字符串列表中
* @param sl 要增加的字符串列表
*/
int Add(const StringList<T> &sl) ///<添加字符串
int Add(const StringList<StringClass> &sl) ///<添加字符串
{
const int count=sl.GetCount();
T **str=sl.Items.GetData();
StringClass **str=sl.Items.GetData();
for(int i=0;i<count;i++)
{
@@ -108,11 +116,11 @@ namespace hgl
* @param str 要删除的字符串
* @return 成功删除的行数
*/
int Delete(const T &str)
int Delete(const StringClass &str)
{
int count=Items.GetCount();
int result=0;
T** sl = Items.GetData();
StringClass** sl = Items.GetData();
sl += count - 1;
while(count--)
@@ -134,10 +142,10 @@ namespace hgl
* @param str 要查找的字符串
* @return 查找到的字符串的索引,未找到返回-1
*/
int Find(const T &str) const ///<查找字符串,未找到返回-1
int Find(const StringClass &str) const ///<查找字符串,未找到返回-1
{
const int count=Items.GetCount();
T** sl = Items.GetData();
StringClass** sl = Items.GetData();
for(int i=0;i<count;i++)
if((*sl)->Comp(str)==0)
@@ -153,10 +161,10 @@ namespace hgl
* @param str 要指找的字符串
* @return 查找到的字符串的索引,未找到返回-1
*/
int CaseFind(const T &str) const ///<查找字符串,英文无视大小写,未找到返回-1
int CaseFind(const StringClass &str) const ///<查找字符串,英文无视大小写,未找到返回-1
{
const int count=Items.GetCount();
T** sl = Items.GetData();
StringClass** sl = Items.GetData();
for (int i = 0; i < count; i++)
if ((*sl)->CaseComp(str) == 0)
@@ -173,11 +181,11 @@ namespace hgl
* @param cn 限定的要查找字符串的最大长度
* @return 查找到的字符串的索引,未找到返回-1
*/
int Find(const T &str,const int cn) const ///<查找字符串,未找到返回-1
int Find(const StringClass &str,const int cn) const ///<查找字符串,未找到返回-1
{
const int count=Items.GetCount();
T** sl = Items.GetData();
StringClass** sl = Items.GetData();
for(int i=0;i<count;i++)
if((*sl)->Comp(str,cn)==0)
@@ -194,11 +202,11 @@ namespace hgl
* @param cn 限定的要查找字符串的最大长度
* @return 查找到的字符串的索引,未找到返回-1
*/
int CaseFind(const T &str,const int cn) const ///<查找字符串,英文无视大小写,未找到返回-1
int CaseFind(const StringClass &str,const int cn) const ///<查找字符串,英文无视大小写,未找到返回-1
{
const int count=Items.GetCount();
T** sl = Items.GetData();
StringClass** sl = Items.GetData();
for (int i = 0; i < count; i++)
if ((*sl)->CaseComp(str, cn) == 0)
@@ -214,10 +222,10 @@ namespace hgl
* @param index 要插入字符串的位置
* @param str 要插入的字符串
*/
void Insert(int index,const T &str) ///<在指定位置插入一个字符串
void Insert(int index,const StringClass &str) ///<在指定位置插入一个字符串
{
if(index<Items.GetCount())
Items.List<T *>::Insert(index,new T(str));
Items.List<StringClass *>::Insert(index,new StringClass(str));
}
/**
@@ -230,10 +238,10 @@ namespace hgl
Items.Exchange(index1,index2);
}
const T &GetString(int n)const{return *(Items[n]);} ///<取得指定行字符串
const StringClass &GetString(int n)const{return *(Items[n]);} ///<取得指定行字符串
};//template<typename T> class StringList
template<typename T> T StringList<T>::NullString; ///<空字符串实例
template<typename T> String<T> StringList<T>::NullString; ///<空字符串实例
/**
* 以不可打印字符为分隔拆解一个字符串到一个字符串列表
@@ -242,7 +250,7 @@ namespace hgl
* @param size 字符串长度
* @return 字符串行数
*/
template<typename T> int SplitToStringListBySpace(StringList<String<T> > &sl,const T *str,int size)
template<typename T> int SplitToStringListBySpace(StringList<T> &sl,const T *str,int size)
{
if(!str||size<=0)return(-1);
@@ -297,7 +305,7 @@ namespace hgl
* @param split_char 分隔字符
* @return 字符串行数
*/
template<typename T> int SplitToStringList(StringList<String<T> > &sl,const T *str,int size,const T &split_char)
template<typename T> int SplitToStringList(StringList<T> &sl,const T *str,int size,const T &split_char)
{
if(!str||size<=0)return(-1);
@@ -344,7 +352,7 @@ namespace hgl
return count;
}//int SplitToStringList
template<typename T> int SplitToStringListFromString(StringList<String<T> > &sl,const String<T> &str,const T &split_char)
template<typename T> int SplitToStringListFromString(StringList<T> &sl,const String<T> &str,const T &split_char)
{
return SplitToStringList<T>(sl,str.c_str(),str.Length(),split_char);
}
@@ -358,7 +366,7 @@ namespace hgl
* @param maxSize 最多执行次数
* @return 字符串行数
*/
template<typename T> int SplitToStringList(StringList<String<T> > &sl,const T *str,int size,const T &split_char,int maxSize)
template<typename T> int SplitToStringList(StringList<T> &sl,const T *str,int size,const T &split_char,int maxSize)
{
if(!str||size<=0)return(-1);
@@ -417,7 +425,7 @@ namespace hgl
return count;
}//int SplitToStringList
template<typename T> int SplitToStringList(StringList<String<T> > &sl,const String<T> &str,const T &split_char,int maxSize)
template<typename T> int SplitToStringList(StringList<T> &sl,const String<T> &str,const T &split_char,int maxSize)
{
return SplitToStringList<T>(sl,str.c_str(),str.Length(),split_char,maxSize);
}
@@ -429,7 +437,7 @@ namespace hgl
* @param size 字符串长度
* @return 字符串行数
*/
template<typename T> int SplitToStringListByEnter(StringList<String<T> > &sl,const T *str,int size)
template<typename T> int SplitToStringListByEnter(StringList<T> &sl,const T *str,int size)
{
if(!str||size<=0)return(-1);
@@ -495,12 +503,12 @@ namespace hgl
return count;
}//int SplitToStringList
template<typename T> int SplitToStringListByEnter(StringList<String<T> > &sl,const String<T> &str)
template<typename T> int SplitToStringListByEnter(StringList<T> &sl,const String<T> &str)
{
return SplitToStringListByEnter<T>(sl,str.c_str(),str.Length());
}
template<typename T> int SplitToStringList(StringList<String<T> > &sl,const String<T> &str)
template<typename T> int SplitToStringList(StringList<T> &sl,const String<T> &str)
{
return SplitToStringList<T>(sl,str.c_str(),str.Length());
}
@@ -513,7 +521,7 @@ namespace hgl
* @param size 字符串长度
* @return 字符串行数
*/
template<typename T> int SplitToMultiStringList(StringList<String<T> > **sl,int slc,const T *str,int size)
template<typename T> int SplitToMultiStringList(StringList<T> **sl,int slc,const T *str,int size)
{
if(!str||size<=0)return(-1);
if(slc<=0)return(-1);
@@ -586,7 +594,7 @@ namespace hgl
return count;
}//int SplitToStringList
template<typename T> int SplitToMultiStringList(StringList<String<T> > **sl,int slc,const String<T> &str)
template<typename T> int SplitToMultiStringList(StringList<T> **sl,int slc,const String<T> &str)
{
if(!sl||slc<=0)return(false);
@@ -602,7 +610,7 @@ namespace hgl
* @param end_line 换行符
* @return 字符串
*/
template<typename T> String<T> ToString(const StringList<String<T>> &sl,const String<T> &end_line)
template<typename T> String<T> ToString(const StringList<T> &sl,const String<T> &end_line)
{
int total_chars=0;
@@ -636,12 +644,16 @@ namespace hgl
return String<T>::newOf(str,total_chars);
}
using UTF8StringList=StringList< UTF8String>;
using UTF16StringList=StringList<UTF16String>;
using UTF32StringList=StringList<UTF32String>;
using AnsiStringList=StringList< AnsiString>;
using WideStringList=StringList< WideString>;
using OSStringList=StringList< OSString>;
#define DEFINE_STRING_LIST(name) using name##StringList=StringList<name##String::CharType>;
DEFINE_STRING_LIST(UTF8)
DEFINE_STRING_LIST(UTF16)
DEFINE_STRING_LIST(UTF32)
DEFINE_STRING_LIST(Ansi)
DEFINE_STRING_LIST(Wide)
DEFINE_STRING_LIST(OS)
#undef DEFINE_STRING_LIST
template<typename T,ByteOrderMask bom> struct ReadStringFromDIS
{
@@ -678,7 +690,7 @@ namespace hgl
* @param dis 数据输入流
* @return 字符串行数
*/
template<typename T,ByteOrderMask bom> int LoadStringList(StringList<String<T> > &sl,io::DataInputStream *dis)
template<typename T,ByteOrderMask bom> int LoadStringList(StringList<T> &sl,io::DataInputStream *dis)
{
if(!dis)return(-1);

View File

@@ -379,5 +379,72 @@ namespace hgl
return(true);
}
/**
* 在多个目录内查找一个文件
* @param filename 要查找的文件名称
* @param paths 要查找的目录
* @param user_data 用户自定义数据
* @param ff 查找响应事件函数
*/
const uint FindFileOnPaths(const OSString &filename,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff)
{
if(filename.IsEmpty()||paths.GetCount()<=0)return(0);
if(ff==nullptr)return 0;
uint count=0;
bool exist;
OSString full_filename;
for(const OSString *pn:paths)
{
full_filename=MergeFilename(*pn,filename);
exist=FileExist(full_filename);
if(exist)
++count;
if(!ff(full_filename,user_data,exist))
return(count);
}
return count;
}
/**
* 在多个目录内查找一个文件,这个文件可能有多个文件名
* @param filenames 要查找的文件名称
* @param paths 要查找的目录
* @param user_data 用户自定义数据
* @param ff 查找响应事件函数
*/
const uint FindFileOnPaths(const OSStringList &filenames,const OSStringList &paths,void *user_data,OnFindedFileFUNC ff)
{
if(filenames.GetCount()<=0||paths.GetCount()<=0)return(0);
if(ff==nullptr)return 0;
uint count=0;
bool exist;
OSString full_filename;
for(const OSString *pn:paths)
{
for(const OSString *fn:filenames)
{
full_filename=MergeFilename(*pn,*fn);
exist=FileExist(full_filename);
if(exist)
++count;
if(!ff(full_filename,user_data,exist))
return(count);
}
}
return count;
}
}//namespace filesystem
}//namespace hgl

View File

@@ -19,7 +19,9 @@ namespace hgl
{
if(!pi_module)return;
plugin_interface->Close();
if(plugin_interface->Close)
plugin_interface->Close();
plugin_interface=nullptr;
delete pi_module;
@@ -74,6 +76,9 @@ namespace hgl
{
if(!plugin_interface)return(false);
if(!plugin_interface->GetInterface)
return(false);
return plugin_interface->GetInterface(ver,interface_data);
}
}//namespace hgl

View File

@@ -5,6 +5,29 @@ namespace hgl
{
using namespace filesystem;
PlugInManage::PlugInManage(const OSString &n)
{
name=OS_TEXT("CMP.")+n;
OSString pn;
if(filesystem::GetCurrentPath(pn))
{
AddFindPath(pn);
pn=MergeFilename(pn,OS_TEXT("Plug-ins"));
AddFindPath(pn);
}
if(filesystem::GetCurrentProgramPath(pn))
{
AddFindPath(pn);
pn=MergeFilename(pn,OS_TEXT("Plug-ins"));
AddFindPath(pn);
}
}
bool PlugInManage::RegistryPlugin(PlugIn *pi)
{
if(!pi)return(false);