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 Mon Aug 16 17:10:01 EDT 2004 by ken@xorian.net 00020 // modified on Wed Apr 1 18:30:14 PST 1998 by heydon 00021 00022 #ifndef _FV_2_H 00023 #define _FV_2_H 00024 00025 /* Like "FV", but the individual names are *sequences* of texts, rather 00026 than simple texts containing delimiters. These are only used by the client. 00027 00028 IMPORTANT: Use of this interface assumes you are linking your application 00029 program with a garbage collector! Also, none of these classes defines an 00030 assignment operator, so objects are copied field-wise by default. This 00031 means that use of the assignment operator will produce aliases for those 00032 fields that are pointer types. */ 00033 00034 #include <Basics.H> 00035 #include <Generics.H> 00036 #include <SRPC.H> 00037 00038 namespace FV2 00039 { 00040 // defined below 00041 class T; 00042 class List; 00043 class ListApp; 00044 } 00045 00046 std::ostream& operator << (std::ostream &os, const FV2::T &t) throw (); 00047 std::ostream& operator << (std::ostream &os, const FV2::List &names) throw (); 00048 00049 namespace FV2 00050 { 00051 class T: public AtomSeq { 00052 public: 00053 // default constructor 00054 T(int sizeHint = 7) : AtomSeq(sizeHint) { /*SKIP*/; } 00055 00056 // constructor (from a text) 00057 T(const Text &t, char delim = '/') throw () 00058 : AtomSeq(/*sizehint=*/ 7) { FromStr(t.cchars(), delim); } 00059 /* Return a new "T" whose elements are the "delim"-separated 00060 sub-strings of "t". */ 00061 00062 // convert to a text 00063 Text ToText(const char delim = '/') const throw (); 00064 /* Return a text representation of the values of this sequence 00065 concatenated together and separated by "delim". */ 00066 00067 // print 00068 void Print(std::ostream &os) const throw(); 00069 /* Write an ASCII representation of "t" to "os". */ 00070 00071 private: 00072 void FromStr(const char *str, const char delim) throw (); 00073 /* Append the "delim"-separated texts of the null-terminated string 00074 "str" to this "FV::T". */ 00075 00076 char* ToStr(char *buff, const int sz, char delim, char type = '\0') 00077 const throw (); 00078 /* Return a null-terminated string corresponding to the Text's of this 00079 sequence concatenated together and separated by "delim". If "type" 00080 is any character but the null character, that character and "/" are 00081 prepended onto the result. In that case, it is a checked run-time 00082 error if "sz" is not at least 2. 00083 00084 "buff" should be a non-NULL buffer of size at least "sz". If 00085 possible, the result will be written into "buff", and "buff" will 00086 be returned. Otherwise, a new string will be allocated on the heap 00087 that is large enough to hold the result. The return result is the 00088 character array containing the resulting string; it will either be 00089 "buff" or a block of memory allocated on the heap. */ 00090 00091 // send 00092 void Send(SRPC &srpc, char type = '\0') const throw (SRPC::failure); 00093 /* Note: There is no "Recv" method because the client receives 00094 names in response to the "FreeVariables" method in the form 00095 of a "CompactFV" object. */ 00096 00097 friend class List; 00098 }; 00099 00100 typedef T *TPtr; 00101 00102 class List { 00103 public: 00104 int len; 00105 FV2::TPtr *name; // array of pointers 00106 00107 // constructors 00108 List() throw () : len(0), name(NULL) { /*SKIP*/ } 00109 00110 // send 00111 void Send(SRPC &srpc, const char *types = NULL) const 00112 throw (SRPC::failure); 00113 /* Note: There is no "Recv" method because the client receives 00114 names in response to the "FreeVariables" method in the form 00115 of a "CompactFV" object. */ 00116 00117 // print 00118 void Print(std::ostream &os, int indent, const char *types = NULL) const 00119 throw (); 00120 private: 00121 // hide copy constructor 00122 List(const List&); 00123 }; 00124 00125 // list with append operation 00126 class ListApp: public List { 00127 public: 00128 // constructors 00129 ListApp() throw () : List(), maxLen(0) { /*SKIP*/ } 00130 00131 void Reset() throw () { len = 0; } 00132 /* Reset this list so as not to contain any names; this does not 00133 free the list's underlying storage. */ 00134 00135 int Append(FV2::T *s) throw (); 00136 /* Append the name "s" to the list, and return the index of "s" in 00137 the (zero-based) "name" array. */ 00138 private: 00139 int maxLen; // size of "name" 00140 ListApp(const ListApp&); // hide from clients 00141 }; 00142 } 00143 00144 #endif // _FV_2_H