1 #ifndef STRING_TABLE_CLASS
2 #define STRING_TABLE_CLASS
4 /*****************************************************************************\
6 * Name : string_table *
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2000-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include "symbol_table.h"
20 #include <basis/astring.h>
21 #include <basis/contracts.h>
23 namespace structures {
25 //! Provides a symbol_table that holds strings as the content.
26 /*! This is essentially a table of named strings. */
29 : public symbol_table<basis::astring>,
30 public virtual basis::packable,
31 public virtual basis::hoople_standard
34 string_table(int estimated_elements = 100) : symbol_table<basis::astring>(estimated_elements),
36 //!< the "estimated_elements" specifies how many items to prepare to efficiently hold.
37 string_table(const string_table &to_copy);
38 virtual ~string_table();
40 DEFINE_CLASS_NAME("string_table");
42 string_table &operator = (const string_table &to_copy);
44 bool operator ==(const string_table &to_compare) const;
46 virtual bool equal_to(const equalizable &to_compare) const {
47 const string_table *cast = dynamic_cast<const string_table *>(&to_compare);
48 if (!cast) return false;
49 return operator ==(*cast);
52 #define STRTAB_COMMENT_PREFIX "#comment#"
53 //!< anything beginning with this is considered a comment.
54 /*!< a numerical uniquifier should be appended to the string to ensure that
55 multiple comments can be handled per table. */
57 static bool is_comment(const basis::astring &to_check);
59 basis::astring text_form() const;
60 //!< prints the contents of the table into the returned string.
61 /*!< if names in the table start with the comment prefix (see above), then
62 they will not be printed as "X=Y" but instead as just "Y". */
64 virtual void text_form(basis::base_string &fill) const { fill = text_form(); }
66 // dictates whether the output will have spaces between the assignment
67 // character and the key name and value. default is to not add them.
68 bool add_spaces() const { return _add_spaces; }
69 void add_spaces(bool add_them) { _add_spaces = add_them; }
71 virtual int packed_size() const;
72 virtual void pack(basis::byte_array &packed_form) const;
73 virtual bool unpack(basis::byte_array &packed_form);
76 bool _add_spaces; // records whether we add spaces around the assignment.