Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

nodeutil.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     @file       util.h  -  description
00003                          -------------------
00004     @date       Fri Mar 1 2002
00005     copyright            : (C) 2002 by Eva Brucherseifer
00006     email                : eva@rt.e-technik.tu-darmstadt.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Library Public License as       *
00013  *   published by the Free Software Foundation; either version 2 of the    *
00014  *   License, or (at your option) any later version.                       *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef NODEUTIL_H
00019 #define NODEUTIL_H
00020 
00021 #include <iostream>
00022 
00023 namespace treecomp
00024 {
00025 
00026 /** Private copy constructor and copy assignment ensure classes derived from
00027   * class noncopyable cannot be copied.
00028   * Taken from Boost library
00029   * Contributed by Dave Abrahams
00030   *
00031   * If anyone needs a namespace here, please tell me at eva@rt.e-technik.tu-darmstadt.de
00032   */
00033 class NonCopyable
00034 {
00035 protected:
00036     NonCopyable(){}
00037     virtual ~NonCopyable(){}
00038 private:  // emphasize the following members are private
00039     NonCopyable( const NonCopyable& );
00040     const NonCopyable& operator=( const NonCopyable& );
00041 };
00042 
00043 
00044 /** this doesn't work as I'd like to :-(  */
00045 template <class _T>
00046 class VirtualCopyable
00047 {
00048 public:
00049     static _T* construct() { return new _T(); }
00050     static _T* clone(_T* me) { return new _T(me); }
00051     static _T* clone(_T& me) { return new _T(&me); }
00052     _T* construct() const { return new _T(); }
00053     _T* clone(_T* me) const { return new _T(me); }
00054     _T* clone(_T& me) const { return new _T(&me); }
00055 };
00056 
00057 
00058 /**
00059  * @interface StreamIn
00060  *
00061  * @brief stores an input stream with and offers an interface to set/get the input stream
00062  */
00063 class StreamIn
00064 {
00065 public:
00066     virtual void setInput(std::istream* in) { m_in = in; }
00067     virtual void setInput(std::istream& in) { m_in = &in; }
00068     std::istream* input() { return m_in; }
00069     std::istream& inputRef() { return *m_in; }
00070     
00071 protected:  
00072     explicit StreamIn(std::istream* in=&std::cin) : m_in(in) {}
00073     explicit StreamIn(std::istream& in) : m_in(&in) {}
00074     std::istream* m_in;
00075 };
00076 
00077 
00078 /**
00079  * @interface StreamOut
00080  *
00081  * @brief stores an output stream with and offers an interface to set/get the output stream
00082  */
00083 class StreamOut
00084 {
00085 public:
00086     virtual void setOutput(std::ostream* out=&std::cout) { m_out = out; }
00087     virtual void setOutput(std::ostream& out) { m_out = &out; }
00088     std::ostream* ouput() { return m_out; }
00089     std::ostream& ouputRef() { return *m_out; }
00090 
00091 protected:
00092     explicit StreamOut(std::ostream* out=&std::cout) : m_out(out) {}
00093     explicit StreamOut(std::ostream& out) : m_out(&out) {}
00094     std::ostream* m_out;
00095 };
00096 
00097 
00098 template <class _Node>
00099 class NodeTraits
00100 {
00101 protected:  
00102     // template functions for stripping const qualifier
00103     // taken from "Modern C++ Design" by A. Alexandrescu
00104     template <class U> struct UnConst
00105         { typedef U Result; };
00106     template <class U> struct UnConst<const U>
00107         { typedef U Result; };
00108 public:
00109     typedef typename UnConst<_Node>::Result _NonConstNode;
00110 };
00111 
00112 
00113 } // namespace treecomp
00114 
00115 #endif

Generated on Mon Jan 6 12:02:08 2003 for TreeComp by doxygen1.2.17