Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Valuation.h

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 ////////////////////////////////////////////////////////////////////
00003 //
00004 // Filename : Valuation.h
00005 //
00006 // IntValuation & DoubleValuation
00007 //
00008 // This file is a part of the UPPAAL toolkit.
00009 // Copyright (c) 1995 - 2003, Uppsala University and Aalborg University.
00010 // All right reserved.
00011 //
00012 // $Id: Valuation.h,v 1.2 2005/04/25 16:38:27 behrmann Exp $
00013 //
00014 ///////////////////////////////////////////////////////////////////
00015 
00016 #ifndef INCLUDE_DBM_VALUATION_H
00017 #define INCLUDE_DBM_VALUATION_H
00018 
00019 #include "base/pointer.h"
00020 #include "debug/utils.h"
00021 
00022 namespace dbm
00023 {
00024     /** Valuation: like a fixed vector of scalars S with
00025      * some basic operations on it.
00026      * We don't use array_t because we don't want to
00027      * resize but we need basic memory alloc/dealloc.
00028      */
00029     template<class S>
00030     class Valuation : public base::pointer_t<S>
00031     {
00032     public:
00033 
00034         /** Constructor
00035          * @param size: size of the S valuation vector,
00036          * or dimension.
00037          */
00038         Valuation(size_t size)
00039             : base::pointer_t<S>(new S[size], size)
00040         { base::pointer_t<S>::reset(); }
00041 
00042         /** Copy constructor
00043          * @param original: vector to copy
00044          */
00045         Valuation(const Valuation<S>& original)
00046         {
00047             this(original.size());
00048             copyFrom(original);
00049         }
00050 
00051         ~Valuation() { delete [] base::pointer_t<S>::data; }
00052 
00053         /** Add value to all the elements of this vector
00054          * EXCEPT element 0 (reference clock).
00055          * @param value: element to add.
00056          */
00057         Valuation<S>& operator += (S value)
00058         {
00059             if (value) 
00060             { 
00061                 for(S *i = base::pointer_t<S>::begin()+1; i < base::pointer_t<S>::end(); ++i) 
00062                 {
00063                     *i += value;
00064                 }
00065             }
00066             return *this;
00067         }
00068 
00069         /** Subtract value to all the elements of this vector.
00070          * @param value: element to subtract.
00071          */
00072         Valuation<S>& operator -= (S value)
00073         {
00074             return *this += -value;
00075         }
00076     };
00077 
00078 
00079     /** IntValuation = Valuation<int32_t>
00080      */
00081     typedef Valuation<int32_t> IntValuation;
00082 
00083 
00084     /** DoubleValuation = Valuation<double>
00085      */
00086     typedef Valuation<double> DoubleValuation;
00087 
00088 
00089     /** Overload += for automatic cast.
00090      */
00091     static inline
00092     DoubleValuation& operator += (DoubleValuation& d, int32_t v)
00093     { return d += (double) v; }
00094 
00095 
00096     /** Overload << IntValuation
00097      */
00098     static inline
00099     std::ostream& operator << (std::ostream& os, const IntValuation& i)
00100     { return debug_cppPrintVector(os, i(), i.size()); }
00101 
00102 
00103     /** Overload << DoubleValuation
00104      */
00105     static inline
00106     std::ostream& operator << (std::ostream& os, const DoubleValuation& d)
00107     { return debug_cppPrintRealVector(os, d(), d.size()); }
00108 
00109 }
00110 
00111 #endif // INCLUDE_DBM_VALUATION_H

Generated on Fri Jun 30 00:02:45 2006 for Module dbm by  doxygen 1.4.2