source: icXML/icXML-devel/src/icxmlc/XMLSymbolStack.hpp @ 2720

Last change on this file since 2720 was 2720, checked in by cameron, 6 years ago

Initial check-in of icXML 0.8 source files

File size: 1.5 KB
RevLine 
[2720]1/*
2 *  Copyright © 2012 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icXML is a trademark of International Characters.
5 */
6
7/*
8 * @author Nigel Medforth, nigelm -at- interational-characters.com
9 * @version $Id: XMLSymbolStack.hpp 207 2012-12-02 20:38:22Z robc $
10 *
11 */
12
13#ifndef XMLSYMBOLSTACK_HPP
14#define XMLSYMBOLSTACK_HPP
15
16#include <icxmlc/XMLConfig.hpp>
17#include <icxmlc/Array.hpp>
18
19XERCES_CPP_NAMESPACE_BEGIN
20
21class XMLSymbol;
22
23/**
24 NOTE: the goal of this class is to eventually replace the /xercesc/internal/ElemStack class without
25 having to support the exact set of features that is currently within it.
26 **/
27class XMLSymbolStack
28{
29        public:
30
31                XMLSymbolStack()
32                : _size(0)
33                , _stack()
34                {
35
36                }
37
38                IDISA_ALWAYS_INLINE
39                void push(gid_t gid);
40
41                IDISA_ALWAYS_INLINE
42                gid_t pop();
43
44                IDISA_ALWAYS_INLINE
45                bool isEmpty() const
46                {
47                        return size() == 0;
48                }
49
50                size_t size() const
51                {
52                        return _size;
53                }
54
55                // this needs a copy constructor so that we know for certain that it'll be stack aligned in the parser
56
57        private:
58
59                size_t                                                                                  _size;
60                DynamicArray<gid_t, INITIAL_MAX_SCOPE>                  _stack;
61};
62
63void XMLSymbolStack::push(gid_t gid)
64{
65        if (unlikely(_size == _stack.capacity()))
66        {
67                _stack.expand(_stack.capacity());
68        }
69        _stack[_size++] = gid;
70}
71
72gid_t XMLSymbolStack::pop()
73{
74        if (unlikely(_size == 0))
75        {
76                return -1;
77        }
78        return _stack[--_size];
79}
80
81XERCES_CPP_NAMESPACE_END
82
83#endif // XMLSYMBOLSTACK_HPP
Note: See TracBrowser for help on using the repository browser.