3a73e98390f6a05ad235f4ff270ece865f124adf
[platform/upstream/groff.git] / src / include / symbol.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989-2014  Free Software Foundation, Inc.
3      Written by James Clark (jjc@jclark.com)
4
5 This file is part of groff.
6
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #define DONT_STORE 1
21 #define MUST_ALREADY_EXIST 2
22
23 class symbol {
24   static const char **table;
25   static int table_used;
26   static int table_size;
27   static char *block;
28   static int block_size;
29   const char *s;
30 public:
31   symbol(const char *p, int how = 0);
32   symbol();
33   unsigned long hash() const;
34   int operator ==(symbol) const;
35   int operator !=(symbol) const;
36   const char *contents() const;
37   int is_null() const;
38   int is_empty() const;
39 };
40
41
42 extern const symbol NULL_SYMBOL;
43 extern const symbol EMPTY_SYMBOL;
44
45 inline symbol::symbol() : s(0)
46 {
47 }
48
49 inline int symbol::operator==(symbol p) const
50 {
51   return s == p.s;
52 }
53
54 inline int symbol::operator!=(symbol p) const
55 {
56   return s != p.s;
57 }
58
59 inline unsigned long symbol::hash() const
60 {
61   return (unsigned long)s;
62 }
63
64 inline const char *symbol::contents() const
65 {
66   return s;
67 }
68
69 inline int symbol::is_null() const
70 {
71   return s == 0;
72 }
73
74 inline int symbol::is_empty() const
75 {
76   return s != 0 && *s == 0;
77 }
78
79 symbol concat(symbol, symbol);
80
81 extern symbol default_symbol;