[111] | 1 | // file : xsd/cxx/tree/containers-wildcard.hxx |
---|
| 2 | // author : Boris Kolpackov <boris@codesynthesis.com> |
---|
| 3 | // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC |
---|
| 4 | // license : GNU GPL v2 + exceptions; see accompanying LICENSE file |
---|
| 5 | |
---|
| 6 | #ifndef XSD_CXX_TREE_CONTAINERS_WILDCARD_HXX |
---|
| 7 | #define XSD_CXX_TREE_CONTAINERS_WILDCARD_HXX |
---|
| 8 | |
---|
| 9 | #include <set> |
---|
| 10 | #include <string> |
---|
| 11 | |
---|
| 12 | #include <xercesc/dom/DOMAttr.hpp> |
---|
| 13 | #include <xercesc/dom/DOMElement.hpp> |
---|
| 14 | #include <xercesc/dom/DOMDocument.hpp> |
---|
| 15 | #include <xercesc/util/XMLString.hpp> |
---|
| 16 | |
---|
| 17 | #include <xsd/cxx/xml/string.hxx> |
---|
| 18 | |
---|
| 19 | #include <xsd/cxx/tree/containers.hxx> // iterator_adapter |
---|
| 20 | |
---|
| 21 | namespace xsd |
---|
| 22 | { |
---|
| 23 | namespace cxx |
---|
| 24 | { |
---|
| 25 | namespace tree |
---|
| 26 | { |
---|
| 27 | // one (for internal use only) |
---|
| 28 | // |
---|
| 29 | class element_one |
---|
| 30 | { |
---|
| 31 | public: |
---|
| 32 | ~element_one () |
---|
| 33 | { |
---|
| 34 | if (x_) |
---|
| 35 | x_->release (); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | explicit |
---|
| 39 | element_one (xercesc::DOMDocument& doc) |
---|
| 40 | : x_ (0), doc_ (doc) |
---|
| 41 | { |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | element_one (const xercesc::DOMElement& x, xercesc::DOMDocument& doc) |
---|
| 45 | : x_ (0), doc_ (doc) |
---|
| 46 | { |
---|
| 47 | set (x); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | element_one (const element_one& x, xercesc::DOMDocument& doc) |
---|
| 51 | : x_ (0), doc_ (doc) |
---|
| 52 | { |
---|
| 53 | if (x.present ()) |
---|
| 54 | set (x.get ()); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | element_one& |
---|
| 58 | operator= (const element_one& x) |
---|
| 59 | { |
---|
| 60 | if (this == &x) |
---|
| 61 | return *this; |
---|
| 62 | |
---|
| 63 | if (x.present ()) |
---|
| 64 | set (x.get ()); |
---|
| 65 | else if (x_) |
---|
| 66 | { |
---|
| 67 | x_->release (); |
---|
| 68 | x_ = 0; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | return *this; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | public: |
---|
| 75 | const xercesc::DOMElement& |
---|
| 76 | get () const |
---|
| 77 | { |
---|
| 78 | return *x_; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | xercesc::DOMElement& |
---|
| 82 | get () |
---|
| 83 | { |
---|
| 84 | return *x_; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void |
---|
| 88 | set (const xercesc::DOMElement& x) |
---|
| 89 | { |
---|
| 90 | using xercesc::DOMElement; |
---|
| 91 | |
---|
| 92 | DOMElement* r ( |
---|
| 93 | static_cast<DOMElement*> ( |
---|
| 94 | doc_.importNode (const_cast<DOMElement*> (&x), true))); |
---|
| 95 | |
---|
| 96 | if (x_) |
---|
| 97 | x_->release (); |
---|
| 98 | |
---|
| 99 | x_ = r; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void |
---|
| 103 | set (xercesc::DOMElement* x) |
---|
| 104 | { |
---|
| 105 | assert (x->getOwnerDocument () == &doc_); |
---|
| 106 | |
---|
| 107 | if (x_) |
---|
| 108 | x_->release (); |
---|
| 109 | |
---|
| 110 | x_ = x; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | bool |
---|
| 114 | present () const |
---|
| 115 | { |
---|
| 116 | return x_ != 0; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | protected: |
---|
| 120 | xercesc::DOMElement* x_; |
---|
| 121 | xercesc::DOMDocument& doc_; |
---|
| 122 | }; |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | // |
---|
| 126 | // |
---|
| 127 | class element_optional |
---|
| 128 | { |
---|
| 129 | public: |
---|
| 130 | ~element_optional () |
---|
| 131 | { |
---|
| 132 | if (x_) |
---|
| 133 | x_->release (); |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | explicit |
---|
| 137 | element_optional (xercesc::DOMDocument& doc) |
---|
| 138 | : x_ (0), doc_ (doc) |
---|
| 139 | { |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | element_optional (const xercesc::DOMElement& x, |
---|
| 143 | xercesc::DOMDocument& doc) |
---|
| 144 | : x_ (0), doc_ (doc) |
---|
| 145 | { |
---|
| 146 | set (x); |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | element_optional (xercesc::DOMElement* x, xercesc::DOMDocument& doc) |
---|
| 150 | : x_ (0), doc_ (doc) |
---|
| 151 | { |
---|
| 152 | set (x); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | element_optional (const element_optional& x, |
---|
| 156 | xercesc::DOMDocument& doc) |
---|
| 157 | : x_ (0), doc_ (doc) |
---|
| 158 | { |
---|
| 159 | if (x) |
---|
| 160 | set (*x); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | element_optional& |
---|
| 164 | operator= (const xercesc::DOMElement& x) |
---|
| 165 | { |
---|
| 166 | if (x_ == &x) |
---|
| 167 | return *this; |
---|
| 168 | |
---|
| 169 | set (x); |
---|
| 170 | |
---|
| 171 | return *this; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | element_optional& |
---|
| 175 | operator= (const element_optional& x) |
---|
| 176 | { |
---|
| 177 | if (this == &x) |
---|
| 178 | return *this; |
---|
| 179 | |
---|
| 180 | if (x) |
---|
| 181 | set (*x); |
---|
| 182 | else |
---|
| 183 | reset (); |
---|
| 184 | |
---|
| 185 | return *this; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | // Pointer-like interface. |
---|
| 189 | // |
---|
| 190 | public: |
---|
| 191 | const xercesc::DOMElement* |
---|
| 192 | operator-> () const |
---|
| 193 | { |
---|
| 194 | return x_; |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | xercesc::DOMElement* |
---|
| 198 | operator-> () |
---|
| 199 | { |
---|
| 200 | return x_; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | const xercesc::DOMElement& |
---|
| 204 | operator* () const |
---|
| 205 | { |
---|
| 206 | return *x_; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | xercesc::DOMElement& |
---|
| 210 | operator* () |
---|
| 211 | { |
---|
| 212 | return *x_; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | typedef void (element_optional::*bool_convertible) (); |
---|
| 216 | |
---|
| 217 | operator bool_convertible () const |
---|
| 218 | { |
---|
| 219 | return x_ != 0 ? &element_optional::true_ : 0; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | // Get/set interface. |
---|
| 223 | // |
---|
| 224 | public: |
---|
| 225 | bool |
---|
| 226 | present () const |
---|
| 227 | { |
---|
| 228 | return x_ != 0; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | const xercesc::DOMElement& |
---|
| 232 | get () const |
---|
| 233 | { |
---|
| 234 | return *x_; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | xercesc::DOMElement& |
---|
| 238 | get () |
---|
| 239 | { |
---|
| 240 | return *x_; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | void |
---|
| 244 | set (const xercesc::DOMElement& x) |
---|
| 245 | { |
---|
| 246 | using xercesc::DOMElement; |
---|
| 247 | |
---|
| 248 | DOMElement* r ( |
---|
| 249 | static_cast<DOMElement*> ( |
---|
| 250 | doc_.importNode (const_cast<DOMElement*> (&x), true))); |
---|
| 251 | |
---|
| 252 | if (x_) |
---|
| 253 | x_->release (); |
---|
| 254 | |
---|
| 255 | x_ = r; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | void |
---|
| 259 | set (xercesc::DOMElement* x) |
---|
| 260 | { |
---|
| 261 | assert (x->getOwnerDocument () == &doc_); |
---|
| 262 | |
---|
| 263 | if (x_) |
---|
| 264 | x_->release (); |
---|
| 265 | |
---|
| 266 | x_ = x; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | void |
---|
| 270 | reset () |
---|
| 271 | { |
---|
| 272 | if (x_) |
---|
| 273 | x_->release (); |
---|
| 274 | |
---|
| 275 | x_ = 0; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | private: |
---|
| 279 | void |
---|
| 280 | true_ () |
---|
| 281 | { |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | private: |
---|
| 285 | xercesc::DOMElement* x_; |
---|
| 286 | xercesc::DOMDocument& doc_; |
---|
| 287 | }; |
---|
| 288 | |
---|
| 289 | // Comparison operators. |
---|
| 290 | // |
---|
| 291 | |
---|
| 292 | inline bool |
---|
| 293 | operator== (const element_optional& a, const element_optional& b) |
---|
| 294 | { |
---|
| 295 | return !a || !b |
---|
| 296 | ? a.present () == b.present () |
---|
| 297 | : a->isEqualNode (&b.get ()); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | inline bool |
---|
| 301 | operator!= (const element_optional& a, const element_optional& b) |
---|
| 302 | { |
---|
| 303 | return !(a == b); |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | |
---|
| 307 | // |
---|
| 308 | // |
---|
| 309 | class element_sequence |
---|
| 310 | { |
---|
| 311 | protected: |
---|
| 312 | // This is a dangerously destructive automatic pointer. We are going |
---|
| 313 | // to use it in a controlled environment to save us a lot of coding. |
---|
| 314 | // |
---|
| 315 | struct ptr |
---|
| 316 | { |
---|
| 317 | ~ptr () |
---|
| 318 | { |
---|
| 319 | if (x_) |
---|
| 320 | x_->release (); |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | explicit |
---|
| 324 | ptr (xercesc::DOMElement* x = 0) |
---|
| 325 | : x_ (x) |
---|
| 326 | { |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | ptr (const ptr& y) |
---|
| 330 | : x_ (y.x_) |
---|
| 331 | { |
---|
| 332 | // Yes, hostile takeover. |
---|
| 333 | // |
---|
| 334 | y.x_ = 0; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | ptr& |
---|
| 338 | operator= (const ptr& y) |
---|
| 339 | { |
---|
| 340 | if (this != &y) |
---|
| 341 | { |
---|
| 342 | // Yes, hostile takeover. |
---|
| 343 | // |
---|
| 344 | if (x_) |
---|
| 345 | x_->release (); |
---|
| 346 | |
---|
| 347 | x_ = y.x_; |
---|
| 348 | y.x_ = 0; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | return *this; |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | public: |
---|
| 355 | xercesc::DOMElement& |
---|
| 356 | operator* () const |
---|
| 357 | { |
---|
| 358 | return *x_; |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | xercesc::DOMElement* |
---|
| 362 | get () const |
---|
| 363 | { |
---|
| 364 | return x_; |
---|
| 365 | } |
---|
| 366 | |
---|
| 367 | private: |
---|
| 368 | mutable xercesc::DOMElement* x_; |
---|
| 369 | }; |
---|
| 370 | |
---|
| 371 | typedef std::vector<ptr> base_sequence; |
---|
| 372 | typedef base_sequence::iterator base_iterator; |
---|
| 373 | typedef base_sequence::const_iterator base_const_iterator; |
---|
| 374 | |
---|
| 375 | public: |
---|
| 376 | typedef xercesc::DOMElement value_type; |
---|
| 377 | typedef xercesc::DOMElement* pointer; |
---|
| 378 | typedef const xercesc::DOMElement* const_pointer; |
---|
| 379 | typedef xercesc::DOMElement& reference; |
---|
| 380 | typedef const xercesc::DOMElement& const_reference; |
---|
| 381 | |
---|
| 382 | typedef |
---|
| 383 | iterator_adapter<base_sequence::iterator, xercesc::DOMElement> |
---|
| 384 | iterator; |
---|
| 385 | |
---|
| 386 | typedef |
---|
| 387 | iterator_adapter<base_sequence::const_iterator, |
---|
| 388 | const xercesc::DOMElement> |
---|
| 389 | const_iterator; |
---|
| 390 | |
---|
| 391 | typedef |
---|
| 392 | iterator_adapter<base_sequence::reverse_iterator, xercesc::DOMElement> |
---|
| 393 | reverse_iterator; |
---|
| 394 | |
---|
| 395 | typedef |
---|
| 396 | iterator_adapter<base_sequence::const_reverse_iterator, |
---|
| 397 | const xercesc::DOMElement> |
---|
| 398 | const_reverse_iterator; |
---|
| 399 | |
---|
| 400 | typedef base_sequence::size_type size_type; |
---|
| 401 | typedef base_sequence::difference_type difference_type; |
---|
| 402 | typedef base_sequence::allocator_type allocator_type; |
---|
| 403 | |
---|
| 404 | public: |
---|
| 405 | explicit |
---|
| 406 | element_sequence (xercesc::DOMDocument& doc) |
---|
| 407 | : doc_ (doc) |
---|
| 408 | { |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | // DOMElement cannot be default-constructed. |
---|
| 412 | // |
---|
| 413 | // explicit |
---|
| 414 | // element_sequence (size_type n); |
---|
| 415 | |
---|
| 416 | element_sequence (size_type n, |
---|
| 417 | const xercesc::DOMElement& x, |
---|
| 418 | xercesc::DOMDocument& doc) |
---|
| 419 | : doc_ (doc) |
---|
| 420 | { |
---|
| 421 | assign (n, x); |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | template <typename I> |
---|
| 425 | element_sequence (const I& begin, const I& end, |
---|
| 426 | xercesc::DOMDocument& doc) |
---|
| 427 | : doc_ (doc) |
---|
| 428 | { |
---|
| 429 | assign (begin, end); |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | element_sequence (const element_sequence& v, |
---|
| 433 | xercesc::DOMDocument& doc) |
---|
| 434 | : doc_ (doc) |
---|
| 435 | { |
---|
| 436 | v_.reserve (v.v_.size ()); |
---|
| 437 | |
---|
| 438 | for (base_const_iterator i (v.v_.begin ()), e (v.v_.end ()); |
---|
| 439 | i != e; ++i) |
---|
| 440 | { |
---|
| 441 | ptr p (static_cast<xercesc::DOMElement*> ( |
---|
| 442 | doc_.importNode (i->get (), true))); |
---|
| 443 | |
---|
| 444 | v_.push_back (p); |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | |
---|
| 448 | element_sequence& |
---|
| 449 | operator= (const element_sequence& v) |
---|
| 450 | { |
---|
| 451 | if (this == &v) |
---|
| 452 | return *this; |
---|
| 453 | |
---|
| 454 | v_.assign (v.v_.size (), ptr ()); |
---|
| 455 | |
---|
| 456 | base_iterator di (v_.begin ()), de (v_.end ()); |
---|
| 457 | base_const_iterator si (v.v_.begin ()), se (v.v_.end ()); |
---|
| 458 | |
---|
| 459 | for (; si != se && di != de; ++si, ++di) |
---|
| 460 | { |
---|
| 461 | ptr p (static_cast<xercesc::DOMElement*> ( |
---|
| 462 | doc_.importNode (si->get (), true))); |
---|
| 463 | *di = p; |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | return *this; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | public: |
---|
| 470 | void |
---|
| 471 | assign (size_type n, const xercesc::DOMElement& x) |
---|
| 472 | { |
---|
| 473 | v_.assign (n, ptr ()); |
---|
| 474 | |
---|
| 475 | for (base_iterator i (v_.begin ()), e (v_.end ()); i != e; ++i) |
---|
| 476 | { |
---|
| 477 | ptr p (static_cast<xercesc::DOMElement*> ( |
---|
| 478 | doc_.importNode ( |
---|
| 479 | const_cast<xercesc::DOMElement*> (&x), true))); |
---|
| 480 | *i = p; |
---|
| 481 | } |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | template <typename I> |
---|
| 485 | void |
---|
| 486 | assign (const I& begin, const I& end) |
---|
| 487 | { |
---|
| 488 | // This is not the fastest way to do it. |
---|
| 489 | // |
---|
| 490 | v_.clear (); |
---|
| 491 | |
---|
| 492 | for (I i (begin); i != end; ++i) |
---|
| 493 | { |
---|
| 494 | ptr p (static_cast<xercesc::DOMElement*> ( |
---|
| 495 | doc_.importNode ( |
---|
| 496 | const_cast<xercesc::DOMElement*> (&(*i)), true))); |
---|
| 497 | v_.push_back (p); |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | public: |
---|
| 502 | // This version of resize can only be used to shrink the |
---|
| 503 | // sequence because DOMElement cannot be default-constructed. |
---|
| 504 | // |
---|
| 505 | void |
---|
| 506 | resize (size_type n) |
---|
| 507 | { |
---|
| 508 | assert (n <= v_.size ()); |
---|
| 509 | v_.resize (n, ptr ()); |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | void |
---|
| 513 | resize (size_type n, const xercesc::DOMElement& x) |
---|
| 514 | { |
---|
| 515 | size_type old (v_.size ()); |
---|
| 516 | v_.resize (n, ptr ()); |
---|
| 517 | |
---|
| 518 | if (old < n) |
---|
| 519 | { |
---|
| 520 | for (base_iterator i (v_.begin () + old), e (v_.end ()); |
---|
| 521 | i != e; ++i) |
---|
| 522 | { |
---|
| 523 | ptr p (static_cast<xercesc::DOMElement*> ( |
---|
| 524 | doc_.importNode ( |
---|
| 525 | const_cast<xercesc::DOMElement*> (&x), true))); |
---|
| 526 | *i = p; |
---|
| 527 | } |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | public: |
---|
| 532 | size_type |
---|
| 533 | size () const |
---|
| 534 | { |
---|
| 535 | return v_.size (); |
---|
| 536 | } |
---|
| 537 | |
---|
| 538 | size_type |
---|
| 539 | max_size () const |
---|
| 540 | { |
---|
| 541 | return v_.max_size (); |
---|
| 542 | } |
---|
| 543 | |
---|
| 544 | size_type |
---|
| 545 | capacity () const |
---|
| 546 | { |
---|
| 547 | return v_.capacity (); |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | bool |
---|
| 551 | empty () const |
---|
| 552 | { |
---|
| 553 | return v_.empty (); |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | void |
---|
| 557 | reserve (size_type n) |
---|
| 558 | { |
---|
| 559 | v_.reserve (n); |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | void |
---|
| 563 | clear () |
---|
| 564 | { |
---|
| 565 | v_.clear (); |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | public: |
---|
| 569 | const_iterator |
---|
| 570 | begin () const |
---|
| 571 | { |
---|
| 572 | return const_iterator (v_.begin ()); |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | const_iterator |
---|
| 576 | end () const |
---|
| 577 | { |
---|
| 578 | return const_iterator (v_.end ()); |
---|
| 579 | } |
---|
| 580 | |
---|
| 581 | iterator |
---|
| 582 | begin () |
---|
| 583 | { |
---|
| 584 | return iterator (v_.begin ()); |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | iterator |
---|
| 588 | end () |
---|
| 589 | { |
---|
| 590 | return iterator (v_.end ()); |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | // reverse |
---|
| 594 | // |
---|
| 595 | |
---|
| 596 | const_reverse_iterator |
---|
| 597 | rbegin () const |
---|
| 598 | { |
---|
| 599 | return const_reverse_iterator (v_.rbegin ()); |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | const_reverse_iterator |
---|
| 603 | rend () const |
---|
| 604 | { |
---|
| 605 | return const_reverse_iterator (v_.rend ()); |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | reverse_iterator |
---|
| 609 | rbegin () |
---|
| 610 | { |
---|
| 611 | return reverse_iterator (v_.rbegin ()); |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | reverse_iterator |
---|
| 615 | rend () |
---|
| 616 | { |
---|
| 617 | return reverse_iterator (v_.rend ()); |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | public: |
---|
| 621 | xercesc::DOMElement& |
---|
| 622 | operator[] (size_type n) |
---|
| 623 | { |
---|
| 624 | return *(v_[n]); |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | const xercesc::DOMElement& |
---|
| 628 | operator[] (size_type n) const |
---|
| 629 | { |
---|
| 630 | return *(v_[n]); |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | xercesc::DOMElement& |
---|
| 634 | at (size_type n) |
---|
| 635 | { |
---|
| 636 | return *(v_.at (n)); |
---|
| 637 | } |
---|
| 638 | |
---|
| 639 | const xercesc::DOMElement& |
---|
| 640 | at (size_type n) const |
---|
| 641 | { |
---|
| 642 | return *(v_.at (n)); |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | xercesc::DOMElement& |
---|
| 646 | front () |
---|
| 647 | { |
---|
| 648 | return *(v_.front ()); |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | const xercesc::DOMElement& |
---|
| 652 | front () const |
---|
| 653 | { |
---|
| 654 | return *(v_.front ()); |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | xercesc::DOMElement& |
---|
| 658 | back () |
---|
| 659 | { |
---|
| 660 | return *(v_.back ()); |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | const xercesc::DOMElement& |
---|
| 664 | back () const |
---|
| 665 | { |
---|
| 666 | return *(v_.back ()); |
---|
| 667 | } |
---|
| 668 | |
---|
| 669 | public: |
---|
| 670 | // Makes a deep copy. |
---|
| 671 | // |
---|
| 672 | void |
---|
| 673 | push_back (const xercesc::DOMElement& x) |
---|
| 674 | { |
---|
| 675 | ptr p (static_cast<xercesc::DOMElement*> ( |
---|
| 676 | doc_.importNode ( |
---|
| 677 | const_cast<xercesc::DOMElement*> (&x), true))); |
---|
| 678 | |
---|
| 679 | v_.push_back (p); |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | // Assumes ownership. |
---|
| 683 | // |
---|
| 684 | void |
---|
| 685 | push_back (xercesc::DOMElement* x) |
---|
| 686 | { |
---|
| 687 | assert (x->getOwnerDocument () == &doc_); |
---|
| 688 | v_.push_back (ptr (x)); |
---|
| 689 | } |
---|
| 690 | |
---|
| 691 | void |
---|
| 692 | pop_back () |
---|
| 693 | { |
---|
| 694 | v_.pop_back (); |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | // Makes a deep copy. |
---|
| 698 | // |
---|
| 699 | iterator |
---|
| 700 | insert (iterator position, const xercesc::DOMElement& x) |
---|
| 701 | { |
---|
| 702 | ptr p (static_cast<xercesc::DOMElement*> ( |
---|
| 703 | doc_.importNode ( |
---|
| 704 | const_cast<xercesc::DOMElement*> (&x), true))); |
---|
| 705 | |
---|
| 706 | return iterator (v_.insert (position.base (), p)); |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | // Assumes ownership. |
---|
| 710 | // |
---|
| 711 | iterator |
---|
| 712 | insert (iterator position, xercesc::DOMElement* x) |
---|
| 713 | { |
---|
| 714 | assert (x->getOwnerDocument () == &doc_); |
---|
| 715 | return iterator (v_.insert (position.base (), ptr (x))); |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | void |
---|
| 719 | insert (iterator position, size_type n, const xercesc::DOMElement& x) |
---|
| 720 | { |
---|
| 721 | difference_type d (v_.end () - position.base ()); |
---|
| 722 | v_.insert (position.base (), n, ptr ()); |
---|
| 723 | |
---|
| 724 | for (base_iterator i (v_.end () - d); n != 0; --n) |
---|
| 725 | { |
---|
| 726 | ptr r (static_cast<xercesc::DOMElement*> ( |
---|
| 727 | doc_.importNode ( |
---|
| 728 | const_cast<xercesc::DOMElement*> (&x), true))); |
---|
| 729 | *(--i) = r; |
---|
| 730 | } |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | template <typename I> |
---|
| 734 | void |
---|
| 735 | insert (iterator position, const I& begin, const I& end) |
---|
| 736 | { |
---|
| 737 | // This is not the fastest way to do it. |
---|
| 738 | // |
---|
| 739 | if (begin != end) |
---|
| 740 | { |
---|
| 741 | base_iterator p (position.base ()); |
---|
| 742 | |
---|
| 743 | for (I i (end);;) |
---|
| 744 | { |
---|
| 745 | --i; |
---|
| 746 | ptr r (static_cast<xercesc::DOMElement*> ( |
---|
| 747 | doc_.importNode (i->get (), true))); |
---|
| 748 | |
---|
| 749 | p = v_.insert (p, r); |
---|
| 750 | |
---|
| 751 | if (i == begin) |
---|
| 752 | break; |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | } |
---|
| 756 | |
---|
| 757 | iterator |
---|
| 758 | erase (iterator position) |
---|
| 759 | { |
---|
| 760 | return iterator (v_.erase (position.base ())); |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | iterator |
---|
| 764 | erase (iterator begin, iterator end) |
---|
| 765 | { |
---|
| 766 | return iterator (v_.erase (begin.base (), end.base ())); |
---|
| 767 | } |
---|
| 768 | |
---|
| 769 | public: |
---|
| 770 | // Note that the DOMDocument object of the two sequences being |
---|
| 771 | // swapped should be the same. |
---|
| 772 | // |
---|
| 773 | void |
---|
| 774 | swap (element_sequence& x) |
---|
| 775 | { |
---|
| 776 | assert (&doc_ == &x.doc_); |
---|
| 777 | v_.swap (x.v_); |
---|
| 778 | } |
---|
| 779 | |
---|
| 780 | private: |
---|
| 781 | base_sequence v_; |
---|
| 782 | xercesc::DOMDocument& doc_; |
---|
| 783 | }; |
---|
| 784 | |
---|
| 785 | // Comparison operators. |
---|
| 786 | // |
---|
| 787 | |
---|
| 788 | inline bool |
---|
| 789 | operator== (const element_sequence& a, const element_sequence& b) |
---|
| 790 | { |
---|
| 791 | if (a.size () != b.size ()) |
---|
| 792 | return false; |
---|
| 793 | |
---|
| 794 | element_sequence::const_iterator |
---|
| 795 | ai (a.begin ()), ae (a.end ()), bi (b.begin ()); |
---|
| 796 | |
---|
| 797 | for (; ai != ae; ++ai, ++bi) |
---|
| 798 | if (!ai->isEqualNode (&(*bi))) |
---|
| 799 | return false; |
---|
| 800 | |
---|
| 801 | return true; |
---|
| 802 | } |
---|
| 803 | |
---|
| 804 | inline bool |
---|
| 805 | operator!= (const element_sequence& a, const element_sequence& b) |
---|
| 806 | { |
---|
| 807 | return !(a == b); |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | |
---|
| 811 | // Attribute set. |
---|
| 812 | // |
---|
| 813 | |
---|
| 814 | class attribute_set_common |
---|
| 815 | { |
---|
| 816 | protected: |
---|
| 817 | // Set entry. It can either act as a dangerously destructive |
---|
| 818 | // automatic pointer for DOMAttr or as an entry containing the |
---|
| 819 | // name we are searching for. |
---|
| 820 | // |
---|
| 821 | struct entry |
---|
| 822 | { |
---|
| 823 | ~entry () |
---|
| 824 | { |
---|
| 825 | if (a_) |
---|
| 826 | a_->release (); |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | explicit |
---|
| 830 | entry (xercesc::DOMAttr* a) |
---|
| 831 | : a_ (a), ns_ (0), name_ (0) |
---|
| 832 | { |
---|
| 833 | ns_ = a->getNamespaceURI (); |
---|
| 834 | name_ = ns_ == 0 ? a->getName () : a->getLocalName (); |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | // Note: uses shallow copy. |
---|
| 838 | // |
---|
| 839 | explicit |
---|
| 840 | entry (const XMLCh* ns, const XMLCh* name) |
---|
| 841 | : a_ (0), ns_ (ns), name_ (name) |
---|
| 842 | { |
---|
| 843 | } |
---|
| 844 | |
---|
| 845 | entry (const entry& y) |
---|
| 846 | : a_ (y.a_), ns_ (y.ns_), name_ (y.name_) |
---|
| 847 | { |
---|
| 848 | // Yes, hostile takeover. |
---|
| 849 | // |
---|
| 850 | y.a_ = 0; |
---|
| 851 | y.ns_ = 0; |
---|
| 852 | y.name_ = 0; |
---|
| 853 | } |
---|
| 854 | |
---|
| 855 | entry& |
---|
| 856 | operator= (const entry& y) |
---|
| 857 | { |
---|
| 858 | if (this != &y) |
---|
| 859 | { |
---|
| 860 | // Yes, hostile takeover. |
---|
| 861 | // |
---|
| 862 | if (a_) |
---|
| 863 | a_->release (); |
---|
| 864 | |
---|
| 865 | a_ = y.a_; |
---|
| 866 | ns_ = y.ns_; |
---|
| 867 | name_ = y.name_; |
---|
| 868 | |
---|
| 869 | y.a_ = 0; |
---|
| 870 | y.ns_ = 0; |
---|
| 871 | y.name_ = 0; |
---|
| 872 | } |
---|
| 873 | |
---|
| 874 | return *this; |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | public: |
---|
| 878 | xercesc::DOMAttr& |
---|
| 879 | operator* () const |
---|
| 880 | { |
---|
| 881 | return *a_; |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | xercesc::DOMAttr* |
---|
| 885 | get () const |
---|
| 886 | { |
---|
| 887 | return a_; |
---|
| 888 | } |
---|
| 889 | |
---|
| 890 | const XMLCh* |
---|
| 891 | ns () const |
---|
| 892 | { |
---|
| 893 | return ns_; |
---|
| 894 | } |
---|
| 895 | |
---|
| 896 | const XMLCh* |
---|
| 897 | name () const |
---|
| 898 | { |
---|
| 899 | return name_; |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | void |
---|
| 903 | release () |
---|
| 904 | { |
---|
| 905 | a_ = 0; |
---|
| 906 | } |
---|
| 907 | |
---|
| 908 | private: |
---|
| 909 | mutable xercesc::DOMAttr* a_; |
---|
| 910 | mutable const XMLCh* ns_; |
---|
| 911 | mutable const XMLCh* name_; |
---|
| 912 | }; |
---|
| 913 | |
---|
| 914 | struct entry_cmp |
---|
| 915 | { |
---|
| 916 | bool |
---|
| 917 | operator() (const entry& a, const entry& b) const |
---|
| 918 | { |
---|
| 919 | using xercesc::XMLString; |
---|
| 920 | |
---|
| 921 | const XMLCh* ans (a.ns ()); |
---|
| 922 | const XMLCh* bns (b.ns ()); |
---|
| 923 | |
---|
| 924 | const XMLCh* an (a.name ()); |
---|
| 925 | const XMLCh* bn (b.name ()); |
---|
| 926 | |
---|
| 927 | if (ans == 0) |
---|
| 928 | return bns != 0 |
---|
| 929 | ? true |
---|
| 930 | : (XMLString::compareString (an, bn) < 0); |
---|
| 931 | |
---|
| 932 | if (ans != 0 && bns == 0) |
---|
| 933 | return false; |
---|
| 934 | |
---|
| 935 | int r (XMLString::compareString (ans, bns)); |
---|
| 936 | |
---|
| 937 | return r < 0 |
---|
| 938 | ? true |
---|
| 939 | : (r > 0 ? false : XMLString::compareString (an, bn)); |
---|
| 940 | } |
---|
| 941 | }; |
---|
| 942 | |
---|
| 943 | typedef std::set<entry, entry_cmp> base_set; |
---|
| 944 | typedef base_set::iterator base_iterator; |
---|
| 945 | typedef base_set::const_iterator base_const_iterator; |
---|
| 946 | }; |
---|
| 947 | |
---|
| 948 | template <typename C> |
---|
| 949 | class attribute_set: public attribute_set_common |
---|
| 950 | { |
---|
| 951 | public: |
---|
| 952 | typedef xercesc::DOMAttr key_type; |
---|
| 953 | typedef xercesc::DOMAttr value_type; |
---|
| 954 | typedef xercesc::DOMAttr* pointer; |
---|
| 955 | typedef const xercesc::DOMAttr* const_pointer; |
---|
| 956 | typedef xercesc::DOMAttr& reference; |
---|
| 957 | typedef const xercesc::DOMAttr& const_reference; |
---|
| 958 | |
---|
| 959 | typedef |
---|
| 960 | iterator_adapter<base_set::iterator, xercesc::DOMAttr> |
---|
| 961 | iterator; |
---|
| 962 | |
---|
| 963 | typedef |
---|
| 964 | iterator_adapter<base_set::const_iterator, const xercesc::DOMAttr> |
---|
| 965 | const_iterator; |
---|
| 966 | |
---|
| 967 | typedef |
---|
| 968 | iterator_adapter<base_set::reverse_iterator, xercesc::DOMAttr> |
---|
| 969 | reverse_iterator; |
---|
| 970 | |
---|
| 971 | typedef |
---|
| 972 | iterator_adapter<base_set::const_reverse_iterator, |
---|
| 973 | const xercesc::DOMAttr> |
---|
| 974 | const_reverse_iterator; |
---|
| 975 | |
---|
| 976 | typedef base_set::size_type size_type; |
---|
| 977 | typedef base_set::difference_type difference_type; |
---|
| 978 | typedef base_set::allocator_type allocator_type; |
---|
| 979 | |
---|
| 980 | public: |
---|
| 981 | attribute_set (xercesc::DOMDocument& doc) |
---|
| 982 | : doc_ (doc) |
---|
| 983 | { |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | template <typename I> |
---|
| 987 | attribute_set (const I& begin, |
---|
| 988 | const I& end, |
---|
| 989 | xercesc::DOMDocument& doc) |
---|
| 990 | : doc_ (doc) |
---|
| 991 | { |
---|
| 992 | insert (begin, end); |
---|
| 993 | } |
---|
| 994 | |
---|
| 995 | attribute_set (const attribute_set& s, xercesc::DOMDocument& doc) |
---|
| 996 | : doc_ (doc) |
---|
| 997 | { |
---|
| 998 | // Can be done faster with the "hinted" insert. |
---|
| 999 | // |
---|
| 1000 | insert (s.begin (), s.end ()); |
---|
| 1001 | } |
---|
| 1002 | |
---|
| 1003 | attribute_set& |
---|
| 1004 | operator= (const attribute_set& s) |
---|
| 1005 | { |
---|
| 1006 | if (this == &s) |
---|
| 1007 | return *this; |
---|
| 1008 | |
---|
| 1009 | // Can be done faster with the "hinted" insert. |
---|
| 1010 | // |
---|
| 1011 | clear (); |
---|
| 1012 | insert (s.begin (), s.end ()); |
---|
| 1013 | |
---|
| 1014 | return *this; |
---|
| 1015 | } |
---|
| 1016 | |
---|
| 1017 | public: |
---|
| 1018 | const_iterator |
---|
| 1019 | begin () const |
---|
| 1020 | { |
---|
| 1021 | return const_iterator (s_.begin ()); |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | const_iterator |
---|
| 1025 | end () const |
---|
| 1026 | { |
---|
| 1027 | return const_iterator (s_.end ()); |
---|
| 1028 | } |
---|
| 1029 | |
---|
| 1030 | iterator |
---|
| 1031 | begin () |
---|
| 1032 | { |
---|
| 1033 | return iterator (s_.begin ()); |
---|
| 1034 | } |
---|
| 1035 | |
---|
| 1036 | iterator |
---|
| 1037 | end () |
---|
| 1038 | { |
---|
| 1039 | return iterator (s_.end ()); |
---|
| 1040 | } |
---|
| 1041 | |
---|
| 1042 | // reverse |
---|
| 1043 | // |
---|
| 1044 | |
---|
| 1045 | const_reverse_iterator |
---|
| 1046 | rbegin () const |
---|
| 1047 | { |
---|
| 1048 | return const_reverse_iterator (s_.rbegin ()); |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | const_reverse_iterator |
---|
| 1052 | rend () const |
---|
| 1053 | { |
---|
| 1054 | return const_reverse_iterator (s_.rend ()); |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | reverse_iterator |
---|
| 1058 | rbegin () |
---|
| 1059 | { |
---|
| 1060 | return reverse_iterator (s_.rbegin ()); |
---|
| 1061 | } |
---|
| 1062 | |
---|
| 1063 | reverse_iterator |
---|
| 1064 | rend () |
---|
| 1065 | { |
---|
| 1066 | return reverse_iterator (s_.rend ()); |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | public: |
---|
| 1070 | size_type |
---|
| 1071 | size () const |
---|
| 1072 | { |
---|
| 1073 | return s_.size (); |
---|
| 1074 | } |
---|
| 1075 | |
---|
| 1076 | size_type |
---|
| 1077 | max_size () const |
---|
| 1078 | { |
---|
| 1079 | return s_.max_size (); |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | bool |
---|
| 1083 | empty () const |
---|
| 1084 | { |
---|
| 1085 | return s_.empty (); |
---|
| 1086 | } |
---|
| 1087 | |
---|
| 1088 | void |
---|
| 1089 | clear () |
---|
| 1090 | { |
---|
| 1091 | s_.clear (); |
---|
| 1092 | } |
---|
| 1093 | |
---|
| 1094 | public: |
---|
| 1095 | // Makes a deep copy. |
---|
| 1096 | // |
---|
| 1097 | std::pair<iterator, bool> |
---|
| 1098 | insert (const xercesc::DOMAttr& a) |
---|
| 1099 | { |
---|
| 1100 | entry e (static_cast<xercesc::DOMAttr*> ( |
---|
| 1101 | doc_.importNode ( |
---|
| 1102 | const_cast<xercesc::DOMAttr*> (&a), true))); |
---|
| 1103 | |
---|
| 1104 | std::pair<base_iterator, bool> r (s_.insert (e)); |
---|
| 1105 | |
---|
| 1106 | return std::pair<iterator, bool> (iterator (r.first), r.second); |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | // Assumes ownership. |
---|
| 1110 | // |
---|
| 1111 | std::pair<iterator, bool> |
---|
| 1112 | insert (xercesc::DOMAttr* a) |
---|
| 1113 | { |
---|
| 1114 | assert (a->getOwnerDocument () == &doc_); |
---|
| 1115 | entry e (a); |
---|
| 1116 | std::pair<base_iterator, bool> r (s_.insert (e)); |
---|
| 1117 | |
---|
| 1118 | if (!r.second) |
---|
| 1119 | e.release (); // Detach the attribute of insert failed. |
---|
| 1120 | |
---|
| 1121 | return std::pair<iterator, bool> (iterator (r.first), r.second); |
---|
| 1122 | } |
---|
| 1123 | |
---|
| 1124 | // Makes a deep copy. |
---|
| 1125 | // |
---|
| 1126 | iterator |
---|
| 1127 | insert (iterator position, const xercesc::DOMAttr& a) |
---|
| 1128 | { |
---|
| 1129 | entry e (static_cast<xercesc::DOMAttr*> ( |
---|
| 1130 | doc_.importNode ( |
---|
| 1131 | const_cast<xercesc::DOMAttr*> (&a), true))); |
---|
| 1132 | |
---|
| 1133 | return iterator (s_.insert (position.base (), e)); |
---|
| 1134 | } |
---|
| 1135 | |
---|
| 1136 | // Assumes ownership. |
---|
| 1137 | // |
---|
| 1138 | iterator |
---|
| 1139 | insert (iterator position, xercesc::DOMAttr* a) |
---|
| 1140 | { |
---|
| 1141 | assert (a->getOwnerDocument () == &doc_); |
---|
| 1142 | entry e (a); |
---|
| 1143 | base_iterator r (s_.insert (position.base (), e)); |
---|
| 1144 | |
---|
| 1145 | if (r->get () != a) |
---|
| 1146 | e.release (); // Detach the attribute of insert failed. |
---|
| 1147 | |
---|
| 1148 | return iterator (r); |
---|
| 1149 | } |
---|
| 1150 | |
---|
| 1151 | template <typename I> |
---|
| 1152 | void |
---|
| 1153 | insert (const I& begin, const I& end) |
---|
| 1154 | { |
---|
| 1155 | for (I i (begin); i != end; ++i) |
---|
| 1156 | { |
---|
| 1157 | entry e (static_cast<xercesc::DOMAttr*> ( |
---|
| 1158 | doc_.importNode ( |
---|
| 1159 | const_cast<xercesc::DOMAttr*> (&(*i)), true))); |
---|
| 1160 | |
---|
| 1161 | s_.insert (e); |
---|
| 1162 | } |
---|
| 1163 | } |
---|
| 1164 | |
---|
| 1165 | public: |
---|
| 1166 | void |
---|
| 1167 | erase (iterator position) |
---|
| 1168 | { |
---|
| 1169 | s_.erase (position.base ()); |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | size_type |
---|
| 1173 | erase (const std::basic_string<C>& name) |
---|
| 1174 | { |
---|
| 1175 | return s_.erase (entry (0, xml::string (name).c_str ())); |
---|
| 1176 | } |
---|
| 1177 | |
---|
| 1178 | size_type |
---|
| 1179 | erase (const std::basic_string<C>& namespace_, |
---|
| 1180 | const std::basic_string<C>& name) |
---|
| 1181 | { |
---|
| 1182 | return s_.erase (entry (xml::string (namespace_).c_str (), |
---|
| 1183 | xml::string (name).c_str ())); |
---|
| 1184 | } |
---|
| 1185 | |
---|
| 1186 | size_type |
---|
| 1187 | erase (const XMLCh* name) |
---|
| 1188 | { |
---|
| 1189 | return s_.erase (entry (0, name)); |
---|
| 1190 | } |
---|
| 1191 | |
---|
| 1192 | size_type |
---|
| 1193 | erase (const XMLCh* namespace_, const XMLCh* name) |
---|
| 1194 | { |
---|
| 1195 | return s_.erase (entry (namespace_, name)); |
---|
| 1196 | } |
---|
| 1197 | |
---|
| 1198 | void |
---|
| 1199 | erase (iterator begin, iterator end) |
---|
| 1200 | { |
---|
| 1201 | s_.erase (begin.base (), end.base ()); |
---|
| 1202 | } |
---|
| 1203 | |
---|
| 1204 | public: |
---|
| 1205 | size_type |
---|
| 1206 | count (const std::basic_string<C>& name) const |
---|
| 1207 | { |
---|
| 1208 | return s_.count (entry (0, xml::string (name).c_str ())); |
---|
| 1209 | } |
---|
| 1210 | |
---|
| 1211 | size_type |
---|
| 1212 | count (const std::basic_string<C>& namespace_, |
---|
| 1213 | const std::basic_string<C>& name) const |
---|
| 1214 | { |
---|
| 1215 | return s_.count (entry (xml::string (namespace_).c_str (), |
---|
| 1216 | xml::string (name).c_str ())); |
---|
| 1217 | } |
---|
| 1218 | |
---|
| 1219 | size_type |
---|
| 1220 | count (const XMLCh* name) const |
---|
| 1221 | { |
---|
| 1222 | return s_.count (entry (0, name)); |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | size_type |
---|
| 1226 | count (const XMLCh* namespace_, const XMLCh* name) const |
---|
| 1227 | { |
---|
| 1228 | return s_.count (entry (namespace_, name)); |
---|
| 1229 | } |
---|
| 1230 | |
---|
| 1231 | // find |
---|
| 1232 | // |
---|
| 1233 | |
---|
| 1234 | iterator |
---|
| 1235 | find (const std::basic_string<C>& name) |
---|
| 1236 | { |
---|
| 1237 | return iterator (s_.find (entry (0, xml::string (name).c_str ()))); |
---|
| 1238 | } |
---|
| 1239 | |
---|
| 1240 | iterator |
---|
| 1241 | find (const std::basic_string<C>& namespace_, |
---|
| 1242 | const std::basic_string<C>& name) |
---|
| 1243 | { |
---|
| 1244 | return iterator ( |
---|
| 1245 | s_.find (entry (xml::string (namespace_).c_str (), |
---|
| 1246 | xml::string (name).c_str ()))); |
---|
| 1247 | } |
---|
| 1248 | |
---|
| 1249 | iterator |
---|
| 1250 | find (const XMLCh* name) |
---|
| 1251 | { |
---|
| 1252 | return iterator (s_.find (entry (0, name))); |
---|
| 1253 | } |
---|
| 1254 | |
---|
| 1255 | iterator |
---|
| 1256 | find (const XMLCh* namespace_, const XMLCh* name) |
---|
| 1257 | { |
---|
| 1258 | return iterator (s_.find (entry (namespace_, name))); |
---|
| 1259 | } |
---|
| 1260 | |
---|
| 1261 | const_iterator |
---|
| 1262 | find (const std::basic_string<C>& name) const |
---|
| 1263 | { |
---|
| 1264 | return const_iterator ( |
---|
| 1265 | s_.find (entry (0, xml::string (name).c_str ()))); |
---|
| 1266 | } |
---|
| 1267 | |
---|
| 1268 | const_iterator |
---|
| 1269 | find (const std::basic_string<C>& namespace_, |
---|
| 1270 | const std::basic_string<C>& name) const |
---|
| 1271 | { |
---|
| 1272 | return const_iterator ( |
---|
| 1273 | s_.find (entry (xml::string (namespace_).c_str (), |
---|
| 1274 | xml::string (name).c_str ()))); |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | const_iterator |
---|
| 1278 | find (const XMLCh* name) const |
---|
| 1279 | { |
---|
| 1280 | return const_iterator (s_.find (entry (0, name))); |
---|
| 1281 | } |
---|
| 1282 | |
---|
| 1283 | const_iterator |
---|
| 1284 | find (const XMLCh* namespace_, const XMLCh* name) const |
---|
| 1285 | { |
---|
| 1286 | return const_iterator (s_.find (entry (namespace_, name))); |
---|
| 1287 | } |
---|
| 1288 | |
---|
| 1289 | public: |
---|
| 1290 | // Note that the DOMDocument object of the two sets being |
---|
| 1291 | // swapped should be the same. |
---|
| 1292 | // |
---|
| 1293 | void |
---|
| 1294 | swap (attribute_set& x) |
---|
| 1295 | { |
---|
| 1296 | assert (&doc_ == &x.doc_); |
---|
| 1297 | s_.swap (x.s_); |
---|
| 1298 | } |
---|
| 1299 | |
---|
| 1300 | private: |
---|
| 1301 | base_set s_; |
---|
| 1302 | xercesc::DOMDocument& doc_; |
---|
| 1303 | }; |
---|
| 1304 | |
---|
| 1305 | // Comparison operators. |
---|
| 1306 | // |
---|
| 1307 | |
---|
| 1308 | template <typename C> |
---|
| 1309 | inline bool |
---|
| 1310 | operator== (const attribute_set<C>& a, const attribute_set<C>& b) |
---|
| 1311 | { |
---|
| 1312 | if (a.size () != b.size ()) |
---|
| 1313 | return false; |
---|
| 1314 | |
---|
| 1315 | typename attribute_set<C>::const_iterator |
---|
| 1316 | ai (a.begin ()), ae (a.end ()), bi (b.begin ()); |
---|
| 1317 | |
---|
| 1318 | for (; ai != ae; ++ai, ++bi) |
---|
| 1319 | if (!ai->isEqualNode (&(*bi))) |
---|
| 1320 | return false; |
---|
| 1321 | |
---|
| 1322 | return true; |
---|
| 1323 | } |
---|
| 1324 | |
---|
| 1325 | template <typename C> |
---|
| 1326 | inline bool |
---|
| 1327 | operator!= (const attribute_set<C>& a, const attribute_set<C>& b) |
---|
| 1328 | { |
---|
| 1329 | return !(a == b); |
---|
| 1330 | } |
---|
| 1331 | } |
---|
| 1332 | } |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | #endif // XSD_CXX_TREE_CONTAINERS_WILDCARD_HXX |
---|