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: DecimalDatatypeValidator.hpp 527149 2007-04-10 14:56:39Z amassari $
20  */
21 
22 #if !defined(XERCESC_INCLUDE_GUARD_DECIMAL_DATATYPEVALIDATOR_HPP)
23 #define XERCESC_INCLUDE_GUARD_DECIMAL_DATATYPEVALIDATOR_HPP
24 
25 #include <xercesc/validators/datatype/AbstractNumericValidator.hpp>
26 #include <xercesc/util/RefVectorOf.hpp>
27 
28 XERCES_CPP_NAMESPACE_BEGIN
29 
30 class XMLBigDecimal;
31 
32 class VALIDATORS_EXPORT DecimalDatatypeValidator : public AbstractNumericValidator
33 {
34 public:
35 
36     // -----------------------------------------------------------------------
37     //  Public ctor/dtor
38     // -----------------------------------------------------------------------
39 	/** @name Constructors and Destructor */
40     //@{
41 
42     DecimalDatatypeValidator
43     (
44         MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
45     );
46     DecimalDatatypeValidator
47     (
48         DatatypeValidator* const baseValidator
49         , RefHashTableOf<KVStringPair>* const facets
50         , RefArrayVectorOf<XMLCh>* const enums
51         , const int finalSet
52         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
53     );
54     virtual ~DecimalDatatypeValidator();
55 
56 	//@}
57 
58     // -----------------------------------------------------------------------
59     // Compare methods
60     // -----------------------------------------------------------------------
61     /** @name Compare Function */
62     //@{
63 
64     /**
65      * Compare two boolean data types
66      *
67      * @param content1
68      * @param content2
69      * @return
70      */
71     virtual int compare(const XMLCh* const, const XMLCh* const
72         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
73         );
74 
75     //@}
76 
77     /**
78       * Returns an instance of the base datatype validator class
79 	  * Used by the DatatypeValidatorFactory.
80       */
81     virtual DatatypeValidator* newInstance
82     (
83         RefHashTableOf<KVStringPair>* const facets
84         , RefArrayVectorOf<XMLCh>* const enums
85         , const int finalSet
86         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
87     );
88 
89     virtual const XMLCh* getCanonicalRepresentation
90                         (
91                           const XMLCh*         const rawData
92                         ,       MemoryManager* const memMgr = 0
93                         ,       bool                 toValidate = false
94                         ) const;
95 
96     /***
97      * Support for Serialization/De-serialization
98      ***/
99     DECL_XSERIALIZABLE(DecimalDatatypeValidator)
100 
101 protected:
102 
103 // -----------------------------------------------------------------------
104 // ctor provided to be used by derived classes
105 // -----------------------------------------------------------------------
106     DecimalDatatypeValidator
107     (
108         DatatypeValidator* const baseValidator
109         , RefHashTableOf<KVStringPair>* const facets
110         , const int finalSet
111         , const ValidatorType type
112         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
113     );
114 
115 // -----------------------------------------------------------------------
116 // Abstract interface from AbstractNumericFacetValidator
117 // -----------------------------------------------------------------------
118 
119     virtual void assignAdditionalFacet(const XMLCh* const key
120                                      , const XMLCh* const value
121                                      , MemoryManager* const manager);
122 
123     virtual void inheritAdditionalFacet();
124 
125     virtual void checkAdditionalFacetConstraints(MemoryManager* const manager) const;
126 
127     virtual void checkAdditionalFacetConstraintsBase(MemoryManager* const manager) const;
128 
129     virtual int  compareValues(const XMLNumber* const lValue
130                              , const XMLNumber* const rValue);
131 
132     virtual void  setMaxInclusive(const XMLCh* const);
133 
134     virtual void  setMaxExclusive(const XMLCh* const);
135 
136     virtual void  setMinInclusive(const XMLCh* const);
137 
138     virtual void  setMinExclusive(const XMLCh* const);
139 
140     virtual void  setEnumeration(MemoryManager* const manager);
141 
142 // -----------------------------------------------------------------------
143 // Abstract interface from AbstractNumericValidator
144 // -----------------------------------------------------------------------
145 
146     virtual void checkContent(const XMLCh*             const content
147                             ,       ValidationContext* const context
148                             , bool                           asBase
149                             ,       MemoryManager*     const manager);
150 public:
151 
152 // -----------------------------------------------------------------------
153 // Getter methods
154 // -----------------------------------------------------------------------
155 
156     inline unsigned int                    getTotalDigits() const;
157 
158     inline unsigned int                    getFractionDigits() const;
159 
160 private:
161 // -----------------------------------------------------------------------
162 // Setter methods
163 // -----------------------------------------------------------------------
164 
165     inline void  setTotalDigits(unsigned int);
166 
167     inline void  setFractionDigits(unsigned int);
168 
169     // -----------------------------------------------------------------------
170     //  Private data members
171     //
172     // -----------------------------------------------------------------------
173     unsigned int         fTotalDigits;
174     unsigned int         fFractionDigits;
175 
176 
177     // -----------------------------------------------------------------------
178     //  Unimplemented constructors and operators
179     // -----------------------------------------------------------------------
180     DecimalDatatypeValidator(const DecimalDatatypeValidator&);
181     DecimalDatatypeValidator& operator=(const DecimalDatatypeValidator&);
182 };
183 
184 // -----------------------------------------------------------------------
185 // Getter methods
186 // -----------------------------------------------------------------------
187 
getTotalDigits() const188 inline unsigned int DecimalDatatypeValidator::getTotalDigits() const
189 {
190     return fTotalDigits;
191 }
192 
getFractionDigits() const193 inline unsigned int DecimalDatatypeValidator::getFractionDigits() const
194 {
195     return fFractionDigits;
196 }
197 
198 // -----------------------------------------------------------------------
199 // Setter methods
200 // -----------------------------------------------------------------------
201 
setTotalDigits(unsigned int newTotalDigits)202 inline void DecimalDatatypeValidator::setTotalDigits(unsigned int newTotalDigits)
203 {
204     fTotalDigits = newTotalDigits;
205 }
206 
setFractionDigits(unsigned int newFractionDigits)207 inline void DecimalDatatypeValidator::setFractionDigits(unsigned int newFractionDigits)
208 {
209     fFractionDigits = newFractionDigits;
210 }
211 
212 XERCES_CPP_NAMESPACE_END
213 
214 #endif
215 
216 /**
217   * End of file DecimalDatatypeValidator.hpp
218   */
219