2004-10-07 09:31:30 +00:00
|
|
|
/** @file
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
$Date$
|
|
|
|
$Author$
|
|
|
|
|
|
|
|
@copy © Marc Wäckerlin
|
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a>
|
|
|
|
|
|
|
|
$Log$
|
2005-11-29 12:42:01 +00:00
|
|
|
Revision 1.4 2005/11/29 12:39:42 marc
|
|
|
|
make it compilable with gcc 4.0.2 and newer doxygen
|
|
|
|
|
2005-04-07 20:51:30 +00:00
|
|
|
Revision 1.3 2005/04/07 20:48:20 marc
|
|
|
|
docu: new doxygen, new grouping
|
|
|
|
|
2004-12-20 07:40:36 +00:00
|
|
|
Revision 1.2 2004/12/20 07:40:35 marc
|
|
|
|
documentation improved, new grouping
|
|
|
|
|
2004-10-07 09:31:30 +00:00
|
|
|
Revision 1.1 2004/10/07 09:31:30 marc
|
|
|
|
new feature
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifndef __MRW__LIST__HPP__
|
|
|
|
#define __MRW__LIST__HPP__
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <mrw/exception.hpp>
|
|
|
|
#include <mrw/string.hpp>
|
|
|
|
|
|
|
|
/** @addtogroup StdExt
|
|
|
|
*/
|
|
|
|
//@{
|
2004-12-20 07:40:36 +00:00
|
|
|
/** @defgroup StdExtSTL STL extensions
|
|
|
|
|
|
|
|
The STL extensions give you the possibility to fill up a container
|
|
|
|
by shifting in values, and to extract values by shifting them out.
|
|
|
|
@code
|
|
|
|
std::list<std::string> l;
|
|
|
|
l<<"hello"<<"world"<<"this"<<is"<<"cool";
|
|
|
|
for (std::string s; l.size();) {
|
|
|
|
l>>s;
|
|
|
|
std::cout<<"list contains: "<<s<<std::endl;
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
*/
|
2005-04-07 20:51:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/** @addtogroup StdExtSTL
|
|
|
|
*/
|
2004-12-20 07:40:36 +00:00
|
|
|
//@{
|
2005-04-07 20:51:30 +00:00
|
|
|
|
2004-12-20 07:40:36 +00:00
|
|
|
/** @defgroup StdExtliststl list
|
|
|
|
*/
|
|
|
|
//@{
|
2004-10-07 09:31:30 +00:00
|
|
|
|
|
|
|
/** @brief push a value to a list
|
|
|
|
|
|
|
|
@code
|
|
|
|
std::list<int> test;
|
|
|
|
test<<1<<2<<3<<4<<5<<6<<7<<8;
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@param l a list of values
|
|
|
|
@param o a value to be inserted into list @c l
|
2005-11-29 12:42:01 +00:00
|
|
|
@pre \#include <mrw/list.hpp>
|
2004-10-07 09:31:30 +00:00
|
|
|
*/
|
2005-11-29 12:42:01 +00:00
|
|
|
// template <typename T, typename A, typename FROM>
|
|
|
|
// std::list<T, A>& operator<<(std::list<T, A>& l, const FROM& o)
|
|
|
|
// throw(std::bad_exception) {
|
|
|
|
// l.push_back(T(o));
|
|
|
|
// return l;
|
|
|
|
// }
|
2004-10-07 09:31:30 +00:00
|
|
|
template <typename T, typename A>
|
2005-11-29 12:42:01 +00:00
|
|
|
std::list<T, A>& operator<<(std::list<T, A>& l, const T& o)
|
|
|
|
throw(std::bad_exception) {
|
2004-10-07 09:31:30 +00:00
|
|
|
l.push_back(o);
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2005-11-29 12:42:01 +00:00
|
|
|
/* @brief push a char* to a list of string
|
|
|
|
|
|
|
|
@code
|
|
|
|
std::list<std::string> test;
|
|
|
|
test<<"Hello"<<"World";
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
@param l a list of string values (that can be constructed from char*)
|
|
|
|
@param o a value to be inserted into list @c l
|
|
|
|
@pre \#include <mrw/list.hpp> */
|
|
|
|
template <typename T, typename A>
|
|
|
|
std::list<T, A>& operator<<(std::list<T, A>& l,
|
|
|
|
const char *const o)
|
|
|
|
throw(std::bad_exception) {
|
|
|
|
l.push_back(T(o));
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2004-10-07 09:31:30 +00:00
|
|
|
/** @brief extract the first value of a list
|
|
|
|
|
|
|
|
@code
|
|
|
|
std::list<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 list of values
|
|
|
|
@param o a value to be extracted from list @c l
|
|
|
|
@throw mrw::length_error, if list was empty on entry
|
|
|
|
@note when something is extracted from a list, it is removed
|
|
|
|
from the list, that means after every shift the list is
|
|
|
|
shortened by the shifted element
|
2005-11-29 12:42:01 +00:00
|
|
|
@pre \#include <mrw/list.hpp>
|
2004-10-07 09:31:30 +00:00
|
|
|
*/
|
|
|
|
template <typename T, typename A>
|
|
|
|
std::list<T, A>& operator>>(std::list<T, A>& l, T& o) throw(std::exception) {
|
|
|
|
typename std::list<T, A>::iterator it(l.begin());
|
|
|
|
if (it==l.end())
|
|
|
|
throw mrw::length_error(std::string(__FILE__ ":")+__LINE__+
|
|
|
|
": std::list<>& operator>>(std::list<>&, T&),"
|
|
|
|
" list is empty");
|
|
|
|
o = *it;
|
|
|
|
l.erase(it);
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2004-12-20 07:40:36 +00:00
|
|
|
//@}
|
2004-10-07 09:31:30 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
#endif
|