====== XManager ====== **//Inherited from//** NULL **//Inherited by//** NULL **//Friend class//** NULL **//Description//** XManager是XT框架数据管理的核心,XT中所有的数据对象均从[[class:domain:xitem|XItem]]继承,数据对象的创建、销毁以及索引均由对应的数据对象管理器完成,所有的数据对象管理器均从XManager继承而来。 原则上,一种数据对象管理器只负责管理概念上属于同一种类的对象(同一种类的对象可细分为若干子类型),这里将种类定义为管理器的域类型(DomainType),对于外部访问,它是一个不大于16个字符的字符串类型名(ctypeString()),在注册时给定;对于内部访问,它是一个不大于256的整型识别码(ctype()),在注册时自动生成或者显式设定。数据对象管理器与对象域一一对应,一种数据对象管理器对应一个静态的字符串域类型名和一个动态生成的整数域标识码;每种数据对象也唯一的对应一个静态的字符串对象类型名和一个动态生成的整数对象识别码。XManager维护了一份全局的域类型映射表和对象类型映射表,域类型名被唯一的映射到域识别码,对象类型名被唯一的映射到对象识别码,域识别码表示对象管理器的序号,对象识别码表示了对象在对象管理器中的序号,因此XManager可以使用统一的接口去访问任意一个对象。 从XManager继承的任意数据对象管理器维护了它所管理的对象的构造函数列表和析构函数列表,并开辟一个独立的内存池空间(XMemPool)和散列索引(XHash),创建对象时均从内存池中分配内存并初始化,赋给其唯一的身份ID,插入到散列索引中,然后,通过ID就可以快速的访问到指定对象。 **//Members//** * OpnRecorder * [[xmanager#m_popnrecorder|m_pOpnRecorder]] * bool m_bAutomaticItemType = [[xmanager#false|false]] * bool m_bAutomaticDomainType = [[xmanager#false|false]] * ulong [[xmanager#m_ulnextitemid|m_ulNextItemId]] * TypeID [[xmanager#m_idomainid|m_iDomainID]] * TypeID [[xmanager#m_idomaintype|m_iDomainType]] * XHash * [[xmanager#m_pitemhash|m_pItemHash]] * AllocItemFunc * [[xmanager#m_fpitemalloc|m_fpItemAlloc]] * FreeItemFunc * [[xmanager#m_fpitemfree|m_fpItemFree]] * XMemPool * [[xmanager#m_pxmempool|m_pXMemPool]] **//Public interface//** * [[xmanager#xmanager1|XManager]](TypeID domainType, int initHashSize, XMemPool * memPool, int defaultMemSize) * [[xmanager#xmanager2|XManager]](TypeID domainType) * static ulong [[xmanager#registercitem|registerCItem]](const char * itemTypeString, TypeID domainType, AllocItemFunc itemAlloc, FreeItemFunc itemFree, TypeID itemType = DItem_Unknown) * static ulong [[xmanager#registerdomain|registerDomain]](const char * domainTypeString, TypeID domainType = Domain_Unknown) * static const char * [[xmanager#getctypestring|getCtypeString]](ulong ctype) * static ulong [[xmanager#getctype|getCtype]](const char * typeString) * static ulong [[xmanager#getnextdomaintype|getNextDomainType]]() * static bool [[xmanager#updatenextdomaintype|updateNextDomainType]](ulong curType) * static TypeID [[xmanager#getnextctype|getNextCtype]](ulong domain) * static bool [[xmanager#registeritem|registerItem]](TypeID type, TypeID domainType, AllocItemFunc itemAlloc, FreeItemFunc itemFree) * static AllocItemFunc * [[xmanager#getitemalloctable|getItemAllocTable]](TypeID domainType) * static FreeItemFunc * [[xmanager#getitemfreetable|getItemFreeTable]](TypeID domainType) * DomainType [[xmanager#getdomaintype|getDomainType]]() const * bool [[xmanager#isautomaticitemtype|isAutomaticItemType]]() const * void [[xmanager#registertorecorder|registerToRecorder]](OpnRecorder * rec, int domainID = -1) * virtual void [[xmanager#additem|addItem]](XItem * item) * virtual void [[xmanager#collectitems|collectItems]](vector * itemArr, TypeID tid = DItem_Unknown) * virtual void [[xmanager#updateafterrenumber|updateAfterRenumber]](TypeID tid = DItem_Unknown) * XItem * [[xmanager#newitem|newItem]](int tid = 0) * XItem * [[xmanager#createitem|createItem]](ulong id = 0, int tid = 0/*,bool bRecord = true*/) * virtual void [[xmanager#removeitem|removeItem]](XItem * item/*,bool bRecord = true*/) * void [[xmanager#destroyitem|destroyItem]](XItem * itm, bool bDestruct = true) * const XItem * [[xmanager#getitem|getItem]](ulong id) const * template T * [[xmanager#checkOutItem|checkOutItem]](ulong id) * virtual void [[xmanager#setprevnext|setPrevNext]](XItem * item, int prevID, int nextID) * virtual void [[xmanager#serializeprevnext|serializePrevNext]](XBinaryIO * io, XItem * obj, bool bSave) * virtual void [[xmanager#write|write]](XH5IO * io, H5Obj * grp) * XItem * [[xmanager#serializerecord|serializeRecord]](XBinaryIO * io, int & opn, bool bUndo) * virtual void [[xmanager#serialize|serialize]](XBinaryIO * io, XItem * obj, bool bSave) = 0 * virtual void [[xmanager#serializelinks|serializeLinks]](XBinaryIO * io, XItem * obj, bool bSave) * virtual void [[xmanager#linkitem|linkItem]](XItem * master, const XItem * slave, bool bAttach) * virtual const XItem * [[xmanager#getlinkitem|getLinkItem]](TypeID type, ulong id) * virtual void [[xmanager#bindlinkmanager|bindLinkManager]](TypeID domanType, XManager * mgr) * void [[xmanager#serializelinkitem|serializeLinkItem]](XBinaryIO * record, const XItem *& obj, bool bSave) * void [[xmanager#binditemiterator|bindItemIterator]](ItemIterator * iter) const * ulong [[xmanager#getitemcount|getItemCount]]() const * virtual void [[xmanager#clear|clear]]() * virtual void [[xmanager#recordexchange|recordExchange]](XItem * item, XBinaryIO * io) * ulong [[xmanager#getnextitemid|getNextItemId]]() const * void [[xmanager#setnextitemid|setNextItemId]](ulong id) * void [[xmanager#getnextitemname|getNextItemName]](const char * curName, string * name) const * void [[xmanager#sortitembyid|sortItemById]](vector * item_list) const * void [[xmanager#sortitembyname|sortItemByName]](vector * item_list) * const NItem * [[xmanager#getitembyname|getItemByName]](const char * name, ulong excludeID = 0) * const XItem * [[xmanager#readitemptr|readItemPtr]](XBinaryIO * io) * void [[xmanager#updateallcache|updateAllCache]]() * virtual bool [[xmanager#getobjectpropertysheet|getObjectPropertySheet]](const XItem * obj, vector * prpSheet) **//Protected interface//** * void [[xmanager#reindexitem|reIndexItem]](const XItem * item, ulong ulNewID) * virtual void [[xmanager#updateprevnext|updatePrevNext]](XItem * item, int prevID, int nextID) ---- {{anchor:m_popnrecorder}} **OpnRecorder * m_pOpnRecorder** {{anchor:false}} **bool m_bAutomaticItemType = false** {{anchor:false}} **bool m_bAutomaticDomainType = false** {{anchor:m_ulnextitemid}} **ulong m_ulNextItemId** {{anchor:m_idomainid}} **TypeID m_iDomainID** {{anchor:m_idomaintype}} **TypeID m_iDomainType** {{anchor:m_pitemhash}} **XHash * m_pItemHash** {{anchor:m_fpitemalloc}} **AllocItemFunc * m_fpItemAlloc** {{anchor:m_fpitemfree}} **FreeItemFunc * m_fpItemFree** {{anchor:m_pxmempool}} **XMemPool * m_pXMemPool** ---- {{anchor:xmanager1}} **XManager(TypeID domainType, int initHashSize, XMemPool * memPool, int defaultMemSize)** *function: 构造函数 *parameters: - [i]TypeID domainType: 域类型ID - [i] int initHashSize: 初始对象数目规模 - [i] XMemPool * memPool: 对象内存池 - [i] int defaultMemSize: 默认内存池大小 *return value: 无 {{anchor:xmanager2}} **XManager(TypeID domainType)** *function: 构造函数 *parameters: - [i]TypeID domainType: 域类型ID *return value: 无 {{anchor:registercitem}} **static ulong registerCItem(const char * itemTypeString, TypeID domainType, AllocItemFunc itemAlloc, FreeItemFunc itemFree, TypeID itemType = DItem_Unknown)** *function: 注册数据对象类型 *parameters: - [i]const char * itemTypeString: 数据对象类型字符串标识 - [i] TypeID domainType: 域类型 - [i] AllocItemFunc itemAlloc: 数据对象构造API - [i] FreeItemFunc itemFree: 数据对象析构API - [i] TypeID itemType = DItem_Unknown: 强制指定数据对象类型ID *return value: 返回数据对象类型ID,itemType为DItem_Unknown时ID为程序自动分配(以域类型ID*10000为基数自动递增),否则为指定的ID {{anchor:registerdomain}} **static ulong registerDomain(const char * domainTypeString, TypeID domainType = Domain_Unknown)** *function: 注册对象管理器 *parameters: - [i]const char * domainTypeString: 域类型字符串标识 - [i] TypeID domainType = Domain_Unknown: 强制指定域类型ID *return value: 返回对象管理器的域类型ID,domainType为Domain_Unknown时ID为程序自动分配(从1递增),否则为指定的ID {{anchor:getctypestring}} **static const char * getCtypeString(ulong ctype)** *function: 获取类型ID为ctype的字符串标识(类型可能为数据对象类型,也可能为域类型) *parameters: - [i]ulong ctype: 给定的类型ID *return value: 字符串标识 {{anchor:getctype}} **static ulong getCtype(const char * typeString)** *function: 获取与给定字符串标识对应的类型ID *parameters: - [i]const char * typeString: 字符串标识 *return value: 类型ID {{anchor:getnextdomaintype}} **static ulong getNextDomainType()** *function: 获取下一个可用的域类型ID,一般在注册对象管理器时调用 *parameters: NULL *return value: 下一个可用的域类型ID {{anchor:updatenextdomaintype}} **static bool updateNextDomainType(ulong curType)** *function: 根据curType更新下一个可用的域类型ID,如当前的最大域类型ID不大于curType,则设置下一个类型ID为curType加1 *parameters: - [i]ulong curType: 当前有效的域类型ID *return value: 返回true {{anchor:getnextctype}} **static TypeID getNextCtype(ulong domain)** *function: 在domain域内获取下一个对象类型ID *parameters: - [i]ulong domain: 指定域类型ID *return value: 下一个对象类型ID {{anchor:getitemalloctable}} **static AllocItemFunc * getItemAllocTable(TypeID domainType)** *function: 获取指定域的构造函数数组 *parameters: - [i]TypeID domainType: 指定域ID *return value: 指定域的构造函数数组 {{anchor:getitemfreetable}} **static FreeItemFunc * getItemFreeTable(TypeID domainType)** *function: 获取指定域的析构函数数组 *parameters: - [i]TypeID domainType: 指定域ID *return value: 指定域的析构函数数组 {{anchor:getdomaintype}} **DomainType getDomainType() const** *function: 获取管理器的域ID *parameters: NULL *return value: 域ID {{anchor:isautomaticitemtype}} **bool isAutomaticItemType() const** *function: 数据对象类型是否自动赋予类型ID *parameters: NULL *return value: 如数据对象是自动赋予类型ID返回true,否则返回false {{anchor:registertorecorder}} **void registerToRecorder(OpnRecorder * rec, int domainID = -1)** *function: 将管理器注册到数据对象记录器中,用于记录数据的操作历史 *parameters: - [i]OpnRecorder * rec: 数据操作记录器 - [i] int domainID = -1: 指定管理器的注册序号,如为-1则有程序自动给定 *return value: 无 {{anchor:additem}} **virtual void addItem(XItem * item)** *function: 将数据对象添加到管理器中 *parameters: - [i]XItem * item: 数据对象 *return value: 无 {{anchor:collectitems}} **virtual void collectItems(vector * itemArr, TypeID tid = DItem_Unknown)** *function: 收集管理器中的数据对象 *parameters: - [i]vector * itemArr: 数据对象数组 - [i] TypeID tid = DItem_Unknown: 指定收集的数据对象子类型,如为DItem_Unknown,收集所有的对象 *return value: 无 {{anchor:updateafterrenumber}} **virtual void updateAfterRenumber(TypeID tid = DItem_Unknown)** *function: 在指定类型的数据对象重新编号后更新管理器 *parameters: - [i]TypeID tid = DItem_Unknown: 重新编号的数据对象类型ID,如为DItem_Unknown表示任意对象重新编号之后都更新管理器 *return value: 无 {{anchor:newitem}} **XItem * newItem(int tid = 0)** *function: 构造类型为tid的数据对象,该数据对象不能被索引 *parameters: - [i]int tid = 0: 指定数据对象类型ID, 如该管理器只管理一种数据对象则tid可给0值 *return value: 新建对象指针 {{anchor:createitem}} **XItem * createItem(ulong id = 0, int tid = 0)** *function: 新建数据对象并加入到管理器中(可通过ID索引数据对象) *parameters: - [i]ulong id = 0: 数据对象的ID,如为0,则ID为自动分配 - [i] int tid = 0:数据对象的类型ID *return value: 数据对象的指针 {{anchor:removeitem}} **virtual void removeItem(XItem * item)** *function: *parameters: - [i]XItem * item: 从管理器中删除对象(对象没有被销毁),它不再被索引 *return value: 无 {{anchor:destroyitem}} **void destroyItem(XItem * itm, bool bDestruct = true)** *function: 销毁对象 *parameters: - [i]XItem * itm: 数据对象指针 - [i] bool bDestruct = true: 是否延迟销毁 *return value: 无 {{anchor:getitem}} **const XItem * getItem(ulong id) const** *function: 通过ID索引数据对象 *parameters: - [i]ulong id: 数据对象ID *return value: 数据对象指针,如ID为id的对象不存在返回NULL {{anchor:setprevnext}} **virtual void setPrevNext(XItem * item, int prevID, int nextID)** *function: 为有序对象设置前置后置对象 *parameters: - [i]XItem * item: 有序对象 - [i] int prevID: 前置对象ID - [i] int nextID: 后置对象ID *return value: 无 {{anchor:serializeprevnext}} **virtual void serializePrevNext(XBinaryIO * io, XItem * obj, bool bSave)** *function: 序列化有序对象,在记录数据操作时调用 *parameters: - [i]XBinaryIO * io: 二进制文件句柄 - [i] XItem * obj: 有序对象 - [i] bool bSave: 是否保存 *return value: 无 {{anchor:write}} **virtual void write(XH5IO * io, H5Obj * grp)** *function: 将数据对象写入到H5文件中 *parameters: - [i]XH5IO * io: H5文件句柄 - [i] H5Obj * grp: 管理器所在的H5节点 *return value: 无 {{anchor:serializerecord}} **XItem * serializeRecord(XBinaryIO * io, int & opn, bool bUndo)** *function: 在undo或redo时序列化对象 *parameters: - [i]XBinaryIO * io: 二进制文件句柄 - [i] int & opn: 数据的操作类型(增加、删除或修改) - [i] bool bUndo: 是否undo *return value: 返回数据对象的指针 {{anchor:serialize}} **virtual void serialize(XBinaryIO * io, XItem * obj, bool bSave) = 0** *function: 序列化数据对象 *parameters: - [i]XBinaryIO * io: 二进制文件句柄 - [i] XItem * obj: 数据对象 - [i] bool bSave: 是否保存 *return value: 无 {{anchor:serializelinks}} **virtual void serializeLinks(XBinaryIO * io, XItem * obj, bool bSave)** *function: 序列化数据对象的引用对象 *parameters: - [i]XBinaryIO * io: 二进制文件句柄 - [i] XItem * obj: 数据对象 - [i] bool bSave: 是否保存 *return value: 无 {{anchor:linkitem}} **virtual void linkItem(XItem * master, const XItem * slave, bool bAttach)** *function: 定义数据对象的引用关系 *parameters: - [i]XItem * master: 数据对象 - [i] const XItem * slave: 被应用的对象 - [i] bool bAttach: 是否添加引用关系(如否则为解除引用关系) *return value: 无 {{anchor:getlinkitem}} **virtual const XItem * getLinkItem(TypeID type, ulong id)** *function: 获取引用对象 *parameters: - [i]TypeID type: 引用对象类型 - [i] ulong id: 引用对象ID *return value: 引用对象指针 {{anchor:bindlinkmanager}} **virtual void bindLinkManager(TypeID domanType, XManager * mgr)** *function: 设置引用对象管理器(用来索引引用对象) *parameters: - [i]TypeID domanType: 引用对象的域ID - [i] XManager * mgr: 引用对象的管理器 *return value: 无 {{anchor:serializelinkitem}} **void serializeLinkItem(XBinaryIO * record, const XItem *& obj, bool bSave)** *function: 序列化引用对象(用于记录数据操作) *parameters: - [i]XBinaryIO * io: 数据操作记录文件句柄 - [i] const XItem *& obj: 数据对象 - [i] bool bSave: 是否保存 *return value: 无 {{anchor:binditemiterator}} **void bindItemIterator(ItemIterator * iter) const** *function: 绑定对象遍历器 *parameters: - [i]ItemIterator * iter: 对象遍历器 *return value: 无 {{anchor:getitemcount}} **ulong getItemCount() const** *function: 获取对象数目 *parameters: NULL *return value: 对象数目 {{anchor:clear}} **virtual void clear()** *function: 清空对象 *parameters: NULL *return value: 无 {{anchor:recordexchange}} **virtual void recordExchange(XItem * item, XBinaryIO * io)** *function: 从数据操作记录文件中存取数据对象 *parameters: - [i]XItem * item: 数据对象 - [i] XBinaryIO * io: 数据操作记录文件句柄 *return value: 无 {{anchor:getnextitemid}} **ulong getNextItemId() const** *function: 获取下一个对象ID(为对象自动分配ID时使用) *parameters: NULL *return value: 下一个对象ID {{anchor:setnextitemid}} **void setNextItemId(ulong id)** *function: 设置下一个对象ID(为对象自动分配ID时使用) *parameters: - [i]ulong id: 下一个对象ID *return value: 无 {{anchor:getnextitemname}} **void getNextItemName(const char * curName, string * name) const** *function: 根据当前名字获取下一个可用命名 *parameters: - [i]const char * curName: 当前名字 - [i] string * name: 下一个名字 *return value: 无 {{anchor:sortitembyid}} **void sortItemById(vector * item_list) const** *function: 将数据对象按照ID的升序排列输出为对象数组 *parameters: - [i]vector * item_list: 对象数组 *return value: 无 {{anchor:sortitembyname}} **void sortItemByName(vector * item_list)** *function: 将数据对象按照对象名的升序排列输出为数组 *parameters: - [i]vector * item_list: 对象指针数组 *return value: 无 {{anchor:getitembyname}} **const NItem * getItemByName(const char * name, ulong excludeID = 0)** *function: 通过名字索引对象 *parameters: - [i]const char * name: 对象名字 - [i] ulong excludeID = 0: 排除给定ID(不为0)的对象 *return value: 对象指针 {{anchor:updateallcache}} **void updateAllCache()** *function: 更新所有数据对象的缓存信息 *parameters: NULL *return value: 无 {{anchor:getobjectpropertysheet}} **virtual bool getObjectPropertySheet(const XItem * obj, vector * prpSheet)** *function: 获取数据对象的属性清单 *parameters: - [i]const XItem * obj: 数据对象 - [i] vector * prpSheet: 属性清单 *return value: 成功获取返回true,否则返回false ---- {{anchor:reindexitem}} **void reIndexItem(const XItem * item, ulong ulNewID)** *function: 对数据对象重新编号 *parameters: - [i]const XItem * item: 数据对象 - [i] ulong ulNewID: 新的编号 *return value: 无 {{anchor:updateprevnext}} **virtual void updatePrevNext(XItem * item, int prevID, int nextID)** *function: 更新有序对象的前后对象信息 *parameters: - [i]XItem * item: 有序对象 - [i] int prevID: 前置对象ID - [i] int nextID: 后置对象ID *return value: 无