PolyBoRi
CCheckedIdx.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00014 //*****************************************************************************
00015 
00016 #ifndef polybori_common_CCheckedIdx_h_
00017 #define polybori_common_CCheckedIdx_h_
00018 
00019 // include basic definitions
00020 #include <polybori/pbori_defs.h>
00021 
00022 BEGIN_NAMESPACE_PBORI
00023 
00029 class CCheckedIdx:
00030   public CTypes::auxtypes_type {
00031 
00033   typedef CCheckedIdx self;
00034 
00035 public:
00036   CCheckedIdx(idx_type idx): m_idx(idx) {
00037     if PBORI_UNLIKELY(idx < 0) handle_error();
00038   }
00039   CCheckedIdx(const self& rhs): m_idx(rhs.m_idx) { }
00040   ~CCheckedIdx() {}
00041 
00042   operator idx_type() const { return m_idx; }
00043 private:
00044   void handle_error() const;
00045   idx_type m_idx;
00046 };
00047 
00048 END_NAMESPACE_PBORI
00049 
00050 #endif