diff --git a/configure.in b/configure.in index cd3e78a..ebcb5e5 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,5 @@ # $Id$ +set +x m4_include(ax_cxx_compile_stdcxx_11.m4) AC_ALIAS([AC_DEFINE_DIR], [AX_DEFINE_DIR]) AC_DEFUN([AX_DEFINE_DIR], [ @@ -23,7 +24,7 @@ DOC_DIR=doc m4_define(x_packagename, mrw-c++) m4_define(x_major, 4) -m4_define(x_minor, 0) +m4_define(x_minor, 1) PACKAGENAME=x_packagename MAJOR=x_major MINOR=x_minor @@ -33,9 +34,12 @@ if svn info . 2>&1 > /dev/null; then LEAST=$(LANG= svn info $path | sed -n 's/Revision: //p') break; else - LEAST=[$(pwd | sed -n 's,^.*/'${PACKAGENAME}'-'${MAJOR}'\.'${MINOR}'\.\([0-9]*\).*$,\1,p')] + MAJOR=[$(pwd | sed -n 's,^.*/'${PACKAGENAME}'-\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$,\1,p')] + MINOR=[$(pwd | sed -n 's,^.*/'${PACKAGENAME}'-\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$,\2,p')] + LEAST=[$(pwd | sed -n 's,^.*/'${PACKAGENAME}'-\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*$,\3,p')] if test -z "${LEAST}"; then - LEAST="ERROR CANNOT DETERMINE REVISION NUMBER from $(pwd)" + AC_MSG_ERROR([CANNOT DETERMINE REVISION NUMBER from $(pwd) + Got: ${MAJOR}.${MINOR}.${LEAST}]) fi fi @@ -49,6 +53,7 @@ while test $MINOR -gt 255; do MAJOR=$((MAJOR+1)) done +AC_MSG_NOTICE([Version number of $PACKAGENAME is: ${MAJOR}.${MINOR}.${LEAST}]) AM_INIT_AUTOMAKE($PACKAGENAME, $MAJOR.$MINOR.$LEAST, [marc@waeckerlin.org]) # files to create diff --git a/doc/examples/makefile.am b/doc/examples/makefile.am index 39b6994..c260e1a 100644 --- a/doc/examples/makefile.am +++ b/doc/examples/makefile.am @@ -4,7 +4,7 @@ ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 exampledir = ${docdir}/examples -example_PROGRAMS = smartpointer arguments +example_PROGRAMS = smartpointer arguments shared if HAVE_STACKTRACE example_PROGRAMS += exceptionhandling endif @@ -24,4 +24,6 @@ smartpointer_LDADD = ${top_builddir}/src/.libs/libmrw.la arguments_SOURCES = arguments.cxx +shared_SOURCES = shared.cxx + MAINTAINERCLEANFILES = makefile.in \ No newline at end of file diff --git a/doc/examples/shared.cxx b/doc/examples/shared.cxx new file mode 100644 index 0000000..3859a00 --- /dev/null +++ b/doc/examples/shared.cxx @@ -0,0 +1,30 @@ +/*! @file + + @id $Id$ +*/ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +#include + +#include + +class Test { + public: + Test(int i): _int1(i), _int2(0) {} + Test(int i, int j): _int1(i), _int2(j) {} + int _int1; + int _int2; +}; + +int main(int, char**) { + mrw::Shared test1(15); + mrw::Shared test2(13, 14); + mrw::Shared test3(new Test(13)); + mrw::Shared test4(test2); + std::cout<<"test1="<_int1<<", "<_int2<_int2<_int2<_int2< */ template - std::deque operator<<(std::deque l, const T& o) + std::deque& operator<<(std::deque& l, const T& o) throw(std::bad_exception) { l.push_back(o); return l; } +/** @brief push a value to a constant deque + + Makes a copy and returns the copy. + + @code + std::deque()<<1<<2<<3<<4<<5<<6<<7<<8; + @endcode + + @param l a deque of values + @param o a value to be inserted into deque @c l + @pre \#include +*/ +template + std::deque operator<<(const std::deque& l, const T& o) + throw(std::bad_exception) { + std::deque copy(l); + copy.push_back(o); + return copy; +} + /** @brief extract the first value of a deque @code diff --git a/src/mrw/list.hxx b/src/mrw/list.hxx index c9d5f37..e738438 100644 --- a/src/mrw/list.hxx +++ b/src/mrw/list.hxx @@ -65,15 +65,35 @@ @param l a list of values @param o a value to be inserted into list @c l - @pre \#include + @pre #include */ template - std::list operator<<(std::list l, const T& o) + std::list& operator<<(std::list& l, const T& o) throw(std::bad_exception) { l.push_back(o); return l; } +/** @brief push a value to a constant list + + Makes a copy and returns the copy. + + @code + std::list()<<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 + @pre #include +*/ +template + std::list operator<<(const std::list& l, const T& o) + throw(std::bad_exception) { + std::list copy(l); + copy.push_back(o); + return ; +} + /* @brief push a char* to a list of string @code diff --git a/src/mrw/map.hxx b/src/mrw/map.hxx index 872e98a..2d8a2ea 100644 --- a/src/mrw/map.hxx +++ b/src/mrw/map.hxx @@ -52,7 +52,7 @@ @pre \#include */ template - std::map operator<<(std::map l, + std::map& operator<<(std::map& l, const std::pair& o) throw(std::exception) { if (!l.insert(o).second) @@ -63,6 +63,34 @@ template return l; } +/** @brief insert a value in a map + + Makes a copy and returns the copy. + + @code + std::map() + < +*/ +template + std::map operator<<(const std::map& l, + const std::pair& o) + throw(std::exception) { + std::map copy(l); + if (!copy.insert(o).second) + throw mrw::invalid_argument(std::string(__FILE__ ":")+__LINE__+ + ": std::map<>&" + " operator<<(std::map<>&, const T&)," + "map element already exists"); + return copy; +} + /** @brief extract the first value of a map @code diff --git a/src/mrw/multimap.hxx b/src/mrw/multimap.hxx index ca39c8a..4899122 100644 --- a/src/mrw/multimap.hxx +++ b/src/mrw/multimap.hxx @@ -52,13 +52,37 @@ @pre \#include */ template - std::multimap operator<<(std::multimap l, - const std::pair& o) + std::multimap& operator<<(std::multimap& l, + const std::pair& o) throw(std::bad_exception) { l.insert(o); return l; } +/** @brief insert a value in a multimap + + Makes a copy and returns the copy. + + @code + std::multimap() + < +*/ +template + std::multimap operator<<(const std::multimap& l, + const std::pair& o) + throw(std::bad_exception) { + std::multimap copy(l); + copy.insert(o); + return copy; +} + /** @brief extract the first value of a multimap @code diff --git a/src/mrw/multiset.hxx b/src/mrw/multiset.hxx index 347f5b7..53269ab 100644 --- a/src/mrw/multiset.hxx +++ b/src/mrw/multiset.hxx @@ -50,12 +50,34 @@ @pre \#include */ template - std::multiset operator<<(std::multiset l, const T& o) + std::multiset& operator<<(std::multiset& l, const T& o) throw(std::bad_exception) { l.insert(o); return l; } +/** @brief insert a value in a multiset + + Makes a copy and returns the copy. + + @code + std::multiset test; + test<<1<<2<<3<<4<<5<<6<<7<<8; + @endcode + + @param l a multiset of values + @param o a value to be inserted into multiset @c l + @pre \#include +*/ +template + std::multiset operator<<(const std::multiset& l, + const T& o) + throw(std::bad_exception) { + std::multiset copy(l); + copy.insert(o); + return copy; +} + /** @brief extract the first value of a multiset @code diff --git a/src/mrw/set.hxx b/src/mrw/set.hxx index 88ddfc8..c5296cb 100644 --- a/src/mrw/set.hxx +++ b/src/mrw/set.hxx @@ -48,10 +48,10 @@ @throw mrw::invalid_argument, if element is already in set @param l a set of values @param o a value to be inserted into set @c l - @pre \#include + @pre #include */ template - std::set operator<<(std::set l, const T& o) + std::set& operator<<(std::set& l, const T& o) throw(std::exception) { if (!l.insert(o).second) throw mrw::invalid_argument(std::string(__FILE__ ":")+__LINE__+ @@ -60,6 +60,30 @@ template return l; } +/** @brief insert a value in a set + + Makes a copy and returns the copy. + + @code + std::set()<<1<<2<<3<<4<<5<<6<<7<<8; + @endcode + + @throw mrw::invalid_argument, if element is already in set + @param l a set of values + @param o a value to be inserted into set @c l + @pre #include +*/ +template + std::set operator<<(const std::set& l, const T& o) + throw(std::exception) { + std::set copy(l); + if (!copy.insert(o).second) + throw mrw::invalid_argument(std::string(__FILE__ ":")+__LINE__+ + ": std::set<>::operator<<, " + "set element already exists"); + return copy; +} + /** @brief extract the first value of a set @code diff --git a/src/mrw/shared.hxx b/src/mrw/shared.hxx new file mode 100644 index 0000000..edf2c89 --- /dev/null +++ b/src/mrw/shared.hxx @@ -0,0 +1,88 @@ +/*! @file + + @id $Id$ +*/ +// 1 2 3 4 5 6 7 8 +// 45678901234567890123456789012345678901234567890123456789012345678901234567890 + +#ifndef __SHARED_HXX__ +#define __SHARED_HXX__ + +#include +#include + +namespace mrw { + + //! Shared pointer with better usage than std::shared_ptr + /*! You can assign a pointer or even construct like an auto variable. */ + template class Shared: public std::shared_ptr { + public: + //! Default empty construction + Shared() {} + Shared(T* t): std::shared_ptr(std::shared_ptr(t)) {} + //! Construction from std::shared_ptr + Shared(std::shared_ptr t): std::shared_ptr(t) {} + //! Constructor creates child with one argument + template + Shared(T1 t1): + std::shared_ptr(new T(t1)) { + } + //! Constructor creates child with two arguments + template + Shared(T1 t1, T2 t2): + std::shared_ptr(new T(t1, t2)) { + } + //! Constructor creates child with three arguments + template + Shared(T1 t1, T2 t2, T3 t3): + std::shared_ptr(new T(t1, t2, t3)) { + } + //! Constructor creates child with four arguments + template + Shared(T1 t1, T2 t2, T3 t3, T4 t4): + std::shared_ptr(new T(t1, t2, t3, t4)) { + } + //! Constructor creates child with five arguments + template + Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5): + std::shared_ptr(new T(t1, t2, t3, t4, t5)) { + } + //! Constructor creates child with six arguments + template + Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6): + std::shared_ptr(new T(t1, t2, t3, t4, t5, t6)) { + } + //! Constructor creates child with seven arguments + template + Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7): + std::shared_ptr(new T(t1, t2, t3, t4, t5, t6, t7)) { + } + //! Constructor creates child with eight arguments + template + Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8): + std::shared_ptr(new T(t1, t2, t3, t4, t5, t6, t7, t8)) { + } + //! Constructor creates child with nine arguments + template + Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9): + std::shared_ptr(new T(t1, t2, t3, t4, t5, t6, t7, t8, t9)) { + } + //! Assign from shared pointer + Shared& operator=(std::shared_ptr t) { + std::shared_ptr::operator=(t); + return *this; + } + //! Assign from pointer + Shared& operator=(T* t) { + std::shared_ptr::operator=(std::shared_ptr(t)); + return *this; + } + }; + +} + +#endif diff --git a/src/stacktrace.cxx b/src/stacktrace.cxx index 101c98b..cfbbf8f 100644 --- a/src/stacktrace.cxx +++ b/src/stacktrace.cxx @@ -9,6 +9,7 @@ @license LGPL, see file COPYING */ + #include #include #include @@ -323,7 +324,7 @@ mrw::StackTrace::BinFiles mrw::StackTrace::filename() prpsinfo_t status; if (fd==-1 || ioctl(fd, PIOCPSINFO, &status)==-1) return res; s = status.pr_psargs; - return res<