1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
/*!
@file
@author Albert Semenov
@date 10/2008
*/
#ifndef MIRROR_LIST_H_
#define MIRROR_LIST_H_
#include "MyGUI.h"
namespace unittest
{
class Mirror_List
{
public:
//------------------------------------------------------------------------------//
// манипуляции айтемами
//! Get number of items
size_t getItemCount() const
{
return mItemsInfo.size();
}
//! Insert an item into a array at a specified position
void insertItemAt(size_t _index, const MyGUI::UString& _name, MyGUI::Any _data = MyGUI::Any::Null)
{
MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "ListBox::insertItemAt");
if (_index == MyGUI::ITEM_NONE) _index = mItemsInfo.size();
mItemsInfo.insert(mItemsInfo.begin() + _index, ItemInfo(_name, _data));
}
//! Add an item to the end of a array
void addItem(const MyGUI::UString& _name, MyGUI::Any _data = MyGUI::Any::Null)
{
insertItemAt(MyGUI::ITEM_NONE, _name, _data);
}
//! Remove item at a specified position
void removeItemAt(size_t _index)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::removeItemAt");
mItemsInfo.erase(mItemsInfo.begin() + _index);
}
//! Remove all items
void removeAllItems()
{
mItemsInfo.clear();
}
//! Swap items at a specified position
void swapItemsAt(size_t _index1, size_t _index2)
{
MYGUI_ASSERT_RANGE(_index1, mItemsInfo.size(), "ListBox::swapItemsAt");
MYGUI_ASSERT_RANGE(_index2, mItemsInfo.size(), "ListBox::swapItemsAt");
if (_index1 == _index2) return;
std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
}
//! Search item, returns the position of the first occurrence in array or ITEM_NONE if item not found
size_t findItemIndexWith(const MyGUI::UString& _name) const
{
for (size_t pos = 0; pos < mItemsInfo.size(); pos++)
{
if (mItemsInfo[pos].name == _name) return pos;
}
return MyGUI::ITEM_NONE;
}
//------------------------------------------------------------------------------//
// манипуляции данными
//! Replace an item data at a specified position
void setItemDataAt(size_t _index, MyGUI::Any _data)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::setItemDataAt");
mItemsInfo[_index].data = _data;
}
//! Clear an item data at a specified position
void clearItemDataAt(size_t _index)
{
setItemDataAt(_index, MyGUI::Any::Null);
}
//! Get item data from specified position
template <typename ValueType>
ValueType* getItemDataAt(size_t _index, bool _throw = true) const
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemDataAt");
return mItemsInfo[_index].data.castType<ValueType>(_throw);
}
//------------------------------------------------------------------------------//
// манипуляции отображением
//! Replace an item name at a specified position
void setItemNameAt(size_t _index, const MyGUI::UString& _name)
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::setItemNameAt");
mItemsInfo[_index].name = _name;
}
//! Get item name from specified position
const MyGUI::UString& getItemNameAt(size_t _index) const
{
MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemNameAt");
return mItemsInfo[_index].name;
}
private:
struct ItemInfo
{
ItemInfo(const MyGUI::UString& _name, MyGUI::Any& _data) :
name(_name),
data(_data)
{
}
MyGUI::UString name;
MyGUI::Any data;
};
typedef std::vector<ItemInfo> VectorItemInfo;
VectorItemInfo mItemsInfo;
};
} // namespace unittest
#endif // MIRROR_LIST_H_
|