class ObjectStorage
{
private:
std::string objName;
int zIndex;
// Reference for the Object interface
boost::shared_ptr<Object> mCppObject;
// Reference for the Python interface
boost::python::object mPythonObject;
public:
ObjectStorage(const std::string &name, int zIndex_, boost::shared_ptr<Object> cpp, boost::python::object python)
: objName(name), zIndex(zIndex_),
mCppObject(cpp), mPythonObject(python) {}
std::string getName() const { return objName; };
int getZIndex() const { return zIndex; }
boost::shared_ptr<Object> getCppObject() const { return mCppObject; }
boost::python::object getPythonObject() const { return mPythonObject; }
};
// Tagging for multi_index container
struct tag_zindex {};
struct tag_name {};
struct tag_cpp {};
struct tag_py {};
typedef boost::multi_index_container<ObjectStorage,
bmi::indexed_by<
// ZIndex
bmi::ordered_non_unique<
bmi::tag<tag_zindex>,
bmi::const_mem_fun<ObjectStorage, int, &ObjectStorage::getZIndex>
>,
// Name
bmi::ordered_unique<
bmi::tag<tag_name>,
bmi::const_mem_fun<ObjectStorage, std::string, &ObjectStorage::getName>
>,
// CPP reference
bmi::ordered_non_unique<
bmi::tag<tag_cpp>,
bmi::const_mem_fun<ObjectStorage, boost::shared_ptr<Object>, &ObjectStorage::getCppObject>
>,
// Python reference
bmi::ordered_unique<
bmi::tag<tag_py>,
bmi::const_mem_fun<ObjectStorage, boost::python::object, &ObjectStorage::getPythonObject>
>
>
> ObjectWrapperSet;
如果第一个索引multi_index
是正确的:容器内的排序对象引用ZIndex
值,我不确定另一个。我需要这样的功能:按 ZIndex 排序,但getCppObject
在迭代时返回。是否不仅可以设置排序,还可以在访问时设置结果?
另外,例如,tag_py
我想遍历 all getPythonObject
,而不是ObjectStorage
. 这真的可能multi_index
吗?