amorph.h

Go to the documentation of this file.
00001 #ifndef AMORPH_CLASS
00002 #define AMORPH_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : amorph                                                            *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1989-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include <basis/array.h>
00019 
00021 
00050 template <class contents>
00051 class amorph : private array<contents *>
00052 {
00053 public:
00054   amorph(int elements = 0);
00056 
00057   ~amorph();
00058 
00059   inline int elements() const { return this->length(); }
00061 
00062   inline int valid_fields() const { return _fields_used; }
00064 
00066   void adjust(int new_max);
00068 
00072   void reset(int new_maximum = 0);
00074 
00075   outcome put(int field, const contents *data);
00077 
00083   outcome append(const contents *data);
00085 
00088   inline outcome operator += (const contents *data) { return append(data); }
00090 
00092 
00094   const contents *get(int field) const;
00096 
00098   contents *borrow(int field);
00099 
00101   inline const contents *operator [] (int field) const { return get(field); }
00103   inline contents *operator [] (int field) { return borrow(field); }
00104 
00105   contents *acquire(int field);
00107 
00114   outcome clear(int field);
00116 
00120   void clear_all();
00122 
00123   outcome zap(int start, int end);
00125 
00133   outcome insert(int position, int lines_to_add);
00135 
00139   int find_empty(outcome &outcome) const;
00141 
00143   const contents *next_valid(int &field) const;
00145 
00149   int find(const contents *to_locate, outcome &outcome);
00151 
00156   void swap_contents(amorph<contents> &other);
00158 
00161 private:
00162   int _fields_used;  
00163 
00164   void check_fields(const char *where) const;
00166 
00168   void set_nil(int start, int end);
00169     // Puts NIL in the indices between start and end.
00173   // not to be used: amorphs should not be copied because it is intended that
00174   // they support storing heavyweight objects that either have no copy
00175   // constructors or have high-cost copy constructors.
00176   inline amorph(const amorph &to_copy) {}  
00177   inline amorph &operator = (const amorph &to_copy) { return *this; }
00179 };
00180 
00182 
00183 // these extensions are phrased as macros to avoid including the headers
00184 // necessary for compiling them.  to use them, just put the macro name in
00185 // the file where the template is needed.
00186 
00188 
00190 
00191 template <class contents>
00192 void amorph_assign(amorph<contents> &to_assign,
00193     const amorph<contents> &to_copy);
00194 
00196 
00198 
00202 template <class contents>
00203 void amorph_pack(byte_array &packed_form, const amorph<contents> &to_pack);
00204 
00206 template <class contents>
00207 bool amorph_unpack(byte_array &packed_form, amorph<contents> &to_unpack);
00208 
00209 #endif
00210 

Generated on Fri Nov 28 04:29:11 2008 for HOOPLE Libraries by  doxygen 1.5.1