Changeset 267 for trunk/src/stringpool.h


Ignore:
Timestamp:
Mar 20, 2009, 12:18:53 PM (10 years ago)
Author:
ksherdy
Message:

Construct and pass string literals as read only (const char *) types.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/stringpool.h

    r184 r267  
    1111#define STRINGPOOL_H
    1212
    13 template <int BasePoolSize, int ExpansionPercent> 
     13template <int BasePoolSize, int ExpansionPercent>
    1414class StringPool {
    1515public:
    1616        StringPool();
    1717        ~StringPool();
    18         char * Insert(char * full_string, int lgth);
     18        char * Insert(const char * full_string, int lgth);
    1919        /* The following methods provide for incremental construction of strings
    2020           each constructed by a sequence of calls of the form:
     
    2424        char * CloseString();  /* Return the pointer to the constructed string. */
    2525private:
    26         /* The initial buffer is allocated as part of the StringPool object. 
     26        /* The initial buffer is allocated as part of the StringPool object.
    2727           For stack allocated StringPools that do not exceed the initial
    2828           BasePoolSize, this completely eliminates the overhead and memory
     
    4343};
    4444
    45 template <int BasePoolSize, int ExpansionPercent> 
     45template <int BasePoolSize, int ExpansionPercent>
    4646StringPool<BasePoolSize, ExpansionPercent>::StringPool() {
    4747        node1.more_buffers = NULL;
     
    5454}
    5555
    56 template <int BasePoolSize, int ExpansionPercent> 
     56template <int BasePoolSize, int ExpansionPercent>
    5757StringPool<BasePoolSize, ExpansionPercent>::~StringPool() {
    5858        while (current_node != &node1) {
     
    6363}
    6464
    65 template <int BasePoolSize, int ExpansionPercent> 
     65template <int BasePoolSize, int ExpansionPercent>
    6666void StringPool<BasePoolSize, ExpansionPercent>::ExtendPool() {
    6767        size_t new_buffer_size = (size_t) ((total_size * ExpansionPercent)/100);
     
    8989        printf("ExtendPool() called: space_avail = %i\n", space_avail);
    9090#endif
    91 }       
     91}
    9292
    93 template <int BasePoolSize, int ExpansionPercent> 
    94 char * StringPool<BasePoolSize, ExpansionPercent>::Insert(char * s, int lgth) {
     93template <int BasePoolSize, int ExpansionPercent>
     94char * StringPool<BasePoolSize, ExpansionPercent>::Insert(const char * s, int lgth) {
    9595        int total_lgth = lgth + 1;
    9696        while (total_lgth > space_avail) ExtendPool();
     
    106106}
    107107
    108 template <int BasePoolSize, int ExpansionPercent> 
     108template <int BasePoolSize, int ExpansionPercent>
    109109void StringPool<BasePoolSize, ExpansionPercent>::OpenString() {
    110110        opened_string_ptr = insertion_ptr;
    111111}
    112112
    113 template <int BasePoolSize, int ExpansionPercent> 
     113template <int BasePoolSize, int ExpansionPercent>
    114114void StringPool<BasePoolSize, ExpansionPercent>::AppendSegment(char * segment, int segment_lgth) {
    115115        /* Make sure that there is length for this segment plus null byte. */
     
    120120}
    121121
    122 template <int BasePoolSize, int ExpansionPercent> 
     122template <int BasePoolSize, int ExpansionPercent>
    123123char * StringPool<BasePoolSize, ExpansionPercent>::CloseString() {
    124124        insertion_ptr[0] = '\0';
Note: See TracChangeset for help on using the changeset viewer.