C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.1 KiB
91 lines
2.1 KiB
21 years ago
|
/** @file
|
||
|
|
||
|
$Id$
|
||
|
|
||
|
$Date$
|
||
|
$Author$
|
||
|
|
||
|
@copy © Marc Wäckerlin
|
||
|
@license LGPL, see file <a href="license.html">COPYING</a>
|
||
|
|
||
|
$Log$
|
||
20 years ago
|
Revision 1.4 2005/11/29 12:39:43 marc
|
||
|
make it compilable with gcc 4.0.2 and newer doxygen
|
||
|
|
||
20 years ago
|
Revision 1.3 2005/04/07 20:48:20 marc
|
||
|
docu: new doxygen, new grouping
|
||
|
|
||
21 years ago
|
Revision 1.2 2004/12/20 07:40:36 marc
|
||
|
documentation improved, new grouping
|
||
|
|
||
21 years ago
|
Revision 1.1 2004/10/07 09:31:30 marc
|
||
|
new feature
|
||
|
|
||
|
|
||
|
*/
|
||
|
#ifndef __MRW__VECTOR__HPP__
|
||
|
#define __MRW__VECTOR__HPP__
|
||
|
|
||
|
#include <vector>
|
||
14 years ago
|
#include <mrw/exception.hxx>
|
||
|
#include <mrw/string.hxx>
|
||
21 years ago
|
|
||
21 years ago
|
/** @addtogroup StdExtSTL
|
||
|
*/
|
||
|
//@{
|
||
|
/** @defgroup StdExtvector vector
|
||
|
*/
|
||
|
//@{
|
||
21 years ago
|
|
||
|
/** @brief push a value to a vector
|
||
|
|
||
|
@code
|
||
|
std::vector<int> test;
|
||
|
test<<1<<2<<3<<4<<5<<6<<7<<8;
|
||
|
@endcode
|
||
|
|
||
|
@param l a vector of values
|
||
|
@param o a value to be inserted into vector @c l
|
||
14 years ago
|
@pre \#include <mrw/vector.hxx>
|
||
21 years ago
|
*/
|
||
|
template <typename T, typename A>
|
||
|
std::vector<T, A>& operator<<(std::vector<T, A>& l, const T& o) throw(std::bad_exception) {
|
||
|
l.push_back(o);
|
||
|
return l;
|
||
|
}
|
||
|
|
||
|
/** @brief extract the first value of a vector
|
||
|
|
||
|
@code
|
||
|
std::vector<int> test;
|
||
|
test<<1<<2<<3<<4<<5<<6<<7<<8;
|
||
|
int i1(0), i2(0), i3(0), i4(0);
|
||
|
test>>i1>>i2>>i3>>i4;
|
||
|
// now: i1==1 i2==2 i3==3 i4==4 test=={5, 6, 7, 8}
|
||
|
@endcode
|
||
|
|
||
|
@param l a vector of values
|
||
|
@param o a value to be extracted from vector @c l
|
||
|
@throw mrw::length_error, if vector was empty on entry
|
||
|
@note when something is extracted from a vector, it is removed
|
||
|
from the vector, that means after every shift the vector is
|
||
|
shortened by the shifted element
|
||
14 years ago
|
@pre \#include <mrw/vector.hxx>
|
||
21 years ago
|
*/
|
||
|
template <typename T, typename A>
|
||
|
std::vector<T, A>& operator>>(std::vector<T, A>& l, T& o) throw(std::exception) {
|
||
|
typename std::vector<T, A>::iterator it(l.begin());
|
||
|
if (it==l.end())
|
||
|
throw mrw::length_error(std::string(__FILE__ ":")+__LINE__+
|
||
|
": std::vector<>& operator>>(std::vector<>&, T&),"
|
||
|
" vector is empty");
|
||
|
o = *it;
|
||
|
l.erase(it);
|
||
|
return l;
|
||
|
}
|
||
|
|
||
21 years ago
|
//@}
|
||
21 years ago
|
//@}
|
||
|
|
||
|
#endif
|