From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- libxsd/xsd/cxx/tree/containers.txx | 284 +++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 libxsd/xsd/cxx/tree/containers.txx (limited to 'libxsd/xsd/cxx/tree/containers.txx') diff --git a/libxsd/xsd/cxx/tree/containers.txx b/libxsd/xsd/cxx/tree/containers.txx new file mode 100644 index 0000000..5cd79ba --- /dev/null +++ b/libxsd/xsd/cxx/tree/containers.txx @@ -0,0 +1,284 @@ +// file : xsd/cxx/tree/containers.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // one + // + template + one:: + ~one () + { + delete x_; + } + + template + one:: + one (flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + } + + template + one:: + one (const T& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template + one:: + one (std::auto_ptr x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template + one:: + one (const one& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + if (x.present ()) + set (x.get ()); + } + + template + one& one:: + operator= (const one& x) + { + if (this == &x) + return *this; + + if (x.present ()) + set (x.get ()); + else + { + delete x_; + x_ = 0; + } + + return *this; + } + + template + void one:: + set (const T& x) + { + // We always do a fresh copy because T may not be x's + // dynamic type. + // + T* r (x._clone (flags_, container_)); + + delete x_; + x_ = r; + } + + template + void one:: + set (std::auto_ptr x) + { + T* r (0); + + if (x.get () != 0) + { + if (x->_container () != container_) + x->_container (container_); + + r = x.release (); + } + + delete x_; + x_ = r; + } + + // optional + // + template + optional:: + ~optional () + { + delete x_; + } + + template + optional:: + optional (flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + } + + template + optional:: + optional (const T& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template + optional:: + optional (std::auto_ptr x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + set (x); + } + + template + optional:: + optional (const optional& x, flags f, container* c) + : x_ (0), flags_ (f), container_ (c) + { + if (x) + set (*x); + } + + template + optional& optional:: + operator= (const T& x) + { + if (x_ == &x) + return *this; + + set (x); + + return *this; + } + + template + optional& optional:: + operator= (const optional& x) + { + if (this == &x) + return *this; + + if (x) + set (*x); + else + reset (); + + return *this; + } + + template + void optional:: + set (const T& x) + { + // We always do a fresh copy because T may not be x's + // dynamic type. + // + T* r (x._clone (flags_, container_)); + + delete x_; + x_ = r; + } + + template + void optional:: + set (std::auto_ptr x) + { + T* r (0); + + if (x.get () != 0) + { + if (x->_container () != container_) + x->_container (container_); + + r = x.release (); + } + + delete x_; + x_ = r; + } + + template + void optional:: + reset () + { + delete x_; + x_ = 0; + } + + template + void optional:: + true_ () + { + } + + + // optional + // + template + optional:: + optional (const T& y, flags, container*) + : present_ (false) + { + set (y); + } + + template + optional:: + optional (const optional& y, flags, container*) + : present_ (false) + { + if (y) + set (*y); + } + + template + optional& optional:: + operator= (const T& y) + { + if (&x_ == &y) + return *this; + + set (y); + + return *this; + } + + template + optional& optional:: + operator= (const optional& y) + { + if (this == &y) + return *this; + + if (y) + set (*y); + else + reset (); + + return *this; + } + + template + void optional:: + true_ () + { + } + + template + std::basic_ostream& + operator<< (std::basic_ostream& os, const optional& x) + { + if (x) + os << *x; + else + os << bits::not_present (); + + return os; + } + } + } +} -- cgit v1.1