GME  13
Match.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: Match.cpp 678879 2008-07-22 20:05:05Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/util/regx/Match.hpp>
00026 #include <xercesc/framework/MemoryManager.hpp>
00027 
00028 XERCES_CPP_NAMESPACE_BEGIN
00029 
00030 // ---------------------------------------------------------------------------
00031 //  Match: Constructors and Destructors
00032 // ---------------------------------------------------------------------------
00033 Match::Match(MemoryManager* const manager) :
00034     fNoGroups(0)
00035     , fPositionsSize(0)
00036     , fStartPositions(0)
00037     , fEndPositions(0)
00038     , fMemoryManager(manager)
00039 {
00040 
00041 }
00042 
00043 Match::Match(const Match& toCopy) :
00044     XMemory(toCopy) 
00045     , fNoGroups(0)
00046     , fPositionsSize(0)
00047     , fStartPositions(0)
00048     , fEndPositions(0)
00049     , fMemoryManager(0)
00050 {
00051   initialize(toCopy);
00052 }
00053 
00054 Match& Match::operator=(const Match& toAssign) {
00055   
00056   initialize(toAssign);
00057   return *this;
00058 }
00059 
00060 
00061 Match::~Match() {
00062 
00063     cleanUp();
00064 }
00065 
00066 // ---------------------------------------------------------------------------
00067 //  Match: Setter Methods
00068 // ---------------------------------------------------------------------------
00069 void Match::setNoGroups(const int n) {
00070 
00071     if (fNoGroups <= 0 || fPositionsSize < n) {
00072 
00073         cleanUp();
00074         fPositionsSize = n;
00075         fStartPositions = (int*) fMemoryManager->allocate(n * sizeof(int));//new int[n];
00076         fEndPositions = (int*) fMemoryManager->allocate(n * sizeof(int));//new int[n];
00077     }
00078 
00079     fNoGroups = n;
00080 
00081     for (int i=0; i< fPositionsSize; i++) {
00082 
00083         fStartPositions[i] = -1;
00084         fEndPositions[i] = -1;
00085     }
00086 }
00087 
00088 // ---------------------------------------------------------------------------
00089 //  Match: private helpers methods
00090 // ---------------------------------------------------------------------------
00091 void Match::initialize(const Match &toCopy){
00092 
00093   //do not copy over value of fPositionSize as it is irrelevant to the 
00094   //state of the Match
00095 
00096   fMemoryManager = toCopy.fMemoryManager;
00097   int toCopySize = toCopy.getNoGroups();
00098   setNoGroups(toCopySize);
00099 
00100   for (int i=0; i<toCopySize; i++){
00101     setStartPos(i, toCopy.getStartPos(i));
00102     setEndPos(i, toCopy.getEndPos(i));
00103   }           
00104 
00105 }
00106 
00107 void Match::cleanUp() {
00108 
00109     fMemoryManager->deallocate(fStartPositions);//delete [] fStartPositions;
00110     fMemoryManager->deallocate(fEndPositions);//delete [] fEndPositions;
00111 
00112     fStartPositions = 0;
00113     fEndPositions = 0;
00114 }
00115 
00116 XERCES_CPP_NAMESPACE_END
00117