diff --git a/inc/hgl/Macro.h b/inc/hgl/Macro.h index 372ed82..ce84daa 100644 --- a/inc/hgl/Macro.h +++ b/inc/hgl/Macro.h @@ -116,11 +116,5 @@ namespace hgl else \ return(false); \ } - - template 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 diff --git a/inc/hgl/TypeFunc.h b/inc/hgl/TypeFunc.h index f3c05c8..7b542e5 100644 --- a/inc/hgl/TypeFunc.h +++ b/inc/hgl/TypeFunc.h @@ -15,9 +15,7 @@ namespace hgl template inline bool RangeCheck(const T &value) { - if(valueT::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 diff --git a/inc/hgl/filesystem/FileSystem.h b/inc/hgl/filesystem/FileSystem.h index a68bd3e..584bd4d 100644 --- a/inc/hgl/filesystem/FileSystem.h +++ b/inc/hgl/filesystem/FileSystem.h @@ -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); ///<在多个目录内查找一个文件,这个文件可能有多个文件名 + /** * 文件名长度限制 * diff --git a/inc/hgl/filesystem/Filename.h b/inc/hgl/filesystem/Filename.h index acc365f..4d065ad 100644 --- a/inc/hgl/filesystem/Filename.h +++ b/inc/hgl/filesystem/Filename.h @@ -79,7 +79,7 @@ namespace hgl * 根据离散的每一级目录名称和最终名称合成完整文件名 */ template - inline const String ComboFilename(const StringList> &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) + inline const String ComboFilename(const StringList &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) { T **str_list=AutoDeleteArray(sl.GetCount()); int *str_len=AutoDeleteArray(sl.GetCount()); diff --git a/inc/hgl/plugin/PlugInManage.h b/inc/hgl/plugin/PlugInManage.h index c5ed464..ab0bf53 100644 --- a/inc/hgl/plugin/PlugInManage.h +++ b/inc/hgl/plugin/PlugInManage.h @@ -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 &); ///<释放一个内置插件 diff --git a/inc/hgl/type/Smart.h b/inc/hgl/type/Smart.h index bf4a0b4..249dcdf 100644 --- a/inc/hgl/type/Smart.h +++ b/inc/hgl/type/Smart.h @@ -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;} diff --git a/inc/hgl/type/StrChar.h b/inc/hgl/type/StrChar.h index 65af87c..7c87769 100644 --- a/inc/hgl/type/StrChar.h +++ b/inc/hgl/type/StrChar.h @@ -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; } /** diff --git a/inc/hgl/type/String.h b/inc/hgl/type/String.h index ecbc5d1..7792a3e 100644 --- a/inc/hgl/type/String.h +++ b/inc/hgl/type/String.h @@ -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); } /** diff --git a/inc/hgl/type/StringInstance.h b/inc/hgl/type/StringInstance.h index 6096dca..315f0c4 100644 --- a/inc/hgl/type/StringInstance.h +++ b/inc/hgl/type/StringInstance.h @@ -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 比较字符串 diff --git a/inc/hgl/type/StringList.h b/inc/hgl/type/StringList.h index a853b27..8e52cd1 100644 --- a/inc/hgl/type/StringList.h +++ b/inc/hgl/type/StringList.h @@ -5,6 +5,7 @@ #include #include #include +#include namespace hgl { @@ -15,28 +16,29 @@ namespace hgl */ template class StringList ///字符串列表处理类 { - static T NullString; + using StringClass=String; + static StringClass NullString; protected: - ObjectList Items; + ObjectList 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 &operator = (const StringList &sl) + StringList &operator = (const StringList &sl) { Clear(); const int n=sl.GetCount(); - T *str; + StringClass *str; for(int i=0;i <) + { + 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 &sl) ///<添加字符串 + int Add(const StringList &sl) ///<添加字符串 { const int count=sl.GetCount(); - T **str=sl.Items.GetData(); + StringClass **str=sl.Items.GetData(); for(int i=0;iComp(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;iComp(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::Insert(index,new T(str)); + Items.List::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 class StringList - template T StringList::NullString; ///<空字符串实例 + template String StringList::NullString; ///<空字符串实例 /** * 以不可打印字符为分隔拆解一个字符串到一个字符串列表 @@ -242,7 +250,7 @@ namespace hgl * @param size 字符串长度 * @return 字符串行数 */ - template int SplitToStringListBySpace(StringList > &sl,const T *str,int size) + template int SplitToStringListBySpace(StringList &sl,const T *str,int size) { if(!str||size<=0)return(-1); @@ -297,7 +305,7 @@ namespace hgl * @param split_char 分隔字符 * @return 字符串行数 */ - template int SplitToStringList(StringList > &sl,const T *str,int size,const T &split_char) + template int SplitToStringList(StringList &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 int SplitToStringListFromString(StringList > &sl,const String &str,const T &split_char) + template int SplitToStringListFromString(StringList &sl,const String &str,const T &split_char) { return SplitToStringList(sl,str.c_str(),str.Length(),split_char); } @@ -358,7 +366,7 @@ namespace hgl * @param maxSize 最多执行次数 * @return 字符串行数 */ - template int SplitToStringList(StringList > &sl,const T *str,int size,const T &split_char,int maxSize) + template int SplitToStringList(StringList &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 int SplitToStringList(StringList > &sl,const String &str,const T &split_char,int maxSize) + template int SplitToStringList(StringList &sl,const String &str,const T &split_char,int maxSize) { return SplitToStringList(sl,str.c_str(),str.Length(),split_char,maxSize); } @@ -429,7 +437,7 @@ namespace hgl * @param size 字符串长度 * @return 字符串行数 */ - template int SplitToStringListByEnter(StringList > &sl,const T *str,int size) + template int SplitToStringListByEnter(StringList &sl,const T *str,int size) { if(!str||size<=0)return(-1); @@ -495,12 +503,12 @@ namespace hgl return count; }//int SplitToStringList - template int SplitToStringListByEnter(StringList > &sl,const String &str) + template int SplitToStringListByEnter(StringList &sl,const String &str) { return SplitToStringListByEnter(sl,str.c_str(),str.Length()); } - template int SplitToStringList(StringList > &sl,const String &str) + template int SplitToStringList(StringList &sl,const String &str) { return SplitToStringList(sl,str.c_str(),str.Length()); } @@ -513,7 +521,7 @@ namespace hgl * @param size 字符串长度 * @return 字符串行数 */ - template int SplitToMultiStringList(StringList > **sl,int slc,const T *str,int size) + template int SplitToMultiStringList(StringList **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 int SplitToMultiStringList(StringList > **sl,int slc,const String &str) + template int SplitToMultiStringList(StringList **sl,int slc,const String &str) { if(!sl||slc<=0)return(false); @@ -602,7 +610,7 @@ namespace hgl * @param end_line 换行符 * @return 字符串 */ - template String ToString(const StringList> &sl,const String &end_line) + template String ToString(const StringList &sl,const String &end_line) { int total_chars=0; @@ -636,12 +644,16 @@ namespace hgl return String::newOf(str,total_chars); } - using UTF8StringList=StringList< UTF8String>; - using UTF16StringList=StringList; - using UTF32StringList=StringList; - using AnsiStringList=StringList< AnsiString>; - using WideStringList=StringList< WideString>; - using OSStringList=StringList< OSString>; +#define DEFINE_STRING_LIST(name) using name##StringList=StringList; + + 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 struct ReadStringFromDIS { @@ -678,7 +690,7 @@ namespace hgl * @param dis 数据输入流 * @return 字符串行数 */ - template int LoadStringList(StringList > &sl,io::DataInputStream *dis) + template int LoadStringList(StringList &sl,io::DataInputStream *dis) { if(!dis)return(-1); diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index 257656c..db2f693 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -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 diff --git a/src/PlugIn/ExternalPlugIn.cpp b/src/PlugIn/ExternalPlugIn.cpp index bd76f66..11fb51a 100644 --- a/src/PlugIn/ExternalPlugIn.cpp +++ b/src/PlugIn/ExternalPlugIn.cpp @@ -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 diff --git a/src/PlugIn/PlugInManage.cpp b/src/PlugIn/PlugInManage.cpp index 792cc69..0b6a512 100644 --- a/src/PlugIn/PlugInManage.cpp +++ b/src/PlugIn/PlugInManage.cpp @@ -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);