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

int_seq.H

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Thu Aug  1 11:08:10 EDT 2002 by kcschalk@shr.intel.com
00020 //      modified on Tue Nov 13 12:38:26 EST 2001 by ken@xorian.net
00021 //      modified on Mon Jun 16 11:07:39 PDT 1997 by heydon
00022 //      modified on Tue Aug  8 11:33:21 PDT 1995 by levin
00023 
00024 #ifndef _int_seq
00025 #define _int_seq
00026 
00027 #include <Basics.H>
00028 #include "int_seq_private.H"
00029 
00030 //  *********************************************************************
00031 //  *  Supporting class for SRPC for tranmitting sequences of integers  *
00032 //  *********************************************************************
00033 
00034 class int_seq {
00035   friend class SRPC;
00036   friend class SRPC_impl;
00037   friend class int_seq_impl;
00038 public:
00039 
00040   // Generic failure type, for exception handling.
00041 
00042   struct failure {
00043     Text msg;
00044     inline failure(const Text &msg) { this->msg = msg; };
00045     inline failure(const failure &f) { this->msg = f.msg; };
00046     inline failure& operator=(const failure &f) {
00047       this->msg = f.msg; return *this; };
00048   };
00049 
00050   // Construction
00051 
00052   int_seq(int len_hint = 0);                                     /* "auto" */
00053     // This constructor creates a (logically empty) int_seq in dynamically
00054     // allocated storage.  "len_hint" estimates the eventual length of the
00055     // sequence.
00056 
00057   int_seq(Basics::int32 *buffer, int bytes) throw(failure);      /* "manual" */
00058     // This constructor creates a (logically empty) int_seq in storage
00059     // provided by the client.  "buffer" specifies the starting
00060     // address of of the storage, "bytes" specifies its extent.  The
00061     // buffer is used for the sequence itself and a small amount of
00062     // overhead.  (It is typed int32* to emphasize the required
00063     // alignment, even though the "bytes" parameter specifies its
00064     // extent in bytes.)  For assistance in computing "bytes", see the
00065     // "min_size" function, below.
00066 
00067     // **Warning** Note the subtle difference in the parameter types
00068     // between this constructor and the next one.  Since their
00069     // semantics are very different, use care in constructing the
00070     // arguments!
00071 
00072   int_seq(const Basics::int32 *seq, int len) throw(failure);     /* "full" */
00073     // This constructor creates a fully filled-in int_seq from an
00074     // existing array of 32-bit integers.  The "seq" and "len"
00075     // parameters specify the address and length of an array of 32-bit
00076     // integers.  The array is copied into dynamically allocated
00077     // storage.  The resulting sequence cannot be subsequently
00078     // extended with "append" or "append-ptr"; attempts to do so cause
00079     // "failure" to be thrown.
00080 
00081     // **Warning** Note the subtle difference in the parameter types
00082     // between this constructor and the preceding one.  Since their
00083     // semantics are very different, use care in constructing the
00084     // arguments!
00085 
00086   ~int_seq();
00087     // Releases dynamic storage allocated by the constructors above.
00088 
00089   static int min_size(int len);
00090     // This function returns the number of bytes required to hold a
00091     // int_seq of "len" 32-bit integers.  (Not inline because of
00092     // compiler bug.)
00093 
00094   // Conversion to int32*
00095 
00096   inline operator Basics::int32*() const
00097   { return (p == NULL ? NULL : &p->base); }
00098     // Warning!  The result returned by this function is valid only as long
00099     // as the underlying storage exists.  In particular, if the int_seq is
00100     // destroyed, the pointer becomes invalid.  Moreover, an "append"
00101     // operation that expands storage may render invalid a result
00102     // previously returned by this function.  Use with care!
00103 
00104 
00105   // Sequence member access
00106 
00107   inline Basics::int32 ith(int i) const
00108   { return ((Basics::int32 *)&p->base)[i]; }
00109     // note: no bounds checking:  in particular, no check for p == NULL
00110 
00111   inline Basics::int32 operator[](int i) const { return ith(i); }
00112     // i.e., is[i] is equivalent to is.ith(i)
00113 
00114   inline int length() const { return (p == NULL ? 0 : p->h.len); }
00115 
00116   // Adding members to the sequence
00117 
00118   void append(Basics::int32 i) throw(failure);
00119     // "append" adds the new member 'i'  to the end of the sequence,
00120     // allocating additional storage if necessary.  This works only if the
00121     // int_seq was created with the "auto" constructor; otherwise, "failure"
00122     // is thrown.
00123 
00124   inline void operator+=(Basics::int32 i) throw(failure) { append(i); }
00125     // i.e.,  is += i  is equivalent to is.append(i)
00126 
00127   // Storage management
00128 
00129   void lengthen(int len_hint);
00130     // If the int_seq was created with the "auto" constructor, its storage
00131     // is reconfigured according to the new length hint.  A larger buffer
00132     // is allocated and the existing data is copied into it.  If len_hint
00133     // is smaller than the previously suppied value (either at construction
00134     // time or on a previous call of "lengthen"), it has no effect.
00135 
00136 private:
00137   int_seq_impl::rep *p;
00138 
00139   // An int_seq can be neither copied nor assigned.
00140 
00141   int_seq(const int_seq &);
00142   int_seq(int_seq &);
00143     // Copy constructor; should never be accessed.
00144 
00145   void operator=(int_seq &);
00146 
00147 };
00148 
00149 #endif  /* _int_seq */

Generated on Mon May 8 00:48:56 2006 for Vesta by  doxygen 1.4.2