wip: dynamic indices
This commit is contained in:
parent
3dd688bbed
commit
05f4cb0abb
3 changed files with 150 additions and 3 deletions
|
@ -19,7 +19,7 @@ namespace CNORXZ
|
|||
{
|
||||
public:
|
||||
typedef T value_type;
|
||||
typedef ConstContainerIndex const_iterator;
|
||||
typedef DConstContainerIndex<value_type> const_iterator;
|
||||
|
||||
protected:
|
||||
RangePtr mRange;
|
||||
|
@ -65,7 +65,7 @@ namespace CNORXZ
|
|||
typedef DArrayBase<T> DAB;
|
||||
typedef DAB::value_type value_type;
|
||||
typedef DAB::const_iterator const_iterator;
|
||||
typedef DContainerIndex iterator;
|
||||
typedef DContainerIndex<value_type> iterator;
|
||||
|
||||
using DAB::operator[];
|
||||
using DAB::at;
|
||||
|
|
58
src/include/dcontainer_index.h
Normal file
58
src/include/dcontainer_index.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
|
||||
#ifndef __dcontainer_index_h__
|
||||
#define __dcontainer_index_h__
|
||||
|
||||
#include <cstdlib>
|
||||
#include <tuple>
|
||||
#include <memory>
|
||||
|
||||
#include "ranges/range_base.h"
|
||||
#include "ranges/index_base.h"
|
||||
#include "mbase_def.h"
|
||||
#include "statics/static_for.h"
|
||||
#include "ranges/range_helper.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
// Future DynamicIndex
|
||||
class XIndexBase : public IndexInterface<XIndexBase,DType>
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(XIndexBase);
|
||||
// ...!!!
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<XIndexBase> XIndexPtr;
|
||||
|
||||
// MultiIndex Wrapper:
|
||||
template <class... Indices>
|
||||
class XIndex
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<MultiIndex<Indices...>> mI;
|
||||
|
||||
public:
|
||||
DEFAULT_MEMBERS(XIndex);
|
||||
XIndex(const std::shared_ptr<MultiIndex<Indices...>>& i);
|
||||
|
||||
// ....!!!!
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class DConstContainerIndex : public IndexInterface<DConstContainerIndex<T>,DType>
|
||||
{
|
||||
protected:
|
||||
XIndexPtr mI;
|
||||
const T* mCData = nullptr;
|
||||
size_t mCPos = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MDConstContainerIndex : public DConstContainerIndex<T>
|
||||
{
|
||||
private:
|
||||
T* mData = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
||||
// DEP:
|
||||
typedef std::pair<const char*,size_t> DynamicMetaElem;
|
||||
|
||||
template <size_t N>
|
||||
|
@ -25,6 +25,7 @@ namespace CNORXZ
|
|||
}
|
||||
};
|
||||
|
||||
// DEP:
|
||||
template <>
|
||||
struct DynamicMetaSetter<0>
|
||||
{
|
||||
|
@ -38,6 +39,7 @@ namespace CNORXZ
|
|||
};
|
||||
|
||||
|
||||
// DEP:
|
||||
class DynamicMetaT
|
||||
{
|
||||
private:
|
||||
|
@ -65,6 +67,93 @@ namespace CNORXZ
|
|||
const DynamicMetaElem& operator[](size_t pos) const;
|
||||
};
|
||||
|
||||
// NEW:
|
||||
// Type Eraser:
|
||||
class DType
|
||||
{
|
||||
public:
|
||||
DEFAULT_MEMBERS(DType);
|
||||
|
||||
virtual std::string str() const = 0;
|
||||
virtual bool operator==(const DType& in) const = 0;
|
||||
virtual bool operator!=(const DType& in) const = 0;
|
||||
virtual size_t size() const = 0;
|
||||
virtual std::shared_ptr<DType> operator[](size_t pos) const = 0;
|
||||
};
|
||||
|
||||
// NEW:
|
||||
template <typename T>
|
||||
class TypeWrapper : public DType
|
||||
{
|
||||
private:
|
||||
T mD;
|
||||
|
||||
public:
|
||||
TypeWrapper(const T& d) : mD(d) {}
|
||||
DEFAULT_MEMBERS(TypeWrapper);
|
||||
|
||||
virtual std::string str() const { return std::to_string(mD); /*wrapper*/ }
|
||||
virtual bool operator==(const DType& in) const { return this->str() == in.str(); }
|
||||
virtual bool operator!=(const DType& in) const { return this->str() != in.str(); }
|
||||
virtual size_t size() const { return 1; }
|
||||
virtual std::shared_ptr<DType> operator[](size_t pos) const { return nullptr; }
|
||||
};
|
||||
|
||||
// NEW:
|
||||
template <typename T>
|
||||
class TypeRefWrapper : public DType
|
||||
{
|
||||
private:
|
||||
const T* mD;
|
||||
|
||||
public:
|
||||
TypeRefWrapper(const T* d) : mD(d) {}
|
||||
DEFAULT_MEMBERS(TypeRefWrapper);
|
||||
|
||||
virtual std::string str() const { return to_string(*mD); /*wrapper*/ }
|
||||
virtual bool operator==(const DType& in) const { return this->str() == in.str(); }
|
||||
virtual bool operator!=(const DType& in) const { return this->str() != in.str(); }
|
||||
virtual size_t size() const { return 1; }
|
||||
virtual std::shared_ptr<DType> operator[](size_t pos) const { return nullptr; }
|
||||
};
|
||||
|
||||
// NEW:
|
||||
template <typename T>
|
||||
class TypeWrapper<std::vector<T>> : public DType
|
||||
{
|
||||
private:
|
||||
std::vector<T> mD;
|
||||
|
||||
public:
|
||||
TypeWrapper(const std::vector<T>& d) : mD(d) {}
|
||||
DEFAULT_MEMBERS(TypeWrapper);
|
||||
|
||||
virtual std::string str() const { return to_string(mD); /* overload before!!! */ }
|
||||
virtual bool operator==(const DType& in) const { return this->str() == in.str(); }
|
||||
virtual bool operator!=(const DType& in) const { return this->str() != in.str(); }
|
||||
virtual size_t size() const { return mD.size(); }
|
||||
virtual std::shared_ptr<DType> operator[](size_t pos) const { return std::make_shared<TypeRefWrapper>(&mD[pos]); }
|
||||
};
|
||||
|
||||
// NEW:
|
||||
template <typename T>
|
||||
class TypeRefWrapper<std::vector<T>> : public DType
|
||||
{
|
||||
private:
|
||||
const std::vector<T>* mD;
|
||||
|
||||
public:
|
||||
TypeWrapper(const std::vector<T>* d) : mD(d) {}
|
||||
DEFAULT_MEMBERS(TypeWrapper);
|
||||
|
||||
virtual std::string str() const { return to_string(*mD); /* overload before!!! */ }
|
||||
virtual bool operator==(const DType& in) const { return this->str() == in.str(); }
|
||||
virtual bool operator!=(const DType& in) const { return this->str() != in.str(); }
|
||||
virtual size_t size() const { return mD->size(); }
|
||||
virtual std::shared_ptr<DType> operator[](size_t pos) const { return std::make_shared<TypeRefWrapper>(&(*mD)[pos]); }
|
||||
};
|
||||
|
||||
// SPECIALIZE: for std::array<T,N> and std::tuple<T...>
|
||||
|
||||
} // namespace CNORXZ
|
||||
|
||||
|
|
Loading…
Reference in a new issue