ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/include/common/string.h
Revision: 1.2
Committed: Tue Aug 28 17:08:07 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.1: +48 -9 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
3     * Rights to this code are as documented in doc/pod/gplicense.pod.
4     *
5     * Various string structures and functions.
6     *
7 pippijn 1.2 * $Id: string.h,v 1.1 2007-07-25 01:05:17 pippijn Exp $
8 pippijn 1.1 */
9    
10 pippijn 1.2 #ifndef ERMYTH_STRING_H
11     #define ERMYTH_STRING_H
12 pippijn 1.1
13     void assign (char *dst, char const *src, size_t maxlen);
14    
15     template<size_t N>
16     inline void assign (char (&dst)[N], char const *src)
17     {
18     assign ((char *)&dst, src, N);
19     }
20    
21 pippijn 1.2 /* static string */
22     struct ststr
23 pippijn 1.1 {
24 pippijn 1.2 ststr (char const * const initstr)
25     : m_rep (initstr)
26 pippijn 1.1 {
27     }
28    
29 pippijn 1.2 ststr (ststr &initstr)
30     : m_rep (initstr)
31     {
32     }
33    
34     char const *c_str () const
35     {
36     return m_rep;
37     }
38    
39     operator char const * () const
40     {
41     return c_str ();
42     }
43    
44     friend std::ostream &operator << (std::ostream &os, ststr const &rhs)
45     {
46     os << rhs.c_str ();
47     return os;
48     }
49    
50     private:
51     char const * const m_rep;
52     };
53    
54     // dynamic string
55     struct dynstr : zero_initialised
56     {
57     dynstr (size_t initlength = 32)
58     : m_rep (new char[size]), pos (0), size (initlength)
59     {
60     }
61    
62     ~dynstr ()
63 pippijn 1.1 {
64     delete[] m_rep;
65     }
66    
67     void reset ()
68     {
69     m_rep[0] = '\0';
70     pos = 0;
71     }
72    
73 pippijn 1.2 char const *c_str () const
74 pippijn 1.1 {
75     return m_rep;
76     }
77    
78 pippijn 1.2 operator char const * () const
79     {
80     return c_str ();
81     }
82    
83 pippijn 1.1 size_t length ()
84     {
85     return pos;
86     }
87    
88 pippijn 1.2 dynstr &operator = (char const *rhs)
89 pippijn 1.1 {
90     reset ();
91     append (rhs, strlen (rhs));
92     return *this;
93     }
94    
95     int append (char const c);
96     int append_nonul (char const c);
97     int append (char const * const src, size_t size);
98     int append_nonul (char const * const src, size_t size);
99    
100     int append_unguarded (char const c);
101     int append_unguarded_nonul (char const c);
102     int append_unguarded (char const * const src, size_t size);
103     int append_unguarded_nonul (char const * const src, size_t size);
104    
105     private:
106     char *m_rep;
107     size_t pos;
108     size_t size;
109     };
110    
111     #endif