ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adstring.hpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  *
7  * ADModelbuilder and associated libraries and documentations are
8  * provided under the general terms of the "New BSD" license
9  *
10  * License:
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are
14  * met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer.
18  *
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * 3. Neither the name of the University of California, Otter Research,
24  * nor the ADMB Foundation nor the names of its contributors may be used
25  * to endorse or promote products derived from this software without
26  * specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  */
41 #ifndef __ADSTRING_HPP__
42 #define __ADSTRING_HPP__
43 
44 #include "clist.h"
45 #include <string.h>
46 //#include <fvar.hpp>
47 #include <ostream>
48 
49 #include <stdio.h>
50 
52 {
53  size_t sz;
54 
55 protected:
56  adstring_shape(const size_t size)
57  {
58  sz = size;
59  }
60  size_t& size()
61  {
62  return sz;
63  }
64 
65  friend class adstring;
66 };
67 
68 class adstring_array;
69 
70 class adstring : public clist
71 {
73 #if (defined __ZTC__) || (defined __NDPX__)
74  char * s;
75 #else
76  unsigned char * s;
77 #endif
78  void allocate(const size_t sz);
79  void deallocate(void);
80  friend class adstring_array;
81 public :
82  adstring();
83  adstring(const adstring &v);
84  adstring(const char v);
85  adstring(const char* t);
86  adstring(const unsigned char v);
87  adstring(const unsigned char* t);
88  adstring(const size_t lb, const size_t ub);
89  adstring(const int size);
90  ~adstring();
91 
92  void allocate(const char* t);
93  void realloc(const char* t);
94  //adstring(const unsigned char v);
95 
96  size_t size() const;
97  size_t buff_size() const;
98  unsigned char &operator()(const size_t i);
99  unsigned char &operator[](const size_t i);
100  const unsigned char& operator()(const size_t i) const;
101  unsigned char& operator[](const size_t i) const;
102 
103  adstring& operator+=(const adstring &u);
104  inline adstring& operator+=(const char u)
105  { return(*this += adstring(u)); }
106 
107  bool operator==(const adstring& other) const;
108  bool operator==(const char* u) const
109  { return !strcmp(*this, u); }
110 
111  bool operator!=(const adstring &u) const
112  { return(!(*this==u)); }
113  bool operator!=(const char* u) const
114  { return strcmp(*this, u) != 0; }
115 
116  adstring operator()(const size_t i, const size_t j);
117  adstring operator()(const size_t i, const size_t j) const;
118 
119 /*
120  int operator==(const char* u) const;
121  bool operator==(const adstring& other) const;
122 */
123 
124  adstring& operator=(const adstring &t);
125  adstring& operator=(const char t);
126  // { return (*this = adstring(t)); }
127 
128  operator unsigned char * ();
129  operator char * ();
130  operator const unsigned char*() const;
131  operator const char*() const;
132 
133  // Pascal-like adstring functions
134 
135  // returns the starting position of substr
136  size_t pos(const adstring& substr) const;
137 
138  // converts a double into a adstring
139  friend adstring str(double x, int minwidth, int decplaces);
140  friend adstring str(const int x);
141  friend void val(const adstring& s, int& v, int& code);
142  friend int val(const adstring& s);
143 
144  void to_upper(void);
145  void to_lower(void);
148 
149  friend std::ostream& operator<<(std::ostream& c, const adstring& t);
150  friend std::istream& operator>>(std::istream& c, adstring& t);
151  friend adstring operator+(const adstring &u, const adstring &v);
152  friend adstring operator+(const adstring &u, const unsigned char v);
153  friend adstring operator+(const adstring &u, const char v);
154  friend adstring operator+(const adstring &u, const unsigned char *v);
155  friend adstring operator+(const adstring & u, const char *v);
156  friend adstring operator+(const unsigned char *v, const adstring& u);
157  friend adstring operator+(const char *v, const adstring &u);
158  friend adstring operator+(const unsigned char u, const adstring &v);
159 };
162 adstring str(double x, int minwidth=17, int decplaces=-1);
163 adstring str(const int x);
164 void val(const adstring& s, int& v, int& code);
165 int val(const adstring& s);
166 
167 class cifstream;
168 
169 class line_adstring : public adstring
170 {
171 public:
172  line_adstring(void) : adstring() {}
175  line_adstring& operator=(const char *s);
176  friend std::istream & operator >> (std::istream & c, line_adstring & t);
177 };
178 
179 adstring itoa(int n,int d);
180 
181 void str(const int, adstring&);
182 adstring chr(int c);
183 size_t length(const adstring& t);
184 size_t pos(const adstring& substr, const adstring& s);
185 
186 //adstring operator+(const char u, const char v)
187 // { return (adstring(u) + adstring(v) ); }
188 #if defined(__BORLANDC__)
189 # if (__BORLANDC__ <= 0x0520)
190  class ifstream;
191  class ofstream;
192  class cifstream;
193 # endif
194 #endif
195 
196 class vector_shape;
197 
198 class adstring_array : public clist
199 {
202 public:
203  int size() const;
204  int indexmin(void) const;
205  int indexmax(void) const;
206  adstring_array(const adstring_array& sa);
207  ~adstring_array();
208  adstring_array(int min,int max);
209  void allocate(int min,int max);
210  void allocate() {}
211  adstring_array(void);
212  const adstring& operator[](int i) const;
213  const adstring& operator()(int i) const;
214  adstring& operator [] (int i);
215  adstring& operator () (int i);
218  friend std::ifstream& operator >> (std::ifstream& ifs,adstring_array& sa);
219  friend std::ostream& operator<<(const std::ostream& ifs,
220  const adstring_array& sa);
222 
223  void to_upper(void);
224  void to_lower(void);
228 }; // end class adstring_array
231 
232 std::ostream& operator<<(const std::ostream& ifs, const adstring_array& sa);
233 
234 int atoi(adstring& s);
235 #endif //#ifndef __STRING_HPP__
friend void val(const adstring &s, int &v, int &code)
Definition: val.cpp:11
size_t size() const
Definition: string.cpp:58
adstring ** ptr
Definition: adstring.hpp:201
adstring_shape(const size_t size)
Definition: adstring.hpp:56
bool operator==(const char *u) const
Definition: adstring.hpp:108
adstring_shape * shape
Definition: adstring.hpp:72
int indexmin(void) const
Definition: string5.cpp:68
adstring_array & operator=(const adstring_array &)
Assigment operator for adstring_array.
void to_upper(void)
Definition: strcase.cpp:21
void allocate(const size_t sz)
Definition: string.cpp:12
Description not yet available.
Definition: fvar.hpp:509
size_t pos(const adstring &substr) const
Definition: string3.cpp:40
adstring_array & operator+=(const adstring &s)
Definition: string5a.cpp:11
void to_lower(void)
Definition: strcase2.cpp:10
#define x
adstring & operator+=(const adstring &u)
Return true if adstring is equal to other, otherwise false.
Definition: string1.cpp:180
bool operator==(const adstring &other) const
Return true if adstring is equal to other, otherwise false.
Definition: string1.cpp:158
vector_shape * shape
Definition: adstring.hpp:200
void to_lower(void)
Definition: strcase.cpp:11
void realloc(const char *t)
Definition: string1.cpp:77
void val(const adstring &s, int &v, int &code)
Definition: val.cpp:11
friend std::istream & operator>>(std::istream &c, line_adstring &t)
unsigned char & operator()(const size_t i)
Returns reference to element at specified index i.
Definition: string1.cpp:110
~adstring_array()
Destructor.
Definition: string5.cpp:38
adstring itoa(int n, int d)
Definition: string2.cpp:89
int atoi(adstring &s)
Returns a integer converted from input s.
Definition: atoi.cpp:20
void allocate()
Definition: adstring.hpp:210
line_adstring & operator=(const adstring &s)
Definition: string2a.cpp:10
friend std::ostream & operator<<(std::ostream &c, const adstring &t)
const adstring & operator[](int i) const
Returns a reference to the element at specified index i.
Definition: string5.cpp:148
#define min(a, b)
Definition: cbivnorm.cpp:188
const adstring & operator()(int i) const
Returns a reference to the element at specified index i.
Definition: string5.cpp:167
bool operator!=(const adstring &u) const
Definition: adstring.hpp:111
adstring_array & append_distinct(const adstring &s)
Definition: string5a.cpp:16
adstring str(double x, int minwidth=17, int decplaces=-1)
Convert x to adstring with minimum width and total number of decimal places.
Definition: str.cpp:25
adstring()
Default constructor.
Definition: string3.cpp:33
friend adstring str(double x, int minwidth, int decplaces)
Convert x to adstring with minimum width and total number of decimal places.
Definition: str.cpp:25
adstring to_upper(adstring &s)
Definition: strcase.cpp:38
adstring_array(void)
Default constructor.
Definition: string5.cpp:18
~adstring()
Destructor.
Definition: string1.cpp:98
unsigned char & operator[](const size_t i)
Returns reference to element at specified index i.
Definition: string1.cpp:212
int size() const
Definition: string5.cpp:65
friend adstring operator+(const adstring &u, const adstring &v)
Definition: string2.cpp:73
Definition: clist.h:43
ostream & operator<<(const ostream &_s, preshowpoint p)
Description not yet available.
Definition: admanip.cpp:48
adstring to_lower(adstring &s)
Definition: strcase.cpp:31
friend std::istream & operator>>(std::istream &c, adstring &t)
size_t pos(const adstring &substr, const adstring &s)
Definition: string3.cpp:56
unsigned char * s
Definition: adstring.hpp:76
int indexmax(void) const
Definition: string5.cpp:71
size_t buff_size() const
Definition: string.cpp:63
size_t & size()
Definition: adstring.hpp:60
adstring & operator=(const adstring &t)
Definition: string1.cpp:48
friend std::ostream & operator<<(const std::ostream &ifs, const adstring_array &sa)
#define max(a, b)
Definition: cbivnorm.cpp:189
void to_upper(void)
Definition: strcase2.cpp:21
friend std::ifstream & operator>>(std::ifstream &ifs, adstring_array &sa)
size_t length(const adstring &t)
Returns the size of adstr.
Definition: string1.cpp:228
void deallocate(void)
Definition: string.cpp:23
adstring chr(int c)
Definition: str.cpp:124
adstring & operator+=(const char u)
Definition: adstring.hpp:104
line_adstring(const adstring &s)
Definition: adstring.hpp:173
line_adstring(void)
Definition: adstring.hpp:172
bool operator!=(const char *u) const
Definition: adstring.hpp:113