X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fcontainers%2Fcopy_functors.hpp;fp=src%2Fstlplus%2Fcontainers%2Fcopy_functors.hpp;h=c82ee9f0c0f920ab05a280b2f53a3d34925e2566;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/containers/copy_functors.hpp b/src/stlplus/containers/copy_functors.hpp new file mode 100644 index 0000000..c82ee9f --- /dev/null +++ b/src/stlplus/containers/copy_functors.hpp @@ -0,0 +1,66 @@ +#ifndef STLPLUS_COPY_FUNCTORS +#define STLPLUS_COPY_FUNCTORS +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +// The function constructor classes below are used by the smart_ptr and the +// simple_ptr classes. They provide three (well ok, two) copying mechanisms. +// These classes have been separated from the smart_ptr header by DJDM, as +// the simple_ptr classes now also use them. + +//////////////////////////////////////////////////////////////////////////////// +#include "containers_fixes.hpp" +#include "exceptions.hpp" + +namespace stlplus +{ + + //////////////////////////////////////////////////////////////////////////////// + // copy functors implementing the three possible copy semantics + + // constructor_copy uses the copy constructor of the object - used for simple types + + template + class constructor_copy + { + public: + T* operator() (const T& from) throw() + { + return new T(from); + } + }; + + // clone_copy uses the clone method of the object - used for polymorphic types + + template + class clone_copy + { + public: + T* operator() (const T& from) throw() + { + return from.clone(); + } + }; + + // no_copy throws an exception - used for types that cannot be copied + + template + class no_copy + { + public: + T* operator() (const T& from) throw(illegal_copy) + { + throw illegal_copy("no_copy functor called"); + return 0; + } + }; + + //////////////////////////////////////////////////////////////////////////////// + +} // end namespace stlplus + +#endif