|
|
@ -9,6 +9,10 @@ |
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a> |
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a> |
|
|
|
|
|
|
|
|
|
|
|
$Log$ |
|
|
|
$Log$ |
|
|
|
|
|
|
|
Revision 1.6 2005/02/18 15:47:23 marc |
|
|
|
|
|
|
|
missing #ifndef |
|
|
|
|
|
|
|
new functions ifelse |
|
|
|
|
|
|
|
|
|
|
|
Revision 1.5 2005/01/28 07:52:33 marc |
|
|
|
Revision 1.5 2005/01/28 07:52:33 marc |
|
|
|
typo in doc |
|
|
|
typo in doc |
|
|
|
|
|
|
|
|
|
|
@ -27,6 +31,9 @@ |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __MRW__STDEXT_HPP__ |
|
|
|
|
|
|
|
#define __MRW__STDEXT_HPP__ |
|
|
|
|
|
|
|
|
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
#include <algorithm> |
|
|
|
#include <algorithm> |
|
|
@ -37,8 +44,14 @@ namespace mrw { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
//@{
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
|
|
/** @defgroup stdextReadline Read Line
|
|
|
|
/** @defgroup stdextFunction Useful Global Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- @ref getline read exactly one line from a stream |
|
|
|
|
|
|
|
- @ref ifelse implements a dual <code>?:</code> operator, like: |
|
|
|
|
|
|
|
<code>a ? a : b</code>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@section stdextReadline Read Line |
|
|
|
|
|
|
|
|
|
|
|
The global functions mrw::getline read exactly one line from a |
|
|
|
The global functions mrw::getline read exactly one line from a |
|
|
|
stream, without the need of a buffer. It is therefore guaranteed |
|
|
|
stream, without the need of a buffer. It is therefore guaranteed |
|
|
|
that a whole line is read, regardless of the length of the |
|
|
|
that a whole line is read, regardless of the length of the |
|
|
@ -94,6 +107,36 @@ namespace mrw { |
|
|
|
return std::max(a, b); |
|
|
|
return std::max(a, b); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Dual <code>?:</code> operation:
|
|
|
|
|
|
|
|
<code>a ? a : b</code> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
If the first parameter is not @c 0, then it is returned, |
|
|
|
|
|
|
|
otherwise the second parameter is returned. It is equivalent to |
|
|
|
|
|
|
|
the construct: <code>a ? a : b</code>, but without |
|
|
|
|
|
|
|
the side effect of duplicated evaluation of parameter |
|
|
|
|
|
|
|
<code>a</code>. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Older gcc compiler implemented the non standard extension of |
|
|
|
|
|
|
|
<code>a?:b</code>, which was exactly the same. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@param a criteria that is checked and returned if not @c 0 |
|
|
|
|
|
|
|
@param b alternative value to be returned if @c a is @c 0 |
|
|
|
|
|
|
|
@return <code>a ? a : b</code> |
|
|
|
|
|
|
|
@pre #include <mrw/stdext.hpp> |
|
|
|
|
|
|
|
@pre @c T must be convertible to @c bool |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
template<typename T> const T& ifelse(const T& a, const T& b) { |
|
|
|
|
|
|
|
return a?a:b; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @brief Dual <code>?:</code> operation:
|
|
|
|
|
|
|
|
<code>a ? a : b</code> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@copydoc ifelse(const T& a, const T& b) */ |
|
|
|
|
|
|
|
template<typename T> const T* ifelse(const T* a, const T* b) { |
|
|
|
|
|
|
|
return a?a:b; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** @brief read one line from a stream
|
|
|
|
/** @brief read one line from a stream
|
|
|
|
|
|
|
|
|
|
|
|
Reads one line from a stream, up to delimiter @c d. |
|
|
|
Reads one line from a stream, up to delimiter @c d. |
|
|
@ -123,3 +166,5 @@ namespace mrw { |
|
|
|
//@}
|
|
|
|
//@}
|
|
|
|
//@}
|
|
|
|
//@}
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|