Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / ace / XML_Utils / XSCRT / XMLSchema.hpp
blob7d19b508c94518ffddadfe7cfe5df8f4dd05e4fa
1 // file : XSCRT/XMLSchema.hpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #ifndef XSCRT_XMLSCHEMA_HPP
4 #define XSCRT_XMLSCHEMA_HPP
6 #include <string>
7 // #include <iostream> //@@ tmp
9 #include "ace/XML_Utils/XMLSchema/XSCRT/Elements.hpp"
11 namespace XMLSchema
13 typedef XSCRT::FundamentalType<signed char> byte;
14 typedef XSCRT::FundamentalType<unsigned char> unsignedByte;
16 typedef XSCRT::FundamentalType<short> short_;
17 typedef XSCRT::FundamentalType<unsigned short> unsignedShort;
19 typedef XSCRT::FundamentalType<int> int_;
20 typedef XSCRT::FundamentalType<unsigned int> unsignedInt;
22 typedef XSCRT::FundamentalType<long long> long_;
23 typedef XSCRT::FundamentalType<unsigned long long> unsignedLong;
25 //@@ It would be nice to use some arbitrary-length integer class.
27 typedef long_ decimal;
28 typedef decimal integer;
29 typedef integer nonPositiveInteger;
30 typedef integer nonNegativeInteger;
31 typedef nonNegativeInteger positiveInteger;
32 typedef nonPositiveInteger negativeInteger;
35 typedef XSCRT::FundamentalType<bool> boolean;
37 typedef XSCRT::FundamentalType<float> float_;
38 typedef XSCRT::FundamentalType<double> double_;
40 // Just to make GCC 3.3 and other broken compilers shutup.
42 using std::basic_string;
45 template <typename C>
46 class string : public XSCRT::Type, public basic_string<C>
48 protected:
49 typedef basic_string<C> Base__ ;
51 public:
52 //@@ VC6 does not inject XSCRT::Type into the scope so I have
53 // to qualify it all the time.
55 string () = default;
57 string (XSCRT::XML::Element<C> const& e)
58 : Base__ (e.value ())
62 string (XSCRT::XML::Attribute<C> const& a)
63 : Base__ (a.value ())
67 string (Base__ const& x)
68 : Base__ (x)
72 string&
73 operator= (Base__ const& x)
75 static_cast<Base__&> (*this) = x;
76 return *this;
81 template <typename C>
82 class normalizedString : public string<C>
84 protected:
85 typedef typename string<C>::Base__ Base__;
87 public:
88 normalizedString () = default;
90 normalizedString (XSCRT::XML::Element<C> const& e)
91 : string<C> (e)
95 normalizedString (XSCRT::XML::Attribute<C> const& a)
96 : string<C> (a)
100 normalizedString (Base__ const& x)
101 : string<C> (x)
105 normalizedString&
106 operator= (Base__ const& x)
108 static_cast<Base__&> (*this) = x;
109 return *this;
114 template <typename C>
115 class token : public normalizedString<C>
117 protected:
118 typedef typename normalizedString<C>::Base__ Base__;
120 public:
121 token () = default;
123 token (XSCRT::XML::Element<C> const& e)
124 : normalizedString<C> (e)
128 token (XSCRT::XML::Attribute<C> const& a)
129 : normalizedString<C> (a)
133 token (Base__ const& x)
134 : normalizedString<C> (x)
138 token&
139 operator= (Base__ const& x)
141 static_cast<Base__&> (*this) = x;
142 return *this;
147 template <typename C>
148 class NMTOKEN : public token<C>
150 protected:
151 typedef typename token<C>::Base__ Base__;
153 public:
154 NMTOKEN () = default;
156 NMTOKEN (XSCRT::XML::Element<C> const& e)
157 : token<C> (e)
161 NMTOKEN (XSCRT::XML::Attribute<C> const& a)
162 : token<C> (a)
166 NMTOKEN (Base__ const& x)
167 : token<C> (x)
171 NMTOKEN&
172 operator= (Base__ const& x)
174 static_cast<Base__&> (*this) = x;
175 return *this;
179 template <typename C>
180 class Name: public token<C>
182 protected:
183 typedef typename token<C>::Base__ Base__;
185 public:
186 Name() = default;
188 Name(XSCRT::XML::Element<C> const& e)
189 : token<C> (e)
193 Name(XSCRT::XML::Attribute<C> const& a)
194 : token<C> (a)
198 Name(Base__ const& x)
199 : token<C> (x)
203 Name&
204 operator= (Base__ const& x)
206 static_cast<Base__&> (*this) = x;
207 return *this;
212 template <typename C>
213 class NCName: public Name<C>
215 protected:
216 typedef typename Name<C>::Base__ Base__;
218 public:
219 NCName() = default;
221 NCName(XSCRT::XML::Element<C> const& e)
222 : Name<C> (e)
226 NCName(XSCRT::XML::Attribute<C> const& a)
227 : Name<C> (a)
231 NCName(Base__ const& x)
232 : Name<C> (x)
236 NCName&
237 operator= (Base__ const& x)
239 static_cast<Base__&> (*this) = x;
240 return *this;
244 template <typename C>
245 class QName: public Name<C>
247 protected:
248 typedef typename Name<C>::Base__ Base__;
250 public:
251 QName() = default;
253 QName(XSCRT::XML::Element<C> const& e)
254 : Name<C> (e)
258 QName(XSCRT::XML::Attribute<C> const& a)
259 : Name<C> (a)
263 QName(Base__ const& x)
264 : Name<C> (x)
268 QName&
269 operator= (Base__ const& x)
271 static_cast<Base__&> (*this) = x;
272 return *this;
276 template <typename C>
277 struct IdentityProvider : XSCRT::IdentityProvider
279 IdentityProvider (NCName<C> const& id)
280 : id_ (id)
284 virtual bool
285 before (XSCRT::IdentityProvider const& y) const
287 return id_ < dynamic_cast<IdentityProvider const&> (y).id_;
290 private:
291 NCName<C> const& id_;
293 private:
294 IdentityProvider (IdentityProvider const&);
296 IdentityProvider&
297 operator= (IdentityProvider const&);
301 template <typename C>
302 class ID : public NCName<C>
304 protected:
305 typedef typename NCName<C>::Base__ Base__;
307 public:
308 ~ID()
310 unregister_id ();
313 ID ()
314 : id_provider_ (*this)
318 ID (XSCRT::XML::Element<C> const& e)
319 : NCName<C> (e), id_provider_ (*this)
323 ID (XSCRT::XML::Attribute<C> const& a)
324 : NCName<C> (a), id_provider_ (*this)
328 ID (ID const& x)
329 : NCName<C> (x), id_provider_ (*this)
333 ID (Base__ const& x)
334 : NCName<C> (x), id_provider_ (*this)
339 operator= (Base__ const& x)
341 unregister_id ();
343 static_cast<NCName<C>&>(*this) = x;
345 register_id ();
347 return *this;
351 operator= (ID const& x)
353 unregister_id ();
355 static_cast<NCName<C>&>(*this) = static_cast<NCName<C> const&>(x);
357 register_id ();
359 return *this;
362 public:
363 using NCName<C>::container;
365 virtual void
366 container (XSCRT::Type* c)
368 unregister_id ();
370 NCName<C>::container (c);
372 register_id ();
375 private:
376 using NCName<C>::empty;
377 using NCName<C>::root;
379 void
380 register_id ()
382 if (container () != this && !empty ())
384 //std::wcerr << "registering " << container ()
385 // << " as '" << *this
386 // << "' on " << container () << std::endl;
387 container ()->register_id (id_provider_, container ());
391 void
392 unregister_id ()
394 if (container () != this && !empty ())
396 //std::wcerr << "un-registering " << container ()
397 // << " as '" << *this
398 // << "' on " << container () << std::endl;
399 container ()->unregister_id (id_provider_);
403 private:
404 IdentityProvider<C> id_provider_;
407 struct IDREF_Base : public XSCRT::Type
409 virtual XSCRT::Type*
410 get () const = 0;
413 template <typename C>
414 class IDREF : public IDREF_Base
416 public:
417 IDREF ()
418 : id_provider_ (id_)
422 IDREF (XSCRT::XML::Element<C> const& e)
423 : id_ (e), id_provider_ (id_)
427 IDREF (XSCRT::XML::Attribute<C> const& a)
428 : id_ (a), id_provider_ (id_)
432 IDREF (IDREF const& x)
433 : id_ (x.id_), id_provider_ (id_)
437 IDREF (basic_string<C> const& id)
438 : id_ (id), id_provider_ (id_)
442 IDREF&
443 operator= (IDREF const& x)
445 id_ = x.id_;
446 return *this;
449 IDREF&
450 operator= (basic_string<C> const& x)
452 id_ = x;
453 return *this;
456 public:
457 XSCRT::Type*
458 operator-> () const
460 return get ();
463 XSCRT::Type&
464 operator* () const
466 return *(get ());
469 virtual XSCRT::Type*
470 get () const
472 if (!id_.empty () && container () != this)
474 return root ()->lookup_id (id_provider_);
476 else
478 return 0;
482 // conversion to bool
484 typedef XSCRT::Type* (IDREF::*bool_convertable)() const;
486 operator bool_convertable () const
488 return get () ? &IDREF::operator-> : 0;
491 private:
492 NCName<C> id_;
493 IdentityProvider<C> id_provider_;
497 // Traversal
500 #include "ace/XML_Utils/XSCRT/Traversal.hpp"
502 namespace XMLSchema
504 namespace Traversal
506 template <typename T>
507 struct Traverser : XSCRT::Traversal::Traverser<T, XSCRT::Type>,
508 XSCRT::Traversal::Traverser<IDREF_Base, XSCRT::Type>
510 typedef
512 Type;
514 virtual void
515 traverse (XMLSchema::IDREF_Base& r)
517 if (r.get ()) dispatch (*(r.get ()));
521 typedef Traverser<byte> byte;
522 typedef Traverser<unsignedByte> unsignedByte;
524 typedef Traverser<short_> short_;
525 typedef Traverser<unsignedShort> unsignedShort;
527 typedef Traverser<int_> int_;
528 typedef Traverser<unsignedInt> unsignedInt;
530 typedef Traverser<long_> long_;
531 typedef Traverser<unsignedLong> unsignedLong;
533 typedef Traverser<boolean> boolean;
535 typedef Traverser<float_> float_;
536 typedef Traverser<double_> double_;
538 template <typename C>
539 struct string : Traverser<XMLSchema::string<C> >
543 template <typename C>
544 struct ID : Traverser<XMLSchema::ID<C> >
551 // ExtendedTypeInfo for XML Schema types
554 #include "ace/XML_Utils/XSCRT/ExtendedTypeInfo.hpp"
556 namespace XMLSchema
558 template <typename C>
559 struct TypeInfoInitializer
561 TypeInfoInitializer (XSCRT::ExtendedTypeInfoMap&);
565 #include "ace/XML_Utils/XSCRT/XMLSchema.ipp"
566 #include "ace/XML_Utils/XSCRT/XMLSchema.tpp"
568 #endif // XSCRT_XMLSCHEMA_HPP