1 // file : XSCRT/XMLSchema.hpp
2 // author : Boris Kolpackov <boris@dre.vanderbilt.edu>
3 #ifndef XSCRT_XMLSCHEMA_HPP
4 #define XSCRT_XMLSCHEMA_HPP
7 // #include <iostream> //@@ tmp
9 #include "ace/XML_Utils/XMLSchema/XSCRT/Elements.hpp"
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
;
46 class string
: public XSCRT::Type
, public basic_string
<C
>
49 typedef basic_string
<C
> Base__
;
52 //@@ VC6 does not inject XSCRT::Type into the scope so I have
53 // to qualify it all the time.
57 string (XSCRT::XML::Element
<C
> const& e
)
62 string (XSCRT::XML::Attribute
<C
> const& a
)
67 string (Base__
const& x
)
73 operator= (Base__
const& x
)
75 static_cast<Base__
&> (*this) = x
;
82 class normalizedString
: public string
<C
>
85 typedef typename string
<C
>::Base__ Base__
;
88 normalizedString () = default;
90 normalizedString (XSCRT::XML::Element
<C
> const& e
)
95 normalizedString (XSCRT::XML::Attribute
<C
> const& a
)
100 normalizedString (Base__
const& x
)
106 operator= (Base__
const& x
)
108 static_cast<Base__
&> (*this) = x
;
114 template <typename C
>
115 class token
: public normalizedString
<C
>
118 typedef typename normalizedString
<C
>::Base__ Base__
;
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
)
139 operator= (Base__
const& x
)
141 static_cast<Base__
&> (*this) = x
;
147 template <typename C
>
148 class NMTOKEN
: public token
<C
>
151 typedef typename token
<C
>::Base__ Base__
;
154 NMTOKEN () = default;
156 NMTOKEN (XSCRT::XML::Element
<C
> const& e
)
161 NMTOKEN (XSCRT::XML::Attribute
<C
> const& a
)
166 NMTOKEN (Base__
const& x
)
172 operator= (Base__
const& x
)
174 static_cast<Base__
&> (*this) = x
;
179 template <typename C
>
180 class Name
: public token
<C
>
183 typedef typename token
<C
>::Base__ Base__
;
188 Name(XSCRT::XML::Element
<C
> const& e
)
193 Name(XSCRT::XML::Attribute
<C
> const& a
)
198 Name(Base__
const& x
)
204 operator= (Base__
const& x
)
206 static_cast<Base__
&> (*this) = x
;
212 template <typename C
>
213 class NCName
: public Name
<C
>
216 typedef typename Name
<C
>::Base__ Base__
;
221 NCName(XSCRT::XML::Element
<C
> const& e
)
226 NCName(XSCRT::XML::Attribute
<C
> const& a
)
231 NCName(Base__
const& x
)
237 operator= (Base__
const& x
)
239 static_cast<Base__
&> (*this) = x
;
244 template <typename C
>
245 class QName
: public Name
<C
>
248 typedef typename Name
<C
>::Base__ Base__
;
253 QName(XSCRT::XML::Element
<C
> const& e
)
258 QName(XSCRT::XML::Attribute
<C
> const& a
)
263 QName(Base__
const& x
)
269 operator= (Base__
const& x
)
271 static_cast<Base__
&> (*this) = x
;
276 template <typename C
>
277 struct IdentityProvider
: XSCRT::IdentityProvider
279 IdentityProvider (NCName
<C
> const& id
)
285 before (XSCRT::IdentityProvider
const& y
) const
287 return id_
< dynamic_cast<IdentityProvider
const&> (y
).id_
;
291 NCName
<C
> const& id_
;
294 IdentityProvider (IdentityProvider
const&);
297 operator= (IdentityProvider
const&);
301 template <typename C
>
302 class ID
: public NCName
<C
>
305 typedef typename NCName
<C
>::Base__ Base__
;
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)
329 : NCName
<C
> (x
), id_provider_ (*this)
334 : NCName
<C
> (x
), id_provider_ (*this)
339 operator= (Base__
const& x
)
343 static_cast<NCName
<C
>&>(*this) = x
;
351 operator= (ID
const& x
)
355 static_cast<NCName
<C
>&>(*this) = static_cast<NCName
<C
> const&>(x
);
363 using NCName
<C
>::container
;
366 container (XSCRT::Type
* c
)
370 NCName
<C
>::container (c
);
376 using NCName
<C
>::empty
;
377 using NCName
<C
>::root
;
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 ());
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_
);
404 IdentityProvider
<C
> id_provider_
;
407 struct IDREF_Base
: public XSCRT::Type
413 template <typename C
>
414 class IDREF
: public IDREF_Base
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_
)
443 operator= (IDREF
const& x
)
450 operator= (basic_string
<C
> const& x
)
472 if (!id_
.empty () && container () != this)
474 return root ()->lookup_id (id_provider_
);
482 // conversion to bool
484 typedef XSCRT::Type
* (IDREF::*bool_convertable
)() const;
486 operator bool_convertable () const
488 return get () ? &IDREF::operator-> : 0;
493 IdentityProvider
<C
> id_provider_
;
500 #include "ace/XML_Utils/XSCRT/Traversal.hpp"
506 template <typename T
>
507 struct Traverser
: XSCRT::Traversal::Traverser
<T
, XSCRT::Type
>,
508 XSCRT::Traversal::Traverser
<IDREF_Base
, XSCRT::Type
>
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"
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