accumulation.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_ACCUMULATION_HXX
00003 #define OPENGM_ACCUMULATION_HXX
00004 
00005 #include "opengm/datastructures/fast_sequence.hxx"
00006 
00008 
00009 namespace opengm {
00010    
00011 template<class Value, class State, class Accumulator>
00012 class Accumulation {
00013 public:
00015    typedef Value ValueType;
00017    typedef State LabelType;
00018    Accumulation();
00019    ValueType value() const;
00020    size_t size() const;
00021    Value neutral() const;
00022    void state(FastSequence<size_t>&) const;
00023    template<class OUT_CONTAINER>
00024    void state(OUT_CONTAINER &) const;
00025    LabelType state(size_t) const;
00026    void clear();
00027    void operator()(const ValueType&, const opengm::FastSequence<size_t>&);
00028    template<class CONTAINER>
00029    void operator()(const ValueType&, const CONTAINER&);
00030    void operator()(const ValueType&);
00031 private:
00032    ValueType value_;
00033    opengm::FastSequence<size_t> state_;
00034 };
00035    
00036 template<class Value, class State, class Accumulator>
00037 inline
00038 Accumulation<Value, State, Accumulator>::Accumulation()
00039 :  value_(Accumulator::template neutral<ValueType>()),
00040    state_(opengm::FastSequence<size_t>())
00041 {}
00042    
00043 template<class Value, class State, class Accumulator>
00044 inline typename Accumulation<Value, State, Accumulator>::ValueType
00045 Accumulation<Value, State, Accumulator>::value() const
00046 {
00047    return(value_);
00048 }
00049    
00050 template<class Value, class State, class Accumulator>
00051 inline size_t
00052 Accumulation<Value, State, Accumulator>::size() const
00053 {
00054    return state_.size();
00055 }
00056    
00057 template<class Value, class State, class Accumulator>
00058 inline typename Accumulation<Value, State, Accumulator>::ValueType
00059 Accumulation<Value, State, Accumulator>::neutral() const
00060 {
00061    return state_.size();
00062 }
00063    
00064 template<class Value, class State, class Accumulator>
00065 inline void
00066 Accumulation<Value, State, Accumulator>::state
00067 (
00068    opengm::FastSequence<size_t>& out
00069 ) const
00070 {
00071    out = state_;
00072 }
00073    
00074 template<class Value, class State, class Accumulator>
00075 template<class OUT_CONTAINER>
00076 inline void
00077 Accumulation<Value, State, Accumulator>::state
00078 (
00079    OUT_CONTAINER& out
00080 ) const
00081 {
00082    out.resize(state_.size());
00083    for(size_t i=0;i<state_.size();++i) {
00084       out[i]=state_[i];
00085    }
00086 }
00087    
00088 template<class Value, class State, class Accumulator>
00089 inline typename Accumulation<Value, State, Accumulator>::LabelType
00090 Accumulation<Value, State, Accumulator>::state
00091 (
00092    size_t index
00093 ) const
00094 {
00095    return state_(index);
00096 }
00097    
00098 template<class Value, class State, class Accumulator>
00099 inline void
00100 Accumulation<Value, State, Accumulator>::clear()
00101 {
00102    Accumulator::neutral(value_);
00103    state_.resize(0);
00104 }
00105    
00106 template<class Value, class State, class Accumulator>
00107 inline void
00108 Accumulation<Value, State, Accumulator>::operator()
00109 (
00110    const ValueType& value,
00111    const opengm::FastSequence<size_t>& state
00112 ) {
00113    if(Accumulator::bop(value, value_)) {
00114       state_ = state;
00115       OPENGM_ASSERT(state_.size()==state.size());
00116    }
00117    Accumulator::op(value, value_, value_);
00118    //OPENGM_ASSERT(state_.size()==state.size());
00119 }
00120    
00121 template<class Value, class State, class Accumulator>
00122 template<class CONTAINER>
00123 inline void
00124 Accumulation<Value, State, Accumulator>::operator()
00125 (
00126    const ValueType& value,
00127    const CONTAINER & state
00128 )
00129 {
00130    if(Accumulator::bop(value, value_)) {
00131       state_.resize(state.size());
00132       for(size_t i=0;i<state.size();++i) {
00133          state_[i] = state[i];
00134       }
00135    }
00136    Accumulator::op(value, value_, value_);
00137    OPENGM_ASSERT(state_.size()==state.size());
00138 }
00139    
00140 template<class Value, class State, class Accumulator>
00141 inline void
00142 Accumulation<Value, State, Accumulator>::operator()
00143 (
00144    const ValueType& value
00145 )
00146 {
00147    Accumulator::op(value, value_, value_);
00148 }
00149 
00150 } // namespace opengm
00151 
00153 
00154 #endif // #ifndef OPENGM_ACCUMULATION_HXX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:01 2013 for OpenGM by  doxygen 1.6.3