📄 hxlist.h
字号:
iterator itCurrent; for (itCurrent = itBegin; itCurrent != end(); ++itCurrent) { if (!key_behaviour::compare((*itCurrent).first, key)) { break; } } return itCurrent; }#endif#endif //IMPLEMENT_KEYED_LIST LIST_FULL_SPEC::_Iterator::_Iterator() : m_pSimpleListWrapped(NULL) , m_ListPosition(NULL) { } LIST_FULL_SPEC::_Iterator::_Iterator ( const CHXSimpleList* pSimpleListWrapped, LISTPOSITION ListPosition ) : m_pSimpleListWrapped((CHXSimpleList*)pSimpleListWrapped) , m_ListPosition(ListPosition) { } LIST_FULL_SPEC::_Iterator::_Iterator ( const LIST_FULL_SPEC::_Iterator& rliocOther ) : m_pSimpleListWrapped(rliocOther.m_pSimpleListWrapped) , m_ListPosition(rliocOther.m_ListPosition) { } LIST_FULL_SPEC::_Iterator::~_Iterator() { } LIST_FULL_SPEC::_Iterator& LIST_FULL_SPEC::_Iterator::operator= ( const LIST_FULL_SPEC::_Iterator& rliocOther ) { m_pSimpleListWrapped = (rliocOther.m_pSimpleListWrapped); m_ListPosition = (rliocOther.m_ListPosition); return *this; } LIST_FULL_SPEC::value_type& LIST_FULL_SPEC::_Iterator::operator*() { HX_ASSERT(m_pSimpleListWrapped && m_ListPosition); return *((LIST_FULL_SPEC::value_type*)m_pSimpleListWrapped->GetAt(m_ListPosition)); } LIST_FULL_SPEC::_Iterator& LIST_FULL_SPEC::_Iterator::operator=(const LIST_FULL_SPEC::value_type& rclsNewValue) { if(m_pSimpleListWrapped && m_ListPosition) { *((LIST_FULL_SPEC::value_type*)m_pSimpleListWrapped->GetAt(m_ListPosition)) = rclsNewValue; } return *this; } LIST_FULL_SPEC::_Iterator& LIST_FULL_SPEC::_Iterator::operator++() { if(m_pSimpleListWrapped && m_ListPosition) { m_pSimpleListWrapped->GetNext(m_ListPosition); } return *this; } const LIST_FULL_SPEC::_Iterator LIST_FULL_SPEC::_Iterator::operator++(int) { _Iterator liocRet(*this); ++(*this); return liocRet; } LIST_FULL_SPEC::_Iterator& LIST_FULL_SPEC::_Iterator::operator--() { if(m_pSimpleListWrapped) { if (!m_ListPosition) { m_ListPosition = m_pSimpleListWrapped->GetTailPosition(); } else { m_pSimpleListWrapped->GetPrev(m_ListPosition); if (!m_ListPosition) { m_ListPosition = m_pSimpleListWrapped->GetHeadPosition(); } } } return *this; } const LIST_FULL_SPEC::_Iterator LIST_FULL_SPEC::_Iterator::operator--(int) { LIST_FULL_SPEC::_Iterator liocRet(*this); --(*this); return liocRet; } BOOL operator== ( const LIST_FULL_SPEC::_Iterator& rliocLeft, const LIST_FULL_SPEC::_Iterator& rliocRight ) { return (rliocLeft.m_pSimpleListWrapped == rliocRight.m_pSimpleListWrapped && rliocLeft.m_ListPosition == rliocRight.m_ListPosition); } BOOL operator!= ( const LIST_FULL_SPEC::_Iterator& rliocLeft, const LIST_FULL_SPEC::_Iterator& rliocRight ) { return (rliocLeft.m_pSimpleListWrapped != rliocRight.m_pSimpleListWrapped || rliocLeft.m_ListPosition != rliocRight.m_ListPosition); }#undef IMPLEMENT_KEYED_LIST#undef IMPLEMENT_LIST#undef LIST_NAME#undef LIST_SCOPE#undef LIST_FULL_SPEC#endif //IMPLEMENT_LIST#ifdef DEFINE_UNIQUELY_KEYED_LIST//#define KEYED_LIST//#define LOOKUP_MAP//#define LIST_NAMEclass LIST_NAME : public KEYED_LIST{public: typedef KEYED_LIST::key_type key_type; typedef KEYED_LIST::key_behaviour key_behaviour; typedef KEYED_LIST::referent_type referent_type; typedef KEYED_LIST::value_type value_type; typedef KEYED_LIST::iterator iterator; typedef KEYED_LIST::const_iterator const_iterator; typedef KEYED_LIST base_list; typedef LOOKUP_MAP lookup_map;public: LIST_NAME(); LIST_NAME(const LIST_NAME& rlocOther); ~LIST_NAME(); LIST_NAME& operator=(const LIST_NAME& rlocOther); iterator insert(iterator itBefore, const value_type&); void insert ( iterator itBefore, const iterator itFirst, const iterator itLast ); iterator insert(const value_type&); iterator remove(iterator itThis); iterator remove(iterator itFirst, iterator itLast); iterator remove(const key_type&); void empty(); KEYED_LIST::_Iterator find(const key_type&);#ifndef _UNIX const KEYED_LIST::_Iterator find(const key_type&) const;#endifprivate: KEYED_LIST::_Iterator find(const KEYED_LIST::_Iterator, const key_type&);#ifndef _UNIX const KEYED_LIST::_Iterator find(const KEYED_LIST::_Iterator, const key_type&) const;#endifprivate: LOOKUP_MAP m_LookupMap; void _copy(const LIST_NAME& rlocOther);};#undef KEYED_LIST#undef LIST_NAME#undef LOOKUP_MAP#undef DEFINE_UNIQUELY_KEYED_LIST#endif //DEFINE_UNIQUELY_KEYED_LIST#ifdef DEFINE_UNIQUELY_KEYED_LIST_GLOBALS#ifndef LIST_SCOPE#define LIST_FULL_SPEC LIST_NAME#else#define LIST_FULL_SPEC LIST_SCOPE::LIST_NAME#endif //!LIST_SCOPE#undef LIST_NAME#undef DEFINE_UNIQUELY_KEYED_LIST_GLOBALS#undef LIST_SCOPE#undef LIST_FULL_SPEC#endif //DEFINE_UNIQUELY_KEYED_LIST_GLOBALS#ifdef IMPLEMENT_UNIQUELY_KEYED_LIST#ifndef LIST_SCOPE#define LIST_FULL_SPEC LIST_NAME#else#define LIST_FULL_SPEC LIST_SCOPE::LIST_NAME#endif //!LIST_SCOPE LIST_FULL_SPEC::LIST_NAME() { } LIST_FULL_SPEC::LIST_NAME(const LIST_FULL_SPEC& rlocOther) { _copy(rlocOther); } LIST_FULL_SPEC::~LIST_NAME() { empty(); } LIST_FULL_SPEC& LIST_FULL_SPEC::operator=(const LIST_FULL_SPEC& rlocOther) { empty(); _copy(rlocOther); return *this; } void LIST_FULL_SPEC::_copy(const LIST_FULL_SPEC& rlocOther) { iterator itOther; for ( itOther = rlocOther.begin(); itOther != rlocOther.end(); ++itOther ) { insert(end(), *itOther); } } LIST_FULL_SPEC::iterator LIST_FULL_SPEC::insert(LIST_FULL_SPEC::iterator itBefore, const LIST_FULL_SPEC::value_type& rvalue) { lookup_map::iterator itValue; iterator itNew; itValue = m_LookupMap.find(rvalue.first); if (itValue == m_LookupMap.end()) { //New insert // insert into ordered list itNew = base_list::insert(itBefore, rvalue); // insert into map m_LookupMap.insert(lookup_map::value_type(rvalue.first, itNew)); } else { // dup insert, replace previous with this. // remove existing from ordered list base_list::remove((*itValue).second); // insert new into ordered list itNew = base_list::insert(itBefore, rvalue); // replace old iterator in the map itValue = lookup_map::value_type(rvalue.first, itNew); } return itNew; } void LIST_FULL_SPEC::insert ( LIST_FULL_SPEC::iterator itBefore, const LIST_FULL_SPEC::iterator itFirst, const LIST_FULL_SPEC::iterator itLast ) { iterator itOther; for (itOther = itFirst; itOther != itLast && itOther != end(); ++itOther) { insert(itBefore, *itOther); } } LIST_FULL_SPEC::iterator LIST_FULL_SPEC::insert(const LIST_FULL_SPEC::value_type& rclsNew) { return insert(begin(), rclsNew); } LIST_FULL_SPEC::iterator LIST_FULL_SPEC::remove(LIST_FULL_SPEC::iterator itThis) { // remove from map m_LookupMap.remove((*itThis).first); // remove from ordered list return base_list::remove(itThis); } LIST_FULL_SPEC::iterator LIST_FULL_SPEC::remove(LIST_FULL_SPEC::iterator itFirst, LIST_FULL_SPEC::iterator itLast) { iterator itOther; for (itOther = itFirst; itOther != itLast && itOther != end();) { itOther = remove(itOther); } return itOther; } LIST_FULL_SPEC::iterator LIST_FULL_SPEC::remove(const LIST_FULL_SPEC::key_type& key) { iterator itNext; lookup_map::iterator itValue; itValue = m_LookupMap.find(key); if (itValue != m_LookupMap.end()) { // Save iterator itNext = (*itValue).second; // remove from map m_LookupMap.remove((*itValue).first); // remove from ordered list itNext = remove(itNext); } else { itNext = end(); } return itNext; } void LIST_FULL_SPEC::empty() { remove(begin(), end()); } LIST_FULL_SPEC::iterator LIST_FULL_SPEC::find(const LIST_FULL_SPEC::key_type& key) { iterator itFound; lookup_map::iterator itValue; itValue = m_LookupMap.find(key); if (itValue != m_LookupMap.end()) { itFound = (*itValue).second; } else { itFound = end(); } return itFound; }#ifndef _UNIX LIST_FULL_SPEC::const_iterator LIST_FULL_SPEC::find(const LIST_FULL_SPEC::key_type& key) const { iterator itFound; lookup_map::iterator itValue; itValue = m_LookupMap.find(key); if (itValue != m_LookupMap.end()) { itFound = (*itValue).second; } else { itFound = end(); } return itFound; }#endif LIST_FULL_SPEC::iterator LIST_FULL_SPEC::find(const LIST_FULL_SPEC::iterator , const LIST_FULL_SPEC::key_type& ) { return end(); }#ifndef _UNIX LIST_FULL_SPEC::const_iterator LIST_FULL_SPEC::find(const LIST_FULL_SPEC::iterator , const LIST_FULL_SPEC::key_type& ) const { return end(); }#endif#undef LIST_NAME#undef IMPLEMENT_UNIQUELY_KEYED_LIST#undef LIST_SCOPE#undef LIST_FULL_SPEC#endif //IMPLEMENT_UNIQUELY_KEYED_LIST
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -