00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _DEBUG_H_
00011 #define _DEBUG_H_
00012
00013
00014
00015
00016
00017
00018 #ifndef NDEBUG
00019
00020 # include <iostream>
00021 # include <stdio.h>
00022 # include <vector>
00023 # include <cassert>
00024
00025 # define dbg1(msg) fprintf(stderr, msg)
00026 # define dbg2(fmt,a1) fprintf(stderr, fmt, a1)
00027 # define dbg3(fmt,a1,a2) fprintf(stderr, fmt, a1, a2)
00028 # define dbg4(fmt,a1,a2,a3) fprintf(stderr, fmt, a1, a2, a3)
00029 # define dbg5(fmt,a1,a2,a3,a4) fprintf(stderr, fmt, a1, a2, a3, a4)
00030 # define dbg(data) { std::cerr << (data); std::cerr.flush(); }
00031
00032
00033
00034 template <class T>
00035 class safevector : public std::vector<T> {
00036 public:
00037 safevector() {}
00038 safevector(unsigned size):std::vector<T>(size) {}
00039 safevector(unsigned size, T const& value):std::vector<T>(size, value) {}
00040 safevector(std::vector<T> const& array): std::vector<T>(array) {}
00041 safevector(T const* begin, T const* end): std::vector<T>(begin, end) {}
00042 safevector(typename std::vector<T>::const_iterator begin,
00043 typename std::vector<T>::const_iterator end): std::vector<T>(begin, end) {}
00044
00045 inline typename std::vector<T>::const_reference operator[](unsigned idx)const {
00046 assert(idx < this->size());
00047 return std::vector<T>::operator[](idx);
00048 }
00049 inline typename std::vector<T>::reference operator[](unsigned idx) {
00050 assert(idx < this->size());
00051 return std::vector<T>::operator[](idx);
00052 }
00053
00054 inline void insert(typename std::vector<T>::iterator pos, T const& value) {
00055 assert(pos >= this->begin() && pos <= this->end());
00056 std::vector<T>::insert(pos, value);
00057 }
00058
00059 inline void insert(typename std::vector<T>::iterator pos,
00060 typename std::vector<T>::const_iterator from,
00061 typename std::vector<T>::const_iterator to) {
00062 assert(pos >= this->begin() && pos <= this->end());
00063 assert(from <= to);
00064 std::vector<T>::insert(pos, from, to);
00065 }
00066
00067 };
00068
00069 #else
00070
00071 # define dbg1(msg) {}
00072 # define dbg2(fmt,a1) {}
00073 # define dbg3(fmt,a1,a2) {}
00074 # define dbg4(fmt,a1,a2,a3) {}
00075 # define dbg5(fmt,a1,a2,a3,a4) {}
00076 # define dbg(data) {}
00077
00078 # define safevector std::vector
00079
00080 #endif//NDEBUG
00081 #endif//_DEBUG_H_