Revision 1542

trunk/src/sparse/string.cpp (revision 1542)
1
/*
2
 * $Id$
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California 
6
 */
7
#include <fvar.hpp>
8
#include <string.h>
9
#include <stdlib.h>
10
#include <safe_mem.h>
11

  
12
void adstring::allocate(int sz)
13
{
14
  shape = (adstring_shape*)mem_malloc(sizeof(adstring_shape));
15
  shape->sz = sz;
16
#if (defined __ZTC__) || (defined __NDPX__)
17
  s =  (char*)mem_malloc(sz+1);
18
#else
19
  s =  (unsigned char*)mem_malloc(sz+1);
20
#endif
21
  if (!s) {
22
    cerr << "Error allocating memory for adstring" << endl;
23
    exit(1);
24
  }
25
}
26

  
27
adstring::operator unsigned char * ()
28
{
29
  return (unsigned char*)s + 1;
30
}
31

  
32
adstring::operator char * ()
33
{
34
  return (char*)(s + 1);
35
}
36

  
37
#ifdef USE_CONST
38
adstring::operator _CONST unsigned char * () _CONST
39
{
40
  return (_CONST unsigned char*)s + 1;
41
}
42

  
43
adstring::operator _CONST char * () _CONST
44
{
45
  return (_CONST char*)(s + 1);
46
}
47
#endif
48

  
49
  unsigned int adstring::size(void) _CONST
50
  {
51
    if (!s) return 0;
52
    return (strlen((char*)(s+1)));
53
  }
54

  
55
  unsigned int adstring::buff_size(void)
56
  {
57
    return (shape->size());
58
  }
59

  
60
ostream & operator << (ostream & c, _CONST adstring & t)
61
{
62
  for (int i = 1; i <= t.size(); i++)
63
  {
64
  #if (defined __ZTC__) || (defined __NDPX__)
65
    c << (char)(t.s)[i];
66
  #else
67
    c << (t.s)[i];
68
  #endif
69
  }
70
  return (c);
71
}
72

  
73
adstring & adstring::operator = (_CONST char t)
74
{ 
75
  return (*this = adstring(t)); 
76
}
trunk/src/sparse/str.cpp (revision 1542)
1
/*
2
 * $Id$
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California 
6
 */
7
#include <fvar.hpp>
8
#include <string.h>
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <math.h>
12
#ifdef __NDPX__
13
  #include <dos.h> //itoa
14
#endif
15

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff