minor changes + some extensions

This commit is contained in:
Christian Zimmermann 2017-03-09 19:59:11 +01:00
parent 63eb7d0505
commit d3dbdbb865
4 changed files with 36 additions and 5 deletions

View file

@ -42,6 +42,24 @@ namespace MultiArrayTools
return MultiArrayOperationRoot<T,Range>(*this, Name("master", str...));
}
template <typename T, class Range>
template <class NameType>
MultiArrayOperationRoot<T,Range> MultiArrayBase<T,Range>::operator()(const NameType& name, bool master)
{
if(master){
return MultiArrayOperationRoot<T,Range>(*this, name);
}
else {
return operator()(name);
}
}
template <typename T, class Range>
bool MultiArrayBase<T,Range>::isInit() const
{
return mInit;
}
/*******************
* MultiArray *
*******************/
@ -49,13 +67,17 @@ namespace MultiArrayTools
template <typename T, class Range>
MultiArray<T,Range>::MultiArray(const Range& range) :
MultiArrayBase<T,Range>(range),
mCont(MAB::mRange->size()) {}
mCont(MAB::mRange->size())
{
MAB::mInit = true;
}
template <typename T, class Range>
MultiArray<T,Range>::MultiArray(const Range& range, const std::vector<T>& vec) :
MultiArrayBase<T,Range>(range),
mCont(vec)
{
MAB::mInit = true;
if(mCont.size() > MAB::mRange->size()){
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
}
@ -66,6 +88,7 @@ namespace MultiArrayTools
MultiArrayBase<T,Range>(range),
mCont(vec)
{
MAB::mInit = true;
if(mCont.size() > MAB::mRange->size()){
mCont.erase(mCont.begin() + MAB::mRange->size(), mCont.end());
}
@ -77,6 +100,7 @@ namespace MultiArrayTools
MultiArrayBase<T,Range>(merge(in.range(), in[ in.begin() ].range()))
// assert that Range2 has always same extension
{
MAB::mInit = true;
mCont.clear();
for(auto i = in.begin(); i != in.end(); ++i){
mCont.insert(mCont.end(), in[i].mCont.begin(), in[i].mCont.end());

View file

@ -39,7 +39,13 @@ namespace MultiArrayTools
template <class... NameTypes>
MultiArrayOperationRoot<T,Range> operator()(const NameTypes&... str);
template <class NameType>
MultiArrayOperationRoot<T,Range> operator()(const NameType& name, bool master);
virtual bool isInit() const;
protected:
bool mInit = false;
std::shared_ptr<Range> mRange;
};

View file

@ -74,7 +74,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range>& in)
{
maketurnSlice(in);
if(mArrayRef.isSlice()){
if(mArrayRef.isSlice() and not mArrayRef.isInit()){
return makeSlice(in);
}
performAssignment(in);
@ -86,7 +86,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(MultiArrayOperationRoot<T,Range2>& in)
{
if(mArrayRef.isSlice()){
if(mArrayRef.isSlice() and not mArrayRef.isInit()){
return makeSlice(in);
}
performAssignment(in);
@ -98,7 +98,7 @@ namespace MultiArrayTools
MultiArrayOperationRoot<T,Range>&
MultiArrayOperationRoot<T,Range>::operator=(const MultiArrayOperation<T,Operation,MAOps...>& in)
{
if(mArrayRef.isSlice()){
if(mArrayRef.isSlice() and not mArrayRef.isInit()){
// NO SLICE CREATION !!! (total array not initialized!!)
// throw !
assert(0);

View file

@ -22,6 +22,7 @@ namespace MultiArrayTools
const typename MARange::IndexType& MAIdx, // for desired slice position
const Name& MANm) // for correct linkage)
{
MAB::mInit = true;
mMultiArrayPtr = &multiArrayRef;
mMAIdx = MAIdx;
mOwnIdx = MAB::mRange->begin();