added new shared pointer with simpler interface; refs #7
This commit is contained in:
		@@ -15,7 +15,7 @@ nobase_include_HEADERS = mrw/arg.hxx mrw/auto.hxx mrw/configfile.hxx	\
 | 
			
		||||
                         mrw/stdext.hxx mrw/string.hxx			\
 | 
			
		||||
                         mrw/tokenizer.hxx mrw/unistd.hxx		\
 | 
			
		||||
                         mrw/vector.hxx mrw/args.hxx mrw/iomanip.hxx	\
 | 
			
		||||
                         mrw/checkcxx11.hxx
 | 
			
		||||
                         mrw/checkcxx11.hxx mrw/shared.hxx
 | 
			
		||||
 | 
			
		||||
if HAVE_STACKTRACE
 | 
			
		||||
  AM_CPPFLAGS += -DHAVE_STACKTRACE
 | 
			
		||||
 
 | 
			
		||||
@@ -50,12 +50,32 @@
 | 
			
		||||
    @pre \#include <mrw/deque.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, typename A>
 | 
			
		||||
    std::deque<T, A> operator<<(std::deque<T, A> l, const T& o)
 | 
			
		||||
    std::deque<T, A>& operator<<(std::deque<T, A>& 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<int>()<<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 <mrw/deque.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, typename A>
 | 
			
		||||
    std::deque<T, A> operator<<(const std::deque<T, A>& l, const T& o)
 | 
			
		||||
    throw(std::bad_exception) {
 | 
			
		||||
  std::deque<T, A> copy(l);
 | 
			
		||||
  copy.push_back(o);
 | 
			
		||||
  return copy;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** @brief extract the first value of a deque
 | 
			
		||||
 | 
			
		||||
    @code
 | 
			
		||||
 
 | 
			
		||||
@@ -65,15 +65,35 @@
 | 
			
		||||
 | 
			
		||||
    @param l a list of values
 | 
			
		||||
    @param o a value to be inserted into list @c l
 | 
			
		||||
    @pre \#include <mrw/list.hxx>
 | 
			
		||||
    @pre #include <mrw/list.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, typename A>
 | 
			
		||||
  std::list<T, A> operator<<(std::list<T, A> l, const T& o)
 | 
			
		||||
  std::list<T, A>& operator<<(std::list<T, A>& 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<int>()<<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 <mrw/list.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, typename A>
 | 
			
		||||
  std::list<T, A> operator<<(const std::list<T, A>& l, const T& o)
 | 
			
		||||
    throw(std::bad_exception) {
 | 
			
		||||
  std::list<T, A> copy(l);
 | 
			
		||||
  copy.push_back(o);
 | 
			
		||||
  return ;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* @brief push a char* to a list of string
 | 
			
		||||
 | 
			
		||||
    @code
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@
 | 
			
		||||
    @pre \#include <mrw/map.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename K, typename T, class C, typename A>
 | 
			
		||||
    std::map<K, T, C, A> operator<<(std::map<K, T, C, A> l,
 | 
			
		||||
    std::map<K, T, C, A>& operator<<(std::map<K, T, C, A>& l,
 | 
			
		||||
                                     const std::pair<K, T>& o)
 | 
			
		||||
  throw(std::exception) {
 | 
			
		||||
  if (!l.insert(o).second)
 | 
			
		||||
@@ -63,6 +63,34 @@ template <typename K, typename T, class C, typename A>
 | 
			
		||||
  return l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** @brief insert a value in a map
 | 
			
		||||
 | 
			
		||||
    Makes a copy and returns the copy.
 | 
			
		||||
 | 
			
		||||
    @code
 | 
			
		||||
    std::map<int, std::string>()
 | 
			
		||||
        <<std::make_pair(1, std::string("one"))
 | 
			
		||||
        <<std::make_pair(2, std::string("two"));
 | 
			
		||||
    @endcode
 | 
			
		||||
 | 
			
		||||
    @throw mrw::invalid_argument, if element is already in map
 | 
			
		||||
    @param l a map of values
 | 
			
		||||
    @param o a value to be inserted into map @c l
 | 
			
		||||
    @pre \#include <mrw/map.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename K, typename T, class C, typename A>
 | 
			
		||||
    std::map<K, T, C, A> operator<<(const std::map<K, T, C, A>& l,
 | 
			
		||||
                                    const std::pair<K, T>& o)
 | 
			
		||||
  throw(std::exception) {
 | 
			
		||||
  std::map<K, T, C, A> 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
 | 
			
		||||
 
 | 
			
		||||
@@ -52,13 +52,37 @@
 | 
			
		||||
    @pre \#include <mrw/multimap.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename K, typename T, class C, typename A>
 | 
			
		||||
    std::multimap<K, T, C, A> operator<<(std::multimap<K, T, C, A> l,
 | 
			
		||||
                                         const std::pair<K, T>& o)
 | 
			
		||||
    std::multimap<K, T, C, A>& operator<<(std::multimap<K, T, C, A>& l,
 | 
			
		||||
                                          const std::pair<K, T>& 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<int, std::string>()
 | 
			
		||||
        <<std::make_pair(1, std::string("one"))
 | 
			
		||||
        <<std::make_pair(2, std::string("two"));
 | 
			
		||||
    @endcode
 | 
			
		||||
 | 
			
		||||
    @throw mrw::invalid_argument, if element is already in multimap
 | 
			
		||||
    @param l a multimap of values
 | 
			
		||||
    @param o a value to be inserted into multimap @c l
 | 
			
		||||
    @pre \#include <mrw/multimap.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename K, typename T, class C, typename A>
 | 
			
		||||
    std::multimap<K, T, C, A> operator<<(const std::multimap<K, T, C, A>& l,
 | 
			
		||||
                                         const std::pair<K, T>& o)
 | 
			
		||||
    throw(std::bad_exception) {
 | 
			
		||||
  std::multimap<K, T, C, A> copy(l);
 | 
			
		||||
  copy.insert(o);
 | 
			
		||||
  return copy;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** @brief extract the first value of a multimap
 | 
			
		||||
 | 
			
		||||
    @code
 | 
			
		||||
 
 | 
			
		||||
@@ -50,12 +50,34 @@
 | 
			
		||||
    @pre \#include <mrw/multiset.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, class C, typename A>
 | 
			
		||||
    std::multiset<T, C, A> operator<<(std::multiset<T, C, A> l, const T& o)
 | 
			
		||||
    std::multiset<T, C, A>& operator<<(std::multiset<T, C, A>& 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<int> 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 <mrw/multiset.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, class C, typename A>
 | 
			
		||||
    std::multiset<T, C, A> operator<<(const std::multiset<T, C, A>& l,
 | 
			
		||||
                                      const T& o)
 | 
			
		||||
    throw(std::bad_exception) {
 | 
			
		||||
  std::multiset<T, C, A> copy(l);
 | 
			
		||||
  copy.insert(o);
 | 
			
		||||
  return copy;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** @brief extract the first value of a multiset
 | 
			
		||||
 | 
			
		||||
    @code
 | 
			
		||||
 
 | 
			
		||||
@@ -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 <mrw/set.hxx>
 | 
			
		||||
    @pre #include <mrw/set.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, class C, typename A>
 | 
			
		||||
    std::set<T, C, A> operator<<(std::set<T, C, A> l, const T& o)
 | 
			
		||||
    std::set<T, C, A>& operator<<(std::set<T, C, A>& 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 <typename T, class C, typename A>
 | 
			
		||||
  return l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** @brief insert a value in a set
 | 
			
		||||
 | 
			
		||||
    Makes a copy and returns the copy.
 | 
			
		||||
 | 
			
		||||
    @code
 | 
			
		||||
    std::set<int>()<<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 <mrw/set.hxx>
 | 
			
		||||
*/
 | 
			
		||||
template <typename T, class C, typename A>
 | 
			
		||||
    std::set<T, C, A> operator<<(const std::set<T, C, A>& l, const T& o)
 | 
			
		||||
    throw(std::exception) {
 | 
			
		||||
  std::set<T, C, A> 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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										88
									
								
								src/mrw/shared.hxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								src/mrw/shared.hxx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
			
		||||
/*! @file
 | 
			
		||||
 | 
			
		||||
    @id $Id$
 | 
			
		||||
*/
 | 
			
		||||
//       1         2         3         4         5         6         7         8
 | 
			
		||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
 | 
			
		||||
 | 
			
		||||
#ifndef __SHARED_HXX__
 | 
			
		||||
#define __SHARED_HXX__
 | 
			
		||||
 | 
			
		||||
#include <mrw/checkcxx11.hxx>
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
namespace mrw {
 | 
			
		||||
 | 
			
		||||
  //! Shared pointer with better usage than std::shared_ptr
 | 
			
		||||
  /*! You can assign a pointer or even construct like an auto variable. */
 | 
			
		||||
  template <typename T> class Shared: public std::shared_ptr<T> {
 | 
			
		||||
    public:
 | 
			
		||||
      //! Default empty construction
 | 
			
		||||
      Shared() {}
 | 
			
		||||
      Shared(T* t): std::shared_ptr<T>(std::shared_ptr<T>(t)) {}
 | 
			
		||||
      //! Construction from std::shared_ptr
 | 
			
		||||
      Shared(std::shared_ptr<T> t): std::shared_ptr<T>(t) {}
 | 
			
		||||
      //! Constructor creates child with one argument
 | 
			
		||||
      template <typename T1>
 | 
			
		||||
          Shared(T1 t1):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with two arguments
 | 
			
		||||
      template <typename T1, typename T2>
 | 
			
		||||
          Shared(T1 t1, T2 t2):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with three arguments
 | 
			
		||||
      template <typename T1, typename T2, typename T3>
 | 
			
		||||
          Shared(T1 t1, T2 t2, T3 t3):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2, t3)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with four arguments
 | 
			
		||||
      template <typename T1, typename T2, typename T3, typename T4>
 | 
			
		||||
          Shared(T1 t1, T2 t2, T3 t3, T4 t4):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2, t3, t4)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with five arguments
 | 
			
		||||
      template <typename T1, typename T2, typename T3, typename T4, typename T5>
 | 
			
		||||
          Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2, t3, t4, t5)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with six arguments
 | 
			
		||||
      template <typename T1, typename T2, typename T3, typename T4, typename T5,
 | 
			
		||||
                typename T6>
 | 
			
		||||
          Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2, t3, t4, t5, t6)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with seven arguments
 | 
			
		||||
      template <typename T1, typename T2, typename T3, typename T4, typename T5,
 | 
			
		||||
                typename T6, typename T7>
 | 
			
		||||
          Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2, t3, t4, t5, t6, t7)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with eight arguments
 | 
			
		||||
      template <typename T1, typename T2, typename T3, typename T4, typename T5,
 | 
			
		||||
                typename T6, typename T7, typename T8>
 | 
			
		||||
          Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2, t3, t4, t5, t6, t7, t8)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Constructor creates child with nine arguments
 | 
			
		||||
      template <typename T1, typename T2, typename T3, typename T4, typename T5,
 | 
			
		||||
                typename T6, typename T7, typename T8, typename T9>
 | 
			
		||||
          Shared(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9):
 | 
			
		||||
              std::shared_ptr<T>(new T(t1, t2, t3, t4, t5, t6, t7, t8, t9)) {
 | 
			
		||||
      }
 | 
			
		||||
      //! Assign from shared pointer
 | 
			
		||||
      Shared& operator=(std::shared_ptr<T> t) {
 | 
			
		||||
        std::shared_ptr<T>::operator=(t);
 | 
			
		||||
        return *this;
 | 
			
		||||
      }
 | 
			
		||||
      //! Assign from pointer
 | 
			
		||||
      Shared& operator=(T* t) {
 | 
			
		||||
        std::shared_ptr<T>::operator=(std::shared_ptr<T>(t));
 | 
			
		||||
        return *this;
 | 
			
		||||
      }
 | 
			
		||||
  };
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -9,6 +9,7 @@
 | 
			
		||||
    @license LGPL, see file <a href="license.html">COPYING</a>
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
#include <mrw/stacktrace.hxx>
 | 
			
		||||
#include <mrw/exec.hxx>
 | 
			
		||||
#include <mrw/string.hxx>
 | 
			
		||||
@@ -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<<BinFiles::value_type(s.substr(0, s.find(' ')), (void*)0);
 | 
			
		||||
    res<<BinFiles::value_type(s.substr(0, s.find(' ')), (void*)0);
 | 
			
		||||
  }
 | 
			
		||||
# elif defined(__linux__)
 | 
			
		||||
  {
 | 
			
		||||
@@ -346,16 +347,15 @@ mrw::StackTrace::BinFiles mrw::StackTrace::filename()
 | 
			
		||||
          res<<BinFiles::value_type(lib, addr);
 | 
			
		||||
      }
 | 
			
		||||
    } catch (...) {} // ignore non matching lines
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
# else
 | 
			
		||||
  {
 | 
			
		||||
#     warning "Don't know how to get executable file name in your system!"
 | 
			
		||||
#     warning "Impossible to get function names in stack trace!"
 | 
			
		||||
#     warning "Give the path to the executable to StackTrace::createSymtable!"
 | 
			
		||||
    return res; // empty
 | 
			
		||||
  }
 | 
			
		||||
# endif 
 | 
			
		||||
  return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//----------------------------------------------------------------------------
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user