Polaris: Assign.h Source File

Assign.h

Go to the documentation of this file.
00001 ///
00002 ///
00003 #ifndef _ASSIGN_H
00004 #define _ASSIGN_H
00005 ///
00006 /// \class Assign 
00007 /// \brief template for assignments into a Collection
00008 /// \defgroup Polaris
00009 /// \ingroup Polaris
00010 ///  C++ VDL
00011 /// \see Assign.h
00012 ///
00013 /// \endcode
00014 /// \section DESCRIPTION DESCRIPTION
00015 /// A template for a 2-tuple which contains the state of a list and an element,
00016 /// where 'T' MUST be derived from class Listable
00017 ///
00018 /// This class is to be used temporarily as:
00019 ///
00020 /// \code
00021 /// for (Iterator<Expression> iter = expr_list; iter.valid(); ++iter)
00022 ///     expr_list.assign(iter.current()) = simplify( iter.pull() );
00023 /// \endcode
00024 ///
00025 #include <stream.h>
00026 #include "../Boolean.h"
00027 #include "../macros.h"
00028 #include "../p-assert.h"
00029 #include "Wrapper.h"
00030 #include "UntypedAssign.h"
00031 ///
00032 template <class T> class Assign : public UntypedAssign {
00033  public:
00034     INLINE  Assign(Listable *elem);
00035     ///< create an Assign object.
00036 
00037     INLINE  Assign(Wrapper *w);
00038     ///< create an Assign object.
00039 
00040     INLINE  Assign(const Assign<T> & a);
00041     ///< Copy constructor
00042 
00043     INLINE  Assign(const UntypedAssign & a);
00044     ///< Copy constructor
00045     
00046     INLINE  ~Assign();
00047     ///< Destroy the temporary assignment object.
00048 
00049     INLINE T & operator = (T *elem);
00050     ///< replace the element in the context list _elem with the new elem.
00051     ///< The existing list takes ownership of the element.
00052 };
00053 
00054 
00055 ///< implementation
00056 
00057 
00058 template <class T>
00059 INLINE 
00060 Assign<T>::Assign(Listable *elem)
00061 {
00062 #if 0
00063     _used = False;    ///< Not available in the current implementation.
00064 #endif
00065 
00066     ///< Set _elem to indicate that the user is not
00067     ///< not doing the garbage collection
00068 
00069     _elem.modify( *elem );
00070 
00071     _wrap = get_wrap(elem);
00072     if (_wrap)
00073         _wrap->ref_inc();
00074 }
00075 
00076 template <class T>
00077 INLINE 
00078 Assign<T>::Assign(Wrapper  *w)
00079 {
00080 #if 0
00081     _used = False;      ///< Not available in the current implementation.
00082 #endif
00083 
00084     _elem.clear();      ///< The user is doing the garbage collection
00085 
00086     _wrap = w;
00087     if (_wrap)
00088         _wrap->ref_inc();
00089 }
00090 
00091 template <class T>
00092 INLINE
00093 Assign<T>::Assign(const Assign<T> & a)
00094 {
00095 #if 0
00096     _used = a._used;        ///< Not available in the current implementation.
00097 #endif
00098     _elem = a._elem;
00099 
00100     _wrap = a._wrap;
00101     if (_wrap)
00102         _wrap->ref_inc();
00103 }    
00104 
00105 template <class T>
00106 INLINE
00107 Assign<T>::Assign(const UntypedAssign & a)
00108 {
00109 #if 0
00110     _used = a._used;        ///< Not available in the current implementation.
00111 #endif
00112 
00113     _elem = a._elem;
00114 
00115     _wrap = a._wrap;
00116     if (_wrap)
00117         _wrap->ref_inc();
00118 }    
00119 
00120 template <class T>
00121 INLINE 
00122 Assign<T>::~Assign()
00123 {
00124 #if 0
00125     p_assert( _used, "Assign<T>::~Assign: error not used in an assignment" );
00126 #endif
00127 }
00128 
00129 template <class T>
00130 INLINE T &
00131 Assign<T>::operator = (T *new_elem)
00132 {
00133     set_pulled( (Listable *) new_elem, 0 );
00134 
00135 #if 0
00136     _used = True;        ///< Not available in the current implementation.
00137 #endif
00138     
00139     ///< attach new_elem this also takes care of reference counts.
00140     ///< This garbage collects the original (_elem) if it exists.
00141 
00142     _wrap->object((Listable *) new_elem);
00143         
00144     return *new_elem;
00145 }
00146 
00147 #endif
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:40 2005