Lolly 1.4.27
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Friends | List of all members
string_rep Class Reference

#include <string.hpp>

Inheritance diagram for string_rep:
Inheritance graph
[legend]
Collaboration diagram for string_rep:
Collaboration graph
[legend]

Public Member Functions

 string_rep ()
 
 string_rep (int n)
 
 ~string_rep ()
 
int expand_or_shrink_by (int delta)
 expand (or shrink) string by delta, but do not release memory when string is shrinked.
 
void resize (int n)
 expand (or shrink) string to given length n, and try to release memory when string is shrinked.
 
void reserve (int n)
 reserve memory space to contain at least n word in the whole string. Do not affect length of string, and do not release memory when n is smaller than current space.
 

Private Attributes

int n
 
chara
 
int a_N
 
- Private Attributes inherited from concrete_struct
int ref_count
 The reference count for the concrete object.
 

Friends

class string
 
int N (string a)
 

Additional Inherited Members

- Private Member Functions inherited from concrete_struct
 concrete_struct ()
 Default constructor for the concrete object. Increments the reference count.
 
virtual ~concrete_struct ()
 Virtual destructor for the concrete object. Decrements the reference count.
 

Detailed Description

Definition at line 24 of file string.hpp.

Constructor & Destructor Documentation

◆ string_rep() [1/2]

string_rep::string_rep ( )
inline

Definition at line 30 of file string.hpp.

30: n (0), a_N (0), a (NULL) {}
The list class represents a linked list.
Definition list.hpp:48
char * a
Definition string.hpp:26

◆ string_rep() [2/2]

string_rep::string_rep ( int n)

Definition at line 34 of file string.cpp.

34 : n (n2), a_N (round_length (n2)), a (nullptr) {
35 if (a_N != 0) {
37 }
38}
int round_length(int n, size_t s)
Definition array.ipp:21

◆ ~string_rep()

string_rep::~string_rep ( )
inline

Definition at line 32 of file string.hpp.

32 {
33 if (a_N != 0) tm_delete_array (a);
34 }
void tm_delete_array(C *Ptr)

Member Function Documentation

◆ expand_or_shrink_by()

int string_rep::expand_or_shrink_by ( int delta)

expand (or shrink) string by delta, but do not release memory when string is shrinked.

Returns
string length before expansion

Definition at line 65 of file string.cpp.

65 {
66 int old_n= n;
67 n+= delta;
68 reserve (n);
69 return old_n;
70}
void reserve(int n)
reserve memory space to contain at least n word in the whole string. Do not affect length of string,...
Definition string.cpp:73
url delta(url base, url u)
Definition url.cpp:469

◆ resize()

void string_rep::resize ( int n)

expand (or shrink) string to given length n, and try to release memory when string is shrinked.

Note
expand_or_shrink_by may be faster if memory space is reserved

Definition at line 41 of file string.cpp.

41 {
42 int nn= round_length (n);
43 int mm= round_length (m);
44 if (mm != nn) {
45 if (mm != 0) {
46 if (nn != 0) {
47 a_N= mm;
49 }
50 else {
51 a_N= mm;
53 }
54 }
55 else if (nn != 0) {
57 a_N= 0;
58 a = NULL;
59 };
60 }
61 n= m;
62}

◆ reserve()

void string_rep::reserve ( int n)

reserve memory space to contain at least n word in the whole string. Do not affect length of string, and do not release memory when n is smaller than current space.

Definition at line 73 of file string.cpp.

73 {
74 int old_size= a_N;
75 if (new_n != 0) {
76 if (old_size == 0) {
79 }
80 else if (old_size < new_n) {
83 }
84 }
85 else {
86 if (old_size != 0) {
88 a = NULL;
89 a_N= 0;
90 };
91 }
92}

Friends And Related Symbol Documentation

◆ string

Definition at line 58 of file string.hpp.

◆ N

int N ( string a)
friend

Definition at line 86 of file string.hpp.

86 {
87 return a->n;
88}

Member Data Documentation

◆ n

int string_rep::n
private

Definition at line 25 of file string.hpp.

◆ a

char* string_rep::a
private

Definition at line 26 of file string.hpp.

◆ a_N

int string_rep::a_N
private

Definition at line 27 of file string.hpp.


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