ADMB Documentation  11.1.2274
 All Classes Files Functions Variables Typedefs Friends Defines
adstring.hpp
Go to the documentation of this file.
00001 /*
00002  * $Id: adstring.hpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "New BSD" license
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00041 #ifndef __ADSTRING_HPP__
00042 #define __ADSTRING_HPP__
00043 
00044 #include "clist.h"
00045 #include <string.h>
00046 //#include <fvar.hpp>
00047 #include <ostream>
00048 
00049 #include <stdio.h>
00050 
00051 class adstring_shape
00052 {
00053   unsigned int sz;
00054 protected :
00055   friend class adstring;
00056   adstring_shape(unsigned int n)
00057   {
00058     sz = n;
00059   }
00060   unsigned int & size()
00061   {
00062     return (sz);
00063   }
00064 };
00065 
00066 class adstring_array;
00067 
00068 class adstring : public clist
00069 {
00070   adstring_shape * shape;
00071 #if (defined __ZTC__) || (defined __NDPX__)
00072   char * s;
00073 #else
00074   unsigned char * s;
00075 #endif
00076   void allocate(int sz);
00077   void deallocate(void);
00078   friend class adstring_array;
00079 public :
00080   friend std::ostream & operator<<(std::ostream & c, const adstring & t);
00081   friend std::istream & operator >> (std::istream & c, adstring & t);
00082 
00083   adstring(const char *t);
00084   void allocate(const char *t);
00085   adstring(int lb, int ub);
00086   adstring(const adstring &v);
00087   void realloc(const char * t);
00088   //adstring(const unsigned char v);
00089   adstring(const char v);
00090   adstring(void);
00091   ~adstring();
00092   unsigned int size(void) const;
00093   unsigned int buff_size(void);
00094   unsigned char &operator()(const int i);
00095   unsigned char &operator[](const int i);
00096   const unsigned char& operator()(const int i) const;
00097   const unsigned char& operator[](const int i) const;
00098 
00099 #ifdef __INTEL_COMPILER
00100   friend adstring operator+(const adstring &u, const char* v)
00101   {
00102     adstring a(v);
00103     return u + a;
00104   }
00105 #endif
00106 
00107   friend adstring operator+(const adstring &u, const adstring &v);
00108 
00109   friend adstring operator+(const adstring &u, const unsigned char v);
00110 
00111   friend adstring operator+(const adstring &u, const signed char v);
00112 
00113   friend adstring operator+(const adstring &u, const unsigned char *v);
00114 
00115   friend adstring operator+(const adstring & u, const signed char *v);
00116 
00117   friend adstring operator+(const unsigned char *v, const adstring& u);
00118 
00119   friend adstring operator+(const char *v, const adstring &u);
00120 
00121   friend adstring operator+(const unsigned char u, const adstring &v);
00122 
00123   adstring& operator+=(const adstring &u);
00124   inline adstring& operator+=(const char u)
00125     { return(*this += adstring(u)); }
00126 
00127   int operator==(const adstring &u);
00128 
00129   inline int operator == (const char* u)
00130     { return *this == adstring(u); }
00131 
00132   inline int operator!=(const adstring &u)
00133     { return(!(*this==u)); }
00134 
00135   adstring operator()(int i, int j);
00136   int operator==(const char* u) const;
00137 
00138   int operator==(const adstring &u) const;
00139   adstring operator()(int i, int j) const;
00140 
00141   adstring& operator=(const adstring &t);
00142   adstring& operator=(const char t);
00143    // { return (*this = adstring(t)); }
00144 
00145   operator unsigned char * ();
00146   operator char * ();
00147   operator const unsigned char*() const;
00148   operator const char*() const;
00149 
00150   // Pascal-like adstring functions
00151 
00152   // returns the starting position of substr
00153   int pos(const adstring& substr) const;
00154 
00155   // converts a double into a adstring
00156   friend adstring str(double x, int minwidth, int decplaces);
00157   friend adstring str(const int x);
00158   friend void val(const adstring& s, int& v, int& code);
00159   friend int val(const adstring& s);
00160 
00161   void to_upper(void);
00162   void to_lower(void);
00163   adstring to_upper(adstring& s);
00164   adstring to_lower(adstring& s);
00165 };
00166 adstring to_lower(adstring& s);
00167 adstring to_upper(adstring& s);
00168 adstring str(double x, int minwidth=17, int decplaces=-1);
00169 adstring str(const int x);
00170 void val(const adstring& s, int& v, int& code);
00171 int val(const adstring& s);
00172 
00173 class cifstream;
00174 
00175 class line_adstring : public adstring
00176 {
00177 public:
00178   line_adstring(void) : adstring() {}
00179   line_adstring(const adstring& s) : adstring(s) {}
00180   line_adstring& operator=(const adstring& s);
00181   line_adstring& operator=(const char *s);
00182   friend std::istream & operator >> (std::istream & c, line_adstring & t);
00183 };
00184 
00185 adstring itoa(int n,int d);
00186 
00187 void str(const int, adstring&);
00188 adstring chr(int c);
00189 int length(const adstring& t);
00190 int pos(const adstring& substr, const adstring& s);
00191 
00192 //adstring operator+(const char u, const char v)
00193 //  { return (adstring(u) + adstring(v) ); }
00194 #if defined(__BORLANDC__)
00195 #  if (__BORLANDC__  <= 0x0520)
00196      class ifstream;
00197      class ofstream;
00198      class cifstream;
00199 #  endif
00200 #endif
00201 
00202 class vector_shape;
00203 
00204 class adstring_array : public clist
00205 {
00206   vector_shape * shape;
00207   adstring ** ptr;
00208 public:
00209   int size() const;
00210   int indexmin(void) const;
00211   int indexmax(void) const;
00212   adstring_array(const adstring_array& sa);
00213   ~adstring_array();
00214   adstring_array(int min,int max);
00215   void allocate(int min,int max);
00216   adstring_array(void);
00217   const adstring& operator[](int i) const;
00218   const adstring& operator()(int i) const;
00219   adstring& operator [] (int i);
00220   adstring& operator () (int i);
00221   adstring_array& operator += (const adstring& s);
00222   adstring_array& append_distinct(const adstring& s);
00223   friend std::ifstream& operator >> (std::ifstream& ifs,adstring_array& sa);
00224   friend std::ostream& operator<<(const std::ostream& ifs,
00225     const adstring_array& sa);
00226   friend cifstream& operator >> (cifstream& ifs,adstring_array& sa);
00227 
00228   void to_upper(void);
00229   void to_lower(void);
00230   adstring_array to_upper(adstring_array& s);
00231   adstring_array to_lower(adstring_array& s);
00232   adstring_array& operator=(const adstring_array&);
00233 };   // end class adstring_array
00234 adstring_array to_lower(adstring_array& s);
00235 adstring_array to_upper(adstring_array& s);
00236 
00237 std::ostream& operator<<(const std::ostream& ifs, const adstring_array& sa);
00238 
00239 int atoi(adstring& s);
00240 #endif //#ifndef __STRING_HPP__