ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
string.cpp
Go to the documentation of this file.
1 
8 #include <fvar.hpp>
9 #include <string.h>
10 #include <stdlib.h>
11 
12 void adstring::allocate(const size_t sz)
13 {
14  shape = new adstring_shape(sz);
15  s = new unsigned char[sz+1];
16  if (!s) {
17  cerr << "Error allocating memory for adstring" << endl;
18  ad_exit(1);
19  }
20  s--;
21 }
22 
24 {
25  if (shape)
26  {
27  delete shape;
28  shape=0;
29  }
30  if (s)
31  {
32  s++;
33 
34  delete [] s;
35  s=0;
36  }
37 }
38 adstring::operator unsigned char*()
39 {
40  return (unsigned char*)s + 1;
41 }
42 
43 adstring::operator char*()
44 {
45  return (char*)(s + 1);
46 }
47 
48 adstring::operator const unsigned char*() const
49 {
50  return (const unsigned char*)s + 1;
51 }
52 
53 adstring::operator const char*() const
54 {
55  return (const char*)(s + 1);
56 }
57 
58 size_t adstring::size() const
59 {
60  return s ? strlen((char*)(s+1)) : 0;
61 }
62 
63 size_t adstring::buff_size() const
64 {
65  return shape->size();
66 }
67 
68 ostream& operator<<(ostream& c, const adstring& t)
69 {
70  for (unsigned int i = 1; i <= t.size(); i++)
71  {
72  #if (defined __ZTC__) || (defined __NDPX__)
73  c << (char)(t.s)[i];
74  #else
75  c << (t.s)[i];
76  #endif
77  }
78  return (c);
79 }
80 
82 {
83  *this = adstring(t);
84  return *this;
85 }
size_t size() const
Definition: string.cpp:58
adstring_shape * shape
Definition: adstring.hpp:72
void allocate(const size_t sz)
Definition: string.cpp:12
exitptr ad_exit
Definition: gradstrc.cpp:53
prnstream & endl(prnstream &)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
adstring()
Default constructor.
Definition: string3.cpp:33
ostream & operator<<(const ostream &_s, preshowpoint p)
Description not yet available.
Definition: admanip.cpp:48
unsigned char * s
Definition: adstring.hpp:76
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
void deallocate(void)
Definition: string.cpp:23