source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/regx/Match.hpp @ 2674

Revision 2674, 5.2 KB checked in by mattausch, 16 years ago (diff)
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: Match.hpp 568078 2007-08-21 11:43:25Z amassari $
20 */
21
22#if !defined(MATCH_HPP)
23#define MATCH_HPP
24
25// ---------------------------------------------------------------------------
26//  Includes
27// ---------------------------------------------------------------------------
28#include <xercesc/util/PlatformUtils.hpp>
29#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
30#include <xercesc/util/RuntimeException.hpp>
31
32XERCES_CPP_NAMESPACE_BEGIN
33
34/**
35  * An instance of this class has ranges captured in matching
36  */
37  class XMLUTIL_EXPORT Match : public XMemory
38{
39public:
40
41        // -----------------------------------------------------------------------
42  //  Public Constructors and Destructor
43  // -----------------------------------------------------------------------
44        Match(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
45       
46  /**
47  * Copy constructor
48  */
49  Match(const Match& toCopy);
50  Match& operator=(const Match& toAssign);
51
52        virtual ~Match();
53
54        // -----------------------------------------------------------------------
55        // Getter functions
56        // -----------------------------------------------------------------------
57        int getNoGroups() const;
58        int getStartPos(int index) const;
59        int getEndPos(int index) const;
60
61        // -----------------------------------------------------------------------
62        // Setter functions
63        // -----------------------------------------------------------------------
64        void setNoGroups(const int n);
65        void setStartPos(const int index, const int value);
66        void setEndPos(const int index, const int value);
67
68private:
69        // -----------------------------------------------------------------------
70        // Initialize/Clean up methods
71        // -----------------------------------------------------------------------
72  void initialize(const Match& toCopy);
73        void cleanUp();
74
75        // -----------------------------------------------------------------------
76    //  Private data members
77    //
78    //  fNoGroups
79    //  Represents no of regular expression groups
80        //             
81    //  fStartPositions
82    //  Array of start positions in the target text matched to specific
83        //              regular expression group
84        //
85        //      fEndPositions
86        //              Array of end positions in the target text matched to specific
87        //              regular expression group
88        //
89        //      fPositionsSize
90        //              Actual size of Start/EndPositions array.
91    // -----------------------------------------------------------------------
92        int fNoGroups;
93        int fPositionsSize;
94        int* fStartPositions;
95        int* fEndPositions;
96    MemoryManager* fMemoryManager;
97};
98
99/**
100  * Inline Methods
101  */
102
103// ---------------------------------------------------------------------------
104//  Match: getter methods
105// ---------------------------------------------------------------------------
106inline int Match::getNoGroups() const {
107
108        if (fNoGroups < 0)
109                ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
110
111        return fNoGroups;
112}
113
114inline int Match::getStartPos(int index) const {
115
116        if (!fStartPositions)
117                ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
118
119        if (index < 0 || fNoGroups <= index)
120                ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
121
122        return fStartPositions[index];
123}
124
125inline int Match::getEndPos(int index) const {
126
127        if (!fEndPositions)
128                ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
129
130        if (index < 0 || fNoGroups <= index)
131                ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
132
133        return fEndPositions[index];
134}
135
136// ---------------------------------------------------------------------------
137//  Match: setter methods
138// ---------------------------------------------------------------------------
139inline void Match::setStartPos(const int index, const int value) {
140
141        if (!fStartPositions)
142        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
143
144        if (index < 0 || fNoGroups <= index)
145                ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
146
147        fStartPositions[index] = value;
148}
149
150inline void Match::setEndPos(const int index, const int value) {
151
152        if (!fEndPositions)
153        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
154
155        if (index < 0 || fNoGroups <= index)
156                ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
157
158        fEndPositions[index] = value;
159}
160
161XERCES_CPP_NAMESPACE_END
162
163#endif
Note: See TracBrowser for help on using the repository browser.