space_base.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_SPACE_BASE_HXX
00003 #define OPENGM_SPACE_BASE_HXX
00004 
00005 #include <vector>
00006 #include <limits>
00007 #include <typeinfo>
00008 
00009 #include "opengm/opengm.hxx"
00010 
00011 namespace opengm {
00012 
00014 template<class SPACE, class I = std::size_t, class L = std::size_t>
00015 class SpaceBase {
00016 public:   
00017    typedef I IndexType;
00018    typedef L LabelType;
00019 
00020    IndexType numberOfVariables() const; // must be implemented in Space
00021    LabelType numberOfLabels(const IndexType) const; // must be implemented in Space
00022    template<class Iterator> void assignDense(Iterator, Iterator);
00023    IndexType addVariable(const LabelType);
00024    bool isSimpleSpace() const;
00025 };
00026 
00027 template<class SPACE, class I, class L>
00028 inline bool
00029 SpaceBase<SPACE, I, L>::isSimpleSpace() const {
00030    const IndexType numVar = static_cast<SPACE const*>(this)->numberOfVariables();
00031    const IndexType l = static_cast<SPACE const*>(this)->numberOfLabels(0);
00032    for(size_t i=1;i<numVar;++i) {
00033       if(l!=static_cast<SPACE const *>(this)->numberOfLabels(i)) {
00034          return false;
00035       }
00036    }
00037    return true;
00038 }
00039 
00040 template<class SPACE, class I, class L>
00041 template<class Iterator>
00042 inline void
00043 SpaceBase<SPACE, I, L>::assignDense
00044 (
00045    Iterator begin,
00046    Iterator end
00047 ) {
00048    throw RuntimeError(std::string("assignDense(begin, end) is not implemented in ")+typeid(SPACE).name());
00049 }
00050 
00051 template<class SPACE, class I, class L>
00052 inline typename SpaceBase<SPACE, I, L>::IndexType
00053 SpaceBase<SPACE, I, L>::addVariable
00054 (
00055    const LabelType numberOfLabels
00056 ) {
00057    throw RuntimeError(std::string("assignDense(begin, end) is not implemented in ")+typeid(SPACE).name());
00058    return IndexType();
00059 }
00060 
00061 } // namespace opengm
00062 
00063 #endif // #ifndef OPENGM_SPACE_BASE_HXX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:06 2013 for OpenGM by  doxygen 1.6.3