Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

ipv2.h

00001 //
00002 // ipv2.h
00003 //
00004 // Copyright (C) 1996 Limit Point Systems, Inc.
00005 //
00006 // Author: Curtis Janssen <cljanss@limitpt.com>
00007 // Maintainer: LPS
00008 //
00009 // This file is part of the SC Toolkit.
00010 //
00011 // The SC Toolkit is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Library General Public License as published by
00013 // the Free Software Foundation; either version 2, or (at your option)
00014 // any later version.
00015 //
00016 // The SC Toolkit is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU Library General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Library General Public License
00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00024 //
00025 // The U.S. Government is granted a limited license as per AL 91-7.
00026 //
00027 
00028 #ifndef _util_keyval_ipv2_ipv2_h
00029 #define _util_keyval_ipv2_ipv2_h
00030 #ifdef __GNUG__
00031 #pragma interface
00032 #endif
00033 
00034 #include <iostream>
00035 #include <util/misc/exenv.h>
00036 #include <util/keyval/ipv2_scan.h>
00037 
00038 #undef yyFlexLexer
00039 #define yyFlexLexer IPV2FlexLexer
00040 #include <FlexLexer.h>
00041 
00042 // For temporary data (only used while parsing)
00043 /* This integer list is used to keep track of the karray index. */
00044 struct intlist_struct {
00045   int i;
00046   struct intlist_struct *p;
00047   };
00048 typedef struct intlist_struct intlist_t;
00049 
00050 // For permanent data
00051 struct ip_keyword_tree_struct {
00052   char *keyword;
00053   char *classname;
00054   char *truename;
00055   struct ip_keyword_tree_struct *across; /* Circular list. */
00056   struct ip_keyword_tree_struct *up;    /* Terminated by NULL. */
00057   struct ip_keyword_tree_struct *down;  /* Terminated by NULL. */
00058   char *variable;  /* If this node points to another name, this
00059                     * is the name, otherwise NULL. */
00060   char *value;
00061   int seen;
00062   };
00063 
00064 struct ip_keyword_tree_list_struct {
00065   struct ip_keyword_tree_struct *kt;
00066   struct ip_keyword_tree_list_struct *p;
00067   };
00068 
00069 struct ip_cwk_stack_struct {
00070   struct ip_keyword_tree_list_struct *ktl;
00071   struct ip_cwk_stack_struct *p;
00072   };
00073 typedef struct ip_cwk_stack_struct ip_cwk_stack_t;
00074 
00075 typedef struct ip_keyword_tree_struct ip_keyword_tree_t;
00076 typedef struct ip_keyword_tree_list_struct ip_keyword_tree_list_t;
00077 
00078 class IPV2
00079 {
00080  public:
00081   enum Status {
00082       OK=0          ,  /* No problem. */
00083       KeyNotFound=1 ,  /* The keyword was not found. */
00084       OutOfBounds=2 ,  /* An array subscript was out of bounds. */
00085       Malloc=3      ,  /* Memory allocation failed. */
00086       NotAnArray=4  ,  /* Gave index for data which isn't an array */
00087       NotAScalar=5  ,  /* Didn't give index for data which is an array */
00088       Type=6        ,  /* The datum is not of the appropiate type. */
00089       HasNoValue=7  ,  /* The keyword has no value. */
00090       ValNotExpd=8     /* A value was not expected for the keyword. */
00091       };
00092   enum { KEYWORD_LENGTH=256 };
00093   
00094  private:
00095   char *filename_;
00096     
00097   // These are needed only when the input is being read in:
00098   ip_string_list_t* table_keywords;
00099   ip_string_list_t* current_table_keyword;
00100   ip_keyword_tree_t* table_sub_tree;
00101   int table_row_number;
00102   int table_array_depth;
00103   intlist_t *karray_indices;
00104   ip_keyword_tree_t *sub_tree;
00105   int init_karray;
00106 
00107   // this maintains a list of current working keyword lists (for cwk_push
00108   // and cwk_pop)
00109   ip_cwk_stack_t *cwkstack;
00110 
00111   // This keeps track of whether or not we've been initialized
00112   int ip_initialized;
00113 
00114   // This is used for error processing
00115   char lastkeyword[KEYWORD_LENGTH];
00116   
00117   // These are needed always:
00118   std::istream* ip_in;
00119   std::ostream* ip_out;
00120   ip_keyword_tree_t* ip_tree;
00121   ip_keyword_tree_list_t* ip_cwk;
00122   int ip_keyword;
00123 
00124   // private routines mainly used for parsing the input
00125   void ip_push_table_col(char*);
00126   void ip_next_table_entry();
00127   char* dup_string(const char*);
00128   ip_keyword_tree_t* ip_get_variable_kt(char*);
00129   char* ip_get_variable_value(char*);
00130   void ip_internal_values();
00131   void ip_push_keyword(char*);
00132   void ip_push_keyclass(char*,char*,ip_string_list_t*);
00133   void ip_pop_keyword();
00134   void ip_begin_table(ip_string_list_t*);
00135   void ip_done_table();
00136   ip_string_list_t* ip_add_string_list(ip_string_list_t*,char*);
00137   ip_string_list_t* ip_string_to_string_list(char*);
00138   void ip_assign_variable(char*);
00139   double ip_get_variable_double(char*);
00140   char* ip_double_to_string(double);
00141   void ip_assign_value(char*value);
00142   void ip_start_karray();
00143   void ip_init_karray();
00144   void ip_incr_karray();
00145   void ip_lastkeyword(const char*);
00146   void ip_lastkeywordtree(ip_keyword_tree_t*);
00147   void ip_lastkeyword_(ip_keyword_tree_t*);
00148   ip_keyword_tree_t* ip_alloc_keyword_tree();
00149   void ip_free_keyword_tree(ip_keyword_tree_t*);
00150   void ip_cwk_add_kt(ip_keyword_tree_t*);
00151   ip_keyword_tree_t* ip_cwk_descend_tree(const char*);
00152   ip_keyword_tree_t* ip_descend_tree(ip_keyword_tree_t*,const char*);
00153   char* ip_key_value(const char*);
00154   void free_keyword_tree_list(ip_keyword_tree_list_t*);
00155   ip_keyword_tree_list_t* splice_keyword_tree_list(ip_keyword_tree_t*,
00156                                                    ip_keyword_tree_list_t*);
00157   void ip_cwk_karray_add_v(int,int*);
00158   void ip_cwk_karray_add(int,...);
00159   ip_keyword_tree_t* ip_karray_descend_v(ip_keyword_tree_t*,int,int*);
00160   ip_keyword_tree_t* ip_karray_descend(ip_keyword_tree_t*,int,...);
00161   void print_tree_(std::ostream&,ip_keyword_tree_t*);
00162   int ip_special_characters(char*);
00163   char* ip_append_keystrings(char*,char*);
00164   void ip_pop_karray();
00165   void ip_initialize(std::istream&,std::ostream&);
00166   void ip_append(std::istream&,std::ostream&);
00167   char* get_truename(ip_keyword_tree_t*kt);
00168 
00169   void showpos();
00170 
00171   IPV2FlexLexer *lexer;
00172 
00173   int ylex() { return lexer->yylex(); }
00174   int yparse();
00175   void yerror(const char* s);
00176 
00177  public:
00178   IPV2();
00179   virtual ~IPV2();
00180   static int have_global();
00181   static void set_global(IPV2*);
00182   static IPV2* global();
00183   // calls either ip_append or ip_initialize based on ip_initialized
00184   void read(std::istream&,std::ostream&,const char *filename=0);
00185   void append_from_input(const char*,std::ostream&);
00186   void done();
00187   const char* error_message(IPV2::Status);
00188   void error(const char*);
00189   void warn(const char*);
00190   void cwk_root();
00191   void cwk_clear();
00192   void cwk_add(const char*);
00193   void cwk_push();
00194   void cwk_pop();
00195   IPV2::Status boolean(const char*,int*,int,...);
00196   IPV2::Status boolean_v(const char*,int*,int,int*);
00197   int exist(const char*,int,...);
00198   int exist_v(const char*,int,int*);
00199   IPV2::Status data(const char*,const char*,void*,int,...);
00200   IPV2::Status data_v(const char*,const char*,void*,int,int*);
00201     // the character string produced by classname must not be delete[]'ed
00202   IPV2::Status classname(const char*,const char**,int,...);
00203   IPV2::Status classname_v(const char*,const char**,int,int*);
00204     // the character string produced by truekeyword must not be delete[]'ed
00205     // if there is no alias for the keyword the string pointer is set to
00206     // null and if the keyword exists OK is returned
00207   IPV2::Status truekeyword(const char*,const char**,int,...);
00208   IPV2::Status truekeyword_v(const char*,const char**,int,int*);
00209   IPV2::Status string(const char*,char**,int,...);
00210   IPV2::Status string_v(const char*,char**,int,int*);
00211     // the character string produced by value must not be delete[]'ed
00212     // or free'ed.
00213   IPV2::Status value(const char*,const char**,int,...);
00214   IPV2::Status value_v(const char*,const char**,int,int*);
00215 
00216   IPV2::Status construct_key_v(const char*,char*,int,int*);
00217   IPV2::Status count(const char*,int*,int,...);
00218   IPV2::Status count_v(const char*,int*,int,int*);
00219 
00220   // some routines for debugging
00221   void print_keyword(std::ostream&f=ExEnv::out(),ip_keyword_tree_t*k=0);
00222   void print_tree(std::ostream&f=ExEnv::out(),ip_keyword_tree_t*k=0);
00223   void print_unseen(std::ostream&f=ExEnv::out(),ip_keyword_tree_t*k=0);
00224   int have_unseen(ip_keyword_tree_t*k=0);
00225 };
00226 
00227 #endif
00228 
00229 // Local Variables:
00230 // mode: c++
00231 // c-file-style: "CLJ"
00232 // End:

Generated at Thu Oct 4 18:08:44 2001 for MPQC 2.0.0 using the documentation package Doxygen 1.2.5.