MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
mbstrbuf Class Reference

#include <mbstrbuf.h>

Collaboration diagram for mbstrbuf:

Public Member Functions

 mbstrbuf (unsigned l=0)
 
std::ostream & stats (std::ostream &out)
 
void make_room (unsigned newlen)
 
void return_cursor (unsigned newcursor=0)
 
void print_str (const char *str)
 
void print_double (const char *fmt, double d)
 
const char * get_buf (void) const
 
unsigned get_len (void) const
 

Private Attributes

unsigned len
 
unsigned cursor
 
char * buf
 

Friends

std::ostream & operator<< (std::ostream &, const mbstrbuf &)
 

Detailed Description

Definition at line 37 of file mbstrbuf.h.

Constructor & Destructor Documentation

mbstrbuf::mbstrbuf ( unsigned  l = 0)
inline

Definition at line 46 of file mbstrbuf.h.

References buf, and len.

46  : len(l), cursor(0), buf(0) {
47  if (len > 0) {
48  buf = new char[len];
49  }
50  };
unsigned cursor
Definition: mbstrbuf.h:42
unsigned len
Definition: mbstrbuf.h:41
char * buf
Definition: mbstrbuf.h:43

Member Function Documentation

const char * mbstrbuf::get_buf ( void  ) const

Definition at line 99 of file mbstrbuf.cc.

References buf.

100 {
101  return buf;
102 }
char * buf
Definition: mbstrbuf.h:43
unsigned mbstrbuf::get_len ( void  ) const

Definition at line 105 of file mbstrbuf.cc.

References len.

106 {
107  return len;
108 }
unsigned len
Definition: mbstrbuf.h:41
void mbstrbuf::make_room ( unsigned  newlen)

Definition at line 47 of file mbstrbuf.cc.

References buf, cursor, and len.

Referenced by print_double(), and print_str().

48 {
49  newlen = std::max(cursor + 2*newlen, 2*len);
50  char *ptr = new char[newlen];
51  memcpy(ptr, buf, cursor);
52  delete[] buf;
53  buf = ptr;
54  len = newlen;
55 }
unsigned cursor
Definition: mbstrbuf.h:42
unsigned len
Definition: mbstrbuf.h:41
char * buf
Definition: mbstrbuf.h:43
void mbstrbuf::print_double ( const char *  fmt,
double  d 
)

Definition at line 83 of file mbstrbuf.cc.

References buf, cursor, len, and make_room().

84 {
85  int dlen, buflen;
86 
87 retry:;
88  buflen = len - cursor;
89  dlen = snprintf(&buf[cursor], buflen, fmt, d);
90  if (dlen >= buflen) {
91  make_room(dlen);
92  goto retry;
93  }
94 
95  cursor += dlen;
96 }
unsigned cursor
Definition: mbstrbuf.h:42
void make_room(unsigned newlen)
Definition: mbstrbuf.cc:47
unsigned len
Definition: mbstrbuf.h:41
char * buf
Definition: mbstrbuf.h:43

Here is the call graph for this function:

void mbstrbuf::print_str ( const char *  str)

Definition at line 65 of file mbstrbuf.cc.

References buf, cursor, len, and make_room().

66 {
67  int slen, buflen;
68 
69 retry:;
70  buflen = len - cursor;
71  slen = strlen(str);
72  if (slen >= buflen) {
73  make_room(slen);
74  goto retry;
75  }
76 
77  memcpy(&buf[cursor], str, slen);
78  cursor += slen;
79  buf[cursor] = '\0';
80 }
unsigned cursor
Definition: mbstrbuf.h:42
void make_room(unsigned newlen)
Definition: mbstrbuf.cc:47
unsigned len
Definition: mbstrbuf.h:41
char * buf
Definition: mbstrbuf.h:43

Here is the call graph for this function:

void mbstrbuf::return_cursor ( unsigned  newcursor = 0)

Definition at line 58 of file mbstrbuf.cc.

References cursor.

59 {
60  cursor = newcursor;
61 }
unsigned cursor
Definition: mbstrbuf.h:42
std::ostream & mbstrbuf::stats ( std::ostream &  out)

Definition at line 40 of file mbstrbuf.cc.

References cursor, and len.

41 {
42  return out << "len=" << len << "; cursor=" << cursor << std::endl;
43 }
unsigned cursor
Definition: mbstrbuf.h:42
unsigned len
Definition: mbstrbuf.h:41

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  ,
const mbstrbuf  
)
friend

Definition at line 111 of file mbstrbuf.cc.

112 {
113  return out << buf.buf;
114 }
char * buf
Definition: mbstrbuf.h:43

Member Data Documentation

char* mbstrbuf::buf
private

Definition at line 43 of file mbstrbuf.h.

Referenced by get_buf(), make_room(), mbstrbuf(), operator<<(), print_double(), and print_str().

unsigned mbstrbuf::cursor
private

Definition at line 42 of file mbstrbuf.h.

Referenced by make_room(), print_double(), print_str(), return_cursor(), and stats().

unsigned mbstrbuf::len
private

Definition at line 41 of file mbstrbuf.h.

Referenced by get_len(), make_room(), mbstrbuf(), print_double(), print_str(), and stats().


The documentation for this class was generated from the following files: