Skip to content

Commit

Permalink
TupleBase
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeura committed Sep 16, 2024
1 parent 529523b commit c711291
Show file tree
Hide file tree
Showing 39 changed files with 724 additions and 450 deletions.
2 changes: 1 addition & 1 deletion src/data/Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class PlainData : public TreeWrapper<DT> {
//data.setPhysicalScale(min, max);
data.setPhysicalRange(min, max, true);
// data.setOptimalScale();
this->odim.scaling.assign(data.getScaling());
this->odim.scaling.assignSequence(data.getScaling());
// odim.scaling.scale = data.getScaling().scale; // needed?
// odim.scaling.offset = data.getScaling().offset; // needed?
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/EncodingODIM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void EncodingODIM::updateLenient(const EncodingODIM & odim){
type = odim.type;

if ((this->scaling.scale == 0.0) && (type == odim.type)){
this->scaling.assign(odim.scaling);
this->scaling.assignSequence(odim.scaling);
//scale = odim.scale;
//offset = odim.offset;
nodata = odim.nodata;
Expand Down
148 changes: 148 additions & 0 deletions src/drain/PseudoTuple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
MIT License
Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
Part of Rack development has been done in the BALTRAD projects part-financed
by the European Union (European Regional Development Fund and European
Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
*/


#ifndef DRAIN_UNITUPLE_WRAPPER
#define DRAIN_UNITUPLE_WRAPPER

#include <cstddef>
#include <iostream>
#include <sstream>
#include <typeinfo>
#include <stdexcept>
#include <string>
//#include <set>

#include <drain/StringBuilder.h>
#include <drain/Type.h> // Utils
// lower == cannot use Sprinter, as long as SprinterLayouit uses UniTuple...
// #include <drain/VariableT.h> lower
//#include <drain/Sprinter.h>
#include "TupleBase.h"

namespace drain {


/***
* \tparam C - base class
* \tparam S - storage class of members (int, double, char)
* \tparam N - number of the members included
*/
template <class C, typename T=typename C::value_t, size_t N=sizeof(C)/sizeof(T)>
class PseudoTuple : public C, public TupleBase<T,N> {

public:

typedef T* iterator;
typedef T const* const_iterator;

static const size_t baseTypeSize;

const size_t elementCount;


inline
PseudoTuple() : elementCount(N>0 ? N : baseTypeSize/TupleBase<T,N>::storageTypeSize) {
// std::cerr << N << '*' << TupleBase<T,N>::storageTypeSize << " ... " << baseTypeSize << '\n';
if (N*TupleBase<T,N>::storageTypeSize > baseTypeSize){
throw std::runtime_error(StringBuilder<>(__FUNCTION__, ": conflicting geometry ", N, 'x',
TupleBase<T,N>::storageTypeSize," in addressing base class ", TypeName<C>::str(), " size=", baseTypeSize));
}
};

virtual inline
const_iterator begin() const {
return static_cast<const_iterator>((void *)(const C *)this); //
}

virtual inline
const_iterator end() const {
return static_cast<const_iterator>((void *)(const C *)this) + N; //
}

virtual inline
iterator begin(){
return static_cast<iterator>((void *)(const C *)this);
}

virtual inline
iterator end(){
return static_cast<iterator>((void *)(const C *)this) + N;
}


protected:

};

template <class C, typename T, size_t N>
const size_t PseudoTuple<C,T,N>::baseTypeSize = sizeof(C);



template <class C, typename T, size_t N>
struct TypeName<PseudoTuple<C,T,N> > {

static const std::string & str(){
if (N == 0){
static const std::string name = drain::StringBuilder<>("PseudoTuple<", drain::TypeName<C>::str(),',' , drain::TypeName<T>::str(),">");
return name;
}
else {
static const std::string name = drain::StringBuilder<>("PseudoTuple<", drain::TypeName<C>::str(),',' , drain::TypeName<T>::str(),',' , N, ">");
return name;
}
}

};

/*
template <class T, size_t N>
std::ostream & operator<<(std::ostream & ostr, const UniTuple<T,N> & tuple){
return tuple.toStream(ostr);
}
*/




/*
// NOTE: cannot use Sprinter, as long as SprinterLayout uses UniTuple...
template <class T, size_t N>
std::ostream & Sprinter::toStream(std::ostream & ostr, const UniTuple<T,N> & tuple, const SprinterLayout & layout) {
return Sprinter::sequenceToStream(ostr, tuple, layout);
}
*/

} // drain


#endif
27 changes: 0 additions & 27 deletions src/drain/Reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,6 @@ Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
*/


/*
*
#include "FlexibleVariable.h"
#include "Variable.h"
namespace drain {
template <>
const char* TypeName<ReferenceBase<Castable> >::get(){
return "ReferenceBase<Castable>";
}
template <>
const char* drain::TypeName<drain::ReferenceBase<drain::Variable> >::get(){
return "ReferenceBase<Variable>";
};
}
/// Methods shared with Variable, Referencer, FlexibleVariable
#define SmartVariable Referencer
#include "SmartVariable.ipp"
#undef SmartVariable
*/

#include <drain/Reference.h>

namespace drain {
Expand Down
25 changes: 0 additions & 25 deletions src/drain/Reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,6 @@ See the documentation of drain::VariableT template specialized by drain::Variabl
*/
typedef VariableT<ReferenceT<Castable> > Reference;


//VariableT<R>
/*
template <>
template <>
void ReferenceT<Castable>::init(const VariableT<ReferenceT<Castable> > & src){
std::cerr << __FILE__ << ' ' << __LINE__ << ':' << __FUNCTION__ << " " << src << std::endl;
}
template <>
template <>
void ReferenceT<Castable>::init(const ReferenceT<Castable> & src){
std::cerr << __FILE__ << ' ' << __LINE__ << ':' << __FUNCTION__ << " " << src << std::endl;
}
*/

template <>
const std::string TypeName<Reference>::name;

Expand All @@ -102,15 +86,6 @@ std::ostream & Sprinter::toStream(std::ostream & ostr, const Reference & v, cons
return Sprinter::toStream(ostr, (const drain::Castable &) v, layout);
};

/*
template <class T, size_t N=2>
template <>
UniTuple<T,N> & UniTuple<T,N>::set(const Reference & t){
// assignSequence(t, true); // by default LENIENT, or how should it be?
return *this;
}
*/

} // namespace drain

#define VariableLike Reference
Expand Down
2 changes: 2 additions & 0 deletions src/drain/ReferenceT.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ReferenceT : public T {

public:

typedef const drain::ReferenceT<T> reference_t;

typedef std::pair<const char *,const drain::ReferenceT<T> > init_pair_t;

/// Tells if the internal pointer can point to an external variable.
Expand Down
3 changes: 2 additions & 1 deletion src/drain/Sprinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ struct TypeLayout : public TypeLayoutBase{
}

TypeLayout(const TypeLayout & layout){
this->assign(layout); // NOTE: copying element by element, not involving strings possibly containing null char (premature end-or-read).
this->assignSequence(layout);
//this->assign(layout); // NOTE: copying element by element, not involving strings possibly containing null char (premature end-or-read).
}

/// Set layout with a single string, for example: "{,}" .
Expand Down
Loading

0 comments on commit c711291

Please sign in to comment.