V8 Project
v8::internal::OStringStream Class Reference

#include <ostreams.h>

+ Inheritance diagram for v8::internal::OStringStream:
+ Collaboration diagram for v8::internal::OStringStream:

Public Member Functions

 OStringStream ()
 
 ~OStringStream ()
 
size_t size () const
 
size_t capacity () const
 
const char * data () const
 
const char * c_str () const
 
virtual OStringStreamwrite (const char *s, size_t n) OVERRIDE
 
virtual OStringStreamflush () OVERRIDE
 
- Public Member Functions inherited from v8::internal::OStream
 OStream ()
 
virtual ~OStream ()
 
OStreamoperator<< (OStream &(*manipulator)(OStream &os))
 
OStreamoperator<< (short x)
 
OStreamoperator<< (unsigned short x)
 
OStreamoperator<< (int x)
 
OStreamoperator<< (unsigned int x)
 
OStreamoperator<< (long x)
 
OStreamoperator<< (unsigned long x)
 
OStreamoperator<< (long long x)
 
OStreamoperator<< (unsigned long long x)
 
OStreamoperator<< (double x)
 
OStreamoperator<< (void *x)
 
OStreamoperator<< (char x)
 
OStreamoperator<< (signed char x)
 
OStreamoperator<< (unsigned char x)
 
OStreamoperator<< (const char *s)
 
OStreamput (char c)
 
OStreamdec ()
 
OStreamhex ()
 

Private Member Functions

void reserve (size_t requested_capacity)
 
 DISALLOW_COPY_AND_ASSIGN (OStringStream)
 

Static Private Member Functions

static char * allocate (size_t n)
 
static void deallocate (char *s, size_t n)
 

Private Attributes

size_t size_
 
size_t capacity_
 
char * data_
 

Detailed Description

Definition at line 72 of file ostreams.h.

Constructor & Destructor Documentation

◆ OStringStream()

v8::internal::OStringStream::OStringStream ( )
inline

Definition at line 74 of file ostreams.h.

74  : size_(0), capacity_(32), data_(allocate(capacity_)) {
75  data_[0] = '\0';
76  }
static char * allocate(size_t n)
Definition: ostreams.h:91

References data_.

◆ ~OStringStream()

v8::internal::OStringStream::~OStringStream ( )
inline

Definition at line 77 of file ostreams.h.

static void deallocate(char *s, size_t n)
Definition: ostreams.h:92

References capacity_, data_, and deallocate().

+ Here is the call graph for this function:

Member Function Documentation

◆ allocate()

static char* v8::internal::OStringStream::allocate ( size_t  n)
inlinestaticprivate

Definition at line 91 of file ostreams.h.

91 { return new char[n]; }

Referenced by reserve().

+ Here is the caller graph for this function:

◆ c_str()

const char* v8::internal::OStringStream::c_str ( ) const
inline

◆ capacity()

size_t v8::internal::OStringStream::capacity ( ) const
inline

Definition at line 80 of file ostreams.h.

80 { return capacity_; }

References capacity_.

◆ data()

const char* v8::internal::OStringStream::data ( ) const
inline

Definition at line 81 of file ostreams.h.

81 { return data_; }

References data_.

Referenced by c_str().

+ Here is the caller graph for this function:

◆ deallocate()

static void v8::internal::OStringStream::deallocate ( char *  s,
size_t  n 
)
inlinestaticprivate

Definition at line 92 of file ostreams.h.

92 { delete[] s; }

Referenced by reserve(), and ~OStringStream().

+ Here is the caller graph for this function:

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::OStringStream::DISALLOW_COPY_AND_ASSIGN ( OStringStream  )
private

◆ flush()

OStringStream & v8::internal::OStringStream::flush ( )
virtual

Implements v8::internal::OStream.

Definition at line 138 of file ostreams.cc.

138  {
139  return *this;
140 }

◆ reserve()

void v8::internal::OStringStream::reserve ( size_t  requested_capacity)
private

Definition at line 143 of file ostreams.cc.

143  {
144  if (requested_capacity <= capacity_) return;
145  size_t new_capacity = // Handle possible overflow by not doubling.
146  std::max(std::max(capacity_ * 2, capacity_), requested_capacity);
147  char * new_data = allocate(new_capacity);
148  memcpy(new_data, data_, size_);
150  capacity_ = new_capacity;
151  data_ = new_data;
152 }

References allocate(), capacity_, data_, deallocate(), and size_.

Referenced by write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

size_t v8::internal::OStringStream::size ( ) const
inline

Definition at line 79 of file ostreams.h.

79 { return size_; }

References size_.

Referenced by v8::internal::InsertIntoString().

+ Here is the caller graph for this function:

◆ write()

OStringStream & v8::internal::OStringStream::write ( const char *  s,
size_t  n 
)
virtual

Implements v8::internal::OStream.

Definition at line 127 of file ostreams.cc.

127  {
128  size_t new_size = size_ + n;
129  if (new_size < size_) return *this; // Overflow => no-op.
130  reserve(new_size + 1);
131  memcpy(data_ + size_, s, n);
132  size_ = new_size;
133  data_[size_] = '\0';
134  return *this;
135 }
void reserve(size_t requested_capacity)
Definition: ostreams.cc:143

References data_, reserve(), and size_.

+ Here is the call graph for this function:

Member Data Documentation

◆ capacity_

size_t v8::internal::OStringStream::capacity_
private

Definition at line 97 of file ostreams.h.

Referenced by capacity(), reserve(), and ~OStringStream().

◆ data_

char* v8::internal::OStringStream::data_
private

Definition at line 98 of file ostreams.h.

Referenced by data(), OStringStream(), reserve(), write(), and ~OStringStream().

◆ size_

size_t v8::internal::OStringStream::size_
private

Definition at line 96 of file ostreams.h.

Referenced by reserve(), size(), and write().


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