27 #ifndef KVECTOR_IMPL_HPP
28 #define KVECTOR_IMPL_HPP
33 #include KSSTREAM_HEADER
57 std::string startDelim = std::string(),
58 std::string endDelim = std::string(),
63 std::string ws(
" \t\n");
65 (
elemDelim_.find_first_not_of(ws) != std::string::npos );
67 (
startDelim_.find_first_not_of(ws) != std::string::npos );
69 (
endDelim_.find_first_not_of(ws) != std::string::npos );
88 template<
typename T, K_UINT_32 BEG,
bool DBG>
94 template<
typename T, K_UINT_32 BEG,
bool DBG>
96 : vimpl_(n), v_( (n != 0) ? &vimpl_[0] - BEG : 0 ), n_(n) {}
100 template<
typename T, K_UINT_32 BEG,
bool DBG>
102 : vimpl_(n, a), v_( (n != 0) ? &vimpl_[0] - BEG : 0 ), n_(n) {}
110 template<
typename T, K_UINT_32 BEG,
bool DBG>
112 : vimpl_(v, v + n), v_( (n != 0) ? &vimpl_[0] - BEG : 0 ), n_(n) {}
116 template<
typename T, K_UINT_32 BEG,
bool DBG>
118 : vimpl_(v.vimpl_), v_( (v.size() != 0) ? &vimpl_[0] - BEG : 0 ),
121 template<
typename T, K_UINT_32 BEG,
bool DBG>
128 template<
typename T, K_UINT_32 BEG,
bool DBG>
139 oss <<
"Trying to access element " << i <<
" not included in ["
151 template<
typename T, K_UINT_32 BEG,
bool DBG>
163 oss <<
"Trying to access element " << i <<
" not included in ["
173 template<
typename T, K_UINT_32 BEG,
bool DBG>
183 template<
typename T, K_UINT_32 BEG,
bool DBG>
191 v_ = (n != 0) ? &vimpl_[0] - BEG : 0;
197 template<
typename T, K_UINT_32 BEG,
bool DBG>
204 const T* end = ptr + n_;
215 template<
typename T, K_UINT_32 BEG,
bool DBG>
226 template<
typename T, K_UINT_32 BEG,
bool DBG>
237 template<
typename T, K_UINT_32 BEG,
bool DBG>
250 template<
typename T, K_UINT_32 BEG,
bool DBG>
265 for (i = 0; i < n_-1; ++i) {
270 for (i = 0; i < n_; ++i) {
286 template<
typename T, K_UINT_32 BEG,
bool DBG>
292 const T* ptr = &vimpl_[0];
295 std::ios::fmtflags f = os.setf(std::ios::scientific,
296 std::ios::floatfield);
297 os.setf(std::ios::showpoint);
301 for (i = 0; i < n_ - 1; ++i) {
316 template<
typename T, K_UINT_32 BEG,
bool DBG>
327 template<
typename T, K_UINT_32 BEG,
bool DBG>
void put(std::ostream &os) const
Writes a vector to a stream.
bool skipStartDelim_
Must we skip a word at start of vector ?
unsigned precision_
Number of significant digits to output.
void resize(K_UINT_32 n)
Resizes the vector. Resulting vector contents are undefined.
KVector & operator=(const T &a)
Assigns a copy of a to all elements of the vector.
Minimalist vector template class.
unsigned width_
Width of output field for nice alignment.
bool skipEndDelim_
Must we skip a word at end of vector ?
KVectorContextImpl(std::string elemDelim=" ", std::string startDelim=std::string(), std::string endDelim=std::string(), unsigned prec=4)
Constructor.
KVectorContextImpl * currentVectorContext
Refers to the currently selected vector printing context.
void swap(T &a, T &b)
Swaps objects a and b.
void get(std::istream &is)
Reads a vector from a stream.
Contains necessary informations to print a formatted KVector.
bool skipElemDelim_
Must we skip a word between elements ?
T * v_
Pointer to start of vimpl_ array.
unsigned long int K_UINT_32
Unsigned 32-bits integral type.
void swap(KVector &v)
Constant-time swap function between two vectors.
T & operator()(K_UINT_32 i)
Returns the i'th element.
std::string endDelim_
Ending string after last vector element.
K_UINT_32 n_
Number of elements in vimpl_.
std::ostream & operator<<(std::ostream &os, const KMatrix< T, BEG, DBG > &M)
Writes a matrix to a stream.
std::string elemDelim_
Delimiter string between vector elements.
Exception class for access to out-of-bound elements.
std::vector< T > vimpl_
Underlying vector implementation.
void assign(K_UINT_32 n, const T *v)
Copies an array of n instances of T.
K_UINT_32 size() const
Returns the vector size.
std::istream & operator>>(std::istream &is, KMatrix< T, BEG, DBG > &M)
Reads a matrix from a stream.
KVector()
Default constructor. Creates an empty vector.
std::string startDelim_
Starting string before first vector element.