feisty meow concerns codebase  2.140
string_table.h
Go to the documentation of this file.
1 #ifndef STRING_TABLE_CLASS
2 #define STRING_TABLE_CLASS
3 
4 /*****************************************************************************\
5 * *
6 * Name : string_table *
7 * Author : Chris Koeritz *
8 * *
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 \*****************************************************************************/
17 
18 #include "symbol_table.h"
19 
20 #include <basis/astring.h>
21 #include <basis/contracts.h>
22 
23 namespace structures {
24 
26 
29 : public symbol_table<basis::astring>,
30  public virtual basis::packable,
31  public virtual basis::hoople_standard
32 {
33 public:
35  _add_spaces(false) {}
37  string_table(const string_table &to_copy);
38  virtual ~string_table();
39 
40  DEFINE_CLASS_NAME("string_table");
41 
42  string_table &operator = (const string_table &to_copy);
43 
44  bool operator ==(const string_table &to_compare) const;
45 
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);
50  }
51 
52  #define STRTAB_COMMENT_PREFIX "#comment#"
54 
57  static bool is_comment(const basis::astring &to_check);
58 
59  basis::astring text_form() const;
61 
64  virtual void text_form(basis::base_string &fill) const { fill = text_form(); }
65 
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; }
70 
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);
74 
75 private:
76  bool _add_spaces; // records whether we add spaces around the assignment.
77 };
78 
79 } //namespace.
80 
81 #endif
82 
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
Defines the base class for all string processing objects in hoople.
Definition: base_string.h:28
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
the base class of the most easily used and tested objects in the library.
Definition: contracts.h:161
A base class for objects that can pack into an array of bytes.
Definition: byte_array.h:87
Provides a symbol_table that holds strings as the content.
Definition: string_table.h:32
DEFINE_CLASS_NAME("string_table")
void add_spaces(bool add_them)
Definition: string_table.h:69
virtual bool equal_to(const equalizable &to_compare) const
Definition: string_table.h:46
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
basis::astring text_form() const
prints the contents of the table into the returned string.
bool operator==(const string_table &to_compare) const
string_table(int estimated_elements=100)
the "estimated_elements" specifies how many items to prepare to efficiently hold.
Definition: string_table.h:34
virtual void text_form(basis::base_string &fill) const
Provides a text view of all the important info owned by this object.
Definition: string_table.h:64
static bool is_comment(const basis::astring &to_check)
string_table & operator=(const string_table &to_copy)
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
virtual int packed_size() const
Estimates the space needed for the packed structure.
Maintains a list of names, where each name has a type and some contents.
Definition: symbol_table.h:36
int estimated_elements() const
returns the number of symbols the table is optimized for.
Definition: symbol_table.h:226
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55