1 | // file : xsd/cxx/parser/xml-schema.ixx |
---|
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 | #include <new> // operator new/delete |
---|
7 | #include <cstring> // std::memcpy, std::memcmp |
---|
8 | |
---|
9 | namespace xsd |
---|
10 | { |
---|
11 | namespace cxx |
---|
12 | { |
---|
13 | namespace parser |
---|
14 | { |
---|
15 | // string_sequence |
---|
16 | // |
---|
17 | template <typename C> |
---|
18 | string_sequence<C>:: |
---|
19 | string_sequence () |
---|
20 | { |
---|
21 | } |
---|
22 | |
---|
23 | template <typename C> |
---|
24 | string_sequence<C>:: |
---|
25 | string_sequence (size_type n, const value_type& x) |
---|
26 | : base (n, x) |
---|
27 | { |
---|
28 | } |
---|
29 | |
---|
30 | template <typename C> |
---|
31 | template <typename I> |
---|
32 | string_sequence<C>:: |
---|
33 | string_sequence (const I& begin, const I& end) |
---|
34 | : base (begin, end) |
---|
35 | { |
---|
36 | } |
---|
37 | |
---|
38 | template <typename C> |
---|
39 | inline bool |
---|
40 | operator!= (const string_sequence<C>& a, const string_sequence<C>& b) |
---|
41 | { |
---|
42 | return !(a == b); |
---|
43 | } |
---|
44 | |
---|
45 | // qname |
---|
46 | // |
---|
47 | template <typename C> |
---|
48 | inline qname<C>:: |
---|
49 | qname (const std::basic_string<C>& name) |
---|
50 | : name_ (name) |
---|
51 | { |
---|
52 | } |
---|
53 | |
---|
54 | template <typename C> |
---|
55 | inline qname<C>:: |
---|
56 | qname (const std::basic_string<C>& prefix, |
---|
57 | const std::basic_string<C>& name) |
---|
58 | : prefix_ (prefix), name_ (name) |
---|
59 | { |
---|
60 | } |
---|
61 | |
---|
62 | template <typename C> |
---|
63 | void qname<C>:: |
---|
64 | swap (qname<C>& x) |
---|
65 | { |
---|
66 | prefix_.swap (x.prefix_); |
---|
67 | name_.swap (x.name_); |
---|
68 | } |
---|
69 | |
---|
70 | template <typename C> |
---|
71 | inline const std::basic_string<C>& qname<C>:: |
---|
72 | prefix () const |
---|
73 | { |
---|
74 | return prefix_; |
---|
75 | } |
---|
76 | |
---|
77 | template <typename C> |
---|
78 | inline std::basic_string<C>& qname<C>:: |
---|
79 | prefix () |
---|
80 | { |
---|
81 | return prefix_; |
---|
82 | } |
---|
83 | |
---|
84 | template <typename C> |
---|
85 | inline void qname<C>:: |
---|
86 | prefix (const std::basic_string<C>& prefix) |
---|
87 | { |
---|
88 | prefix_ = prefix; |
---|
89 | } |
---|
90 | |
---|
91 | template <typename C> |
---|
92 | inline const std::basic_string<C>& qname<C>:: |
---|
93 | name () const |
---|
94 | { |
---|
95 | return name_; |
---|
96 | } |
---|
97 | |
---|
98 | template <typename C> |
---|
99 | inline std::basic_string<C>& qname<C>:: |
---|
100 | name () |
---|
101 | { |
---|
102 | return name_; |
---|
103 | } |
---|
104 | |
---|
105 | template <typename C> |
---|
106 | inline void qname<C>:: |
---|
107 | name (const std::basic_string<C>& name) |
---|
108 | { |
---|
109 | name_ = name; |
---|
110 | } |
---|
111 | |
---|
112 | template <typename C> |
---|
113 | inline bool |
---|
114 | operator== (const qname<C>& a, const qname<C>& b) |
---|
115 | { |
---|
116 | return a.prefix () == b.prefix () && a.name () == b.name (); |
---|
117 | } |
---|
118 | |
---|
119 | template <typename C> |
---|
120 | inline bool |
---|
121 | operator!= (const qname<C>& a, const qname<C>& b) |
---|
122 | { |
---|
123 | return !(a == b); |
---|
124 | } |
---|
125 | |
---|
126 | // buffer |
---|
127 | // |
---|
128 | inline buffer:: |
---|
129 | ~buffer () |
---|
130 | { |
---|
131 | operator delete (data_); |
---|
132 | } |
---|
133 | |
---|
134 | inline buffer:: |
---|
135 | buffer (size_t size) |
---|
136 | : data_ (0), size_ (0), capacity_ (0) |
---|
137 | { |
---|
138 | capacity (size); |
---|
139 | size_ = size; |
---|
140 | } |
---|
141 | |
---|
142 | inline buffer:: |
---|
143 | buffer (size_t size, size_t cap) |
---|
144 | : data_ (0), size_ (0), capacity_ (0) |
---|
145 | { |
---|
146 | if (size > cap) |
---|
147 | throw bounds (); |
---|
148 | |
---|
149 | capacity (cap); |
---|
150 | size_ = size; |
---|
151 | } |
---|
152 | |
---|
153 | inline buffer:: |
---|
154 | buffer (const void* data, size_t size) |
---|
155 | : data_ (0), size_ (0), capacity_ (0) |
---|
156 | { |
---|
157 | capacity (size); |
---|
158 | size_ = size; |
---|
159 | |
---|
160 | if (size_) |
---|
161 | std::memcpy (data_, data, size_); |
---|
162 | } |
---|
163 | |
---|
164 | inline buffer:: |
---|
165 | buffer (const void* data, size_t size, size_t cap) |
---|
166 | : data_ (0), size_ (0), capacity_ (0) |
---|
167 | { |
---|
168 | if (size > cap) |
---|
169 | throw bounds (); |
---|
170 | |
---|
171 | capacity (cap); |
---|
172 | size_ = size; |
---|
173 | |
---|
174 | if (size_) |
---|
175 | std::memcpy (data_, data, size_); |
---|
176 | } |
---|
177 | |
---|
178 | inline buffer:: |
---|
179 | buffer (void* data, size_t size, size_t cap, bool own) |
---|
180 | : data_ (0), size_ (0), capacity_ (0) |
---|
181 | { |
---|
182 | if (size > cap) |
---|
183 | throw bounds (); |
---|
184 | |
---|
185 | if (own) |
---|
186 | { |
---|
187 | data_ = reinterpret_cast<char*> (data); |
---|
188 | size_ = size; |
---|
189 | capacity_ = cap; |
---|
190 | } |
---|
191 | else |
---|
192 | { |
---|
193 | capacity (cap); |
---|
194 | size_ = size; |
---|
195 | |
---|
196 | if (size_) |
---|
197 | std::memcpy (data_, data, size_); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | inline buffer:: |
---|
202 | buffer (const buffer& other) |
---|
203 | : data_ (0), size_ (0), capacity_ (0) |
---|
204 | { |
---|
205 | capacity (other.capacity_); |
---|
206 | size_ = other.size_; |
---|
207 | |
---|
208 | if (size_) |
---|
209 | std::memcpy (data_, other.data_, size_); |
---|
210 | } |
---|
211 | |
---|
212 | inline buffer& buffer:: |
---|
213 | operator= (const buffer& other) |
---|
214 | { |
---|
215 | if (this != &other) |
---|
216 | { |
---|
217 | capacity (other.capacity_, false); |
---|
218 | size_ = other.size_; |
---|
219 | |
---|
220 | if (size_) |
---|
221 | std::memcpy (data_, other.data_, size_); |
---|
222 | } |
---|
223 | |
---|
224 | return *this; |
---|
225 | } |
---|
226 | |
---|
227 | inline size_t buffer:: |
---|
228 | capacity () const |
---|
229 | { |
---|
230 | return capacity_; |
---|
231 | } |
---|
232 | |
---|
233 | inline bool buffer:: |
---|
234 | capacity (size_t cap) |
---|
235 | { |
---|
236 | return capacity (cap, true); |
---|
237 | } |
---|
238 | |
---|
239 | inline size_t buffer:: |
---|
240 | size () const |
---|
241 | { |
---|
242 | return size_; |
---|
243 | } |
---|
244 | |
---|
245 | inline bool buffer:: |
---|
246 | size (size_t size) |
---|
247 | { |
---|
248 | bool r (false); |
---|
249 | |
---|
250 | if (size > capacity_) |
---|
251 | r = capacity (size); |
---|
252 | |
---|
253 | size_ = size; |
---|
254 | |
---|
255 | return r; |
---|
256 | } |
---|
257 | |
---|
258 | inline const char* buffer:: |
---|
259 | data () const |
---|
260 | { |
---|
261 | return data_; |
---|
262 | } |
---|
263 | |
---|
264 | inline char* buffer:: |
---|
265 | data () |
---|
266 | { |
---|
267 | return data_; |
---|
268 | } |
---|
269 | |
---|
270 | inline const char* buffer:: |
---|
271 | begin () const |
---|
272 | { |
---|
273 | return data_; |
---|
274 | } |
---|
275 | |
---|
276 | inline char* buffer:: |
---|
277 | begin () |
---|
278 | { |
---|
279 | return data_; |
---|
280 | } |
---|
281 | |
---|
282 | inline const char* buffer:: |
---|
283 | end () const |
---|
284 | { |
---|
285 | return data_ + size_; |
---|
286 | } |
---|
287 | |
---|
288 | inline char* buffer:: |
---|
289 | end () |
---|
290 | { |
---|
291 | return data_ + size_; |
---|
292 | } |
---|
293 | |
---|
294 | inline void buffer:: |
---|
295 | swap (buffer& other) |
---|
296 | { |
---|
297 | char* tmp_data (data_); |
---|
298 | size_t tmp_size (size_); |
---|
299 | size_t tmp_capacity (capacity_); |
---|
300 | |
---|
301 | data_ = other.data_; |
---|
302 | size_ = other.size_; |
---|
303 | capacity_ = other.capacity_; |
---|
304 | |
---|
305 | other.data_ = tmp_data; |
---|
306 | other.size_ = tmp_size; |
---|
307 | other.capacity_ = tmp_capacity; |
---|
308 | } |
---|
309 | |
---|
310 | inline bool buffer:: |
---|
311 | capacity (size_t capacity, bool copy) |
---|
312 | { |
---|
313 | if (size_ > capacity) |
---|
314 | throw bounds (); |
---|
315 | |
---|
316 | if (capacity <= capacity_) |
---|
317 | { |
---|
318 | return false; // Do nothing if shrinking is requested. |
---|
319 | } |
---|
320 | else |
---|
321 | { |
---|
322 | char* data (reinterpret_cast<char*> (operator new (capacity))); |
---|
323 | |
---|
324 | if (copy && size_ > 0) |
---|
325 | std::memcpy (data, data_, size_); |
---|
326 | |
---|
327 | char* tmp (data_); |
---|
328 | data_ = data; |
---|
329 | capacity_ = capacity; |
---|
330 | |
---|
331 | operator delete (tmp); |
---|
332 | |
---|
333 | return true; |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | inline bool |
---|
338 | operator== (const buffer& a, const buffer& b) |
---|
339 | { |
---|
340 | return a.size () == b.size () && |
---|
341 | std::memcmp (a.data (), b.data (), a.size ()) == 0; |
---|
342 | } |
---|
343 | |
---|
344 | inline bool |
---|
345 | operator!= (const buffer& a, const buffer& b) |
---|
346 | { |
---|
347 | return !(a == b); |
---|
348 | } |
---|
349 | |
---|
350 | // time_zone |
---|
351 | // |
---|
352 | inline time_zone:: |
---|
353 | time_zone () |
---|
354 | : present_ (false) |
---|
355 | { |
---|
356 | } |
---|
357 | |
---|
358 | inline time_zone:: |
---|
359 | time_zone (short h, short m) |
---|
360 | : present_ (true), hours_ (h), minutes_ (m) |
---|
361 | { |
---|
362 | } |
---|
363 | |
---|
364 | inline bool time_zone:: |
---|
365 | zone_present () const |
---|
366 | { |
---|
367 | return present_; |
---|
368 | } |
---|
369 | |
---|
370 | inline void time_zone:: |
---|
371 | zone_reset () |
---|
372 | { |
---|
373 | present_ = false; |
---|
374 | } |
---|
375 | |
---|
376 | inline short time_zone:: |
---|
377 | zone_hours () const |
---|
378 | { |
---|
379 | return hours_; |
---|
380 | } |
---|
381 | |
---|
382 | inline void time_zone:: |
---|
383 | zone_hours (short h) |
---|
384 | { |
---|
385 | hours_ = h; |
---|
386 | present_ = true; |
---|
387 | } |
---|
388 | |
---|
389 | inline short time_zone:: |
---|
390 | zone_minutes () const |
---|
391 | { |
---|
392 | return minutes_; |
---|
393 | } |
---|
394 | |
---|
395 | inline void time_zone:: |
---|
396 | zone_minutes (short m) |
---|
397 | { |
---|
398 | minutes_ = m; |
---|
399 | present_ = true; |
---|
400 | } |
---|
401 | |
---|
402 | inline bool |
---|
403 | operator== (const time_zone& x, const time_zone& y) |
---|
404 | { |
---|
405 | return x.zone_present () |
---|
406 | ? y.zone_present () && |
---|
407 | x.zone_hours () == y.zone_hours () && |
---|
408 | x.zone_minutes () == y.zone_minutes () |
---|
409 | : !y.zone_present (); |
---|
410 | } |
---|
411 | |
---|
412 | inline bool |
---|
413 | operator!= (const time_zone& x, const time_zone& y) |
---|
414 | { |
---|
415 | return !(x == y); |
---|
416 | } |
---|
417 | |
---|
418 | // gday |
---|
419 | // |
---|
420 | inline gday:: |
---|
421 | gday (unsigned short day) |
---|
422 | : day_ (day) |
---|
423 | { |
---|
424 | } |
---|
425 | |
---|
426 | inline gday:: |
---|
427 | gday (unsigned short day, short zh, short zm) |
---|
428 | : time_zone (zh, zm), day_ (day) |
---|
429 | { |
---|
430 | } |
---|
431 | |
---|
432 | inline unsigned short gday:: |
---|
433 | day () const |
---|
434 | { |
---|
435 | return day_; |
---|
436 | } |
---|
437 | |
---|
438 | inline void gday:: |
---|
439 | day (unsigned short day) |
---|
440 | { |
---|
441 | day_ = day; |
---|
442 | } |
---|
443 | |
---|
444 | inline bool |
---|
445 | operator== (const gday& a, const gday& b) |
---|
446 | { |
---|
447 | const time_zone& az = a; |
---|
448 | const time_zone& bz = b; |
---|
449 | |
---|
450 | return a.day () == b.day () && az == bz; |
---|
451 | } |
---|
452 | |
---|
453 | inline bool |
---|
454 | operator!= (const gday& a, const gday& b) |
---|
455 | { |
---|
456 | return !(a == b); |
---|
457 | } |
---|
458 | |
---|
459 | // gmonth |
---|
460 | // |
---|
461 | inline gmonth:: |
---|
462 | gmonth (unsigned short month) |
---|
463 | : month_ (month) |
---|
464 | { |
---|
465 | } |
---|
466 | |
---|
467 | inline gmonth:: |
---|
468 | gmonth (unsigned short month, short zh, short zm) |
---|
469 | : time_zone (zh, zm), month_ (month) |
---|
470 | { |
---|
471 | } |
---|
472 | |
---|
473 | inline unsigned short gmonth:: |
---|
474 | month () const |
---|
475 | { |
---|
476 | return month_; |
---|
477 | } |
---|
478 | |
---|
479 | inline void gmonth:: |
---|
480 | month (unsigned short month) |
---|
481 | { |
---|
482 | month_ = month; |
---|
483 | } |
---|
484 | |
---|
485 | inline bool |
---|
486 | operator== (const gmonth& a, const gmonth& b) |
---|
487 | { |
---|
488 | const time_zone& az = a; |
---|
489 | const time_zone& bz = b; |
---|
490 | |
---|
491 | return a.month () == b.month () && az == bz; |
---|
492 | } |
---|
493 | |
---|
494 | inline bool |
---|
495 | operator!= (const gmonth& a, const gmonth& b) |
---|
496 | { |
---|
497 | return !(a == b); |
---|
498 | } |
---|
499 | |
---|
500 | // gyear |
---|
501 | // |
---|
502 | inline gyear:: |
---|
503 | gyear (int year) |
---|
504 | : year_ (year) |
---|
505 | { |
---|
506 | } |
---|
507 | |
---|
508 | inline gyear:: |
---|
509 | gyear (int year, short zh, short zm) |
---|
510 | : time_zone (zh, zm), year_ (year) |
---|
511 | { |
---|
512 | } |
---|
513 | |
---|
514 | inline int gyear:: |
---|
515 | year () const |
---|
516 | { |
---|
517 | return year_; |
---|
518 | } |
---|
519 | |
---|
520 | inline void gyear:: |
---|
521 | year (int year) |
---|
522 | { |
---|
523 | year_ = year; |
---|
524 | } |
---|
525 | |
---|
526 | inline bool |
---|
527 | operator== (const gyear& a, const gyear& b) |
---|
528 | { |
---|
529 | const time_zone& az = a; |
---|
530 | const time_zone& bz = b; |
---|
531 | |
---|
532 | return a.year () == b.year () && az == bz; |
---|
533 | } |
---|
534 | |
---|
535 | inline bool |
---|
536 | operator!= (const gyear& a, const gyear& b) |
---|
537 | { |
---|
538 | return !(a == b); |
---|
539 | } |
---|
540 | |
---|
541 | // gmonth_day |
---|
542 | // |
---|
543 | inline gmonth_day:: |
---|
544 | gmonth_day (unsigned short month, unsigned short day) |
---|
545 | : month_ (month), day_ (day) |
---|
546 | { |
---|
547 | } |
---|
548 | |
---|
549 | inline gmonth_day:: |
---|
550 | gmonth_day (unsigned short month, |
---|
551 | unsigned short day, |
---|
552 | short zh, short zm) |
---|
553 | : time_zone (zh, zm), month_ (month), day_ (day) |
---|
554 | { |
---|
555 | } |
---|
556 | |
---|
557 | inline unsigned short gmonth_day:: |
---|
558 | month () const |
---|
559 | { |
---|
560 | return month_; |
---|
561 | } |
---|
562 | |
---|
563 | inline void gmonth_day:: |
---|
564 | month (unsigned short month) |
---|
565 | { |
---|
566 | month_ = month; |
---|
567 | } |
---|
568 | |
---|
569 | inline unsigned short gmonth_day:: |
---|
570 | day () const |
---|
571 | { |
---|
572 | return day_; |
---|
573 | } |
---|
574 | |
---|
575 | inline void gmonth_day:: |
---|
576 | day (unsigned short day) |
---|
577 | { |
---|
578 | day_ = day; |
---|
579 | } |
---|
580 | |
---|
581 | inline bool |
---|
582 | operator== (const gmonth_day& a, const gmonth_day& b) |
---|
583 | { |
---|
584 | const time_zone& az = a; |
---|
585 | const time_zone& bz = b; |
---|
586 | |
---|
587 | return a.month () == b.month () && |
---|
588 | a.day () == b.day () && |
---|
589 | az == bz; |
---|
590 | } |
---|
591 | |
---|
592 | inline bool |
---|
593 | operator!= (const gmonth_day& a, const gmonth_day& b) |
---|
594 | { |
---|
595 | return !(a == b); |
---|
596 | } |
---|
597 | |
---|
598 | // gyear_month |
---|
599 | // |
---|
600 | inline gyear_month:: |
---|
601 | gyear_month (int year, unsigned short month) |
---|
602 | : year_ (year), month_ (month) |
---|
603 | { |
---|
604 | } |
---|
605 | |
---|
606 | inline gyear_month:: |
---|
607 | gyear_month (int year, unsigned short month, |
---|
608 | short zh, short zm) |
---|
609 | : time_zone (zh, zm), year_ (year), month_ (month) |
---|
610 | { |
---|
611 | } |
---|
612 | |
---|
613 | inline int gyear_month:: |
---|
614 | year () const |
---|
615 | { |
---|
616 | return year_; |
---|
617 | } |
---|
618 | |
---|
619 | inline void gyear_month:: |
---|
620 | year (int year) |
---|
621 | { |
---|
622 | year_ = year; |
---|
623 | } |
---|
624 | |
---|
625 | inline unsigned short gyear_month:: |
---|
626 | month () const |
---|
627 | { |
---|
628 | return month_; |
---|
629 | } |
---|
630 | |
---|
631 | inline void gyear_month:: |
---|
632 | month (unsigned short month) |
---|
633 | { |
---|
634 | month_ = month; |
---|
635 | } |
---|
636 | |
---|
637 | inline bool |
---|
638 | operator== (const gyear_month& a, const gyear_month& b) |
---|
639 | { |
---|
640 | const time_zone& az = a; |
---|
641 | const time_zone& bz = b; |
---|
642 | |
---|
643 | return a.year () == b.year () && |
---|
644 | a.month () == b.month () && |
---|
645 | az == bz; |
---|
646 | } |
---|
647 | |
---|
648 | inline bool |
---|
649 | operator!= (const gyear_month& a, const gyear_month& b) |
---|
650 | { |
---|
651 | return !(a == b); |
---|
652 | } |
---|
653 | |
---|
654 | // date |
---|
655 | // |
---|
656 | inline date:: |
---|
657 | date (int year, unsigned short month, unsigned short day) |
---|
658 | : year_ (year), month_ (month), day_ (day) |
---|
659 | { |
---|
660 | } |
---|
661 | |
---|
662 | inline date:: |
---|
663 | date (int year, unsigned short month, unsigned short day, |
---|
664 | short zh, short zm) |
---|
665 | : time_zone (zh, zm), year_ (year), month_ (month), day_ (day) |
---|
666 | { |
---|
667 | } |
---|
668 | |
---|
669 | inline int date:: |
---|
670 | year () const |
---|
671 | { |
---|
672 | return year_; |
---|
673 | } |
---|
674 | |
---|
675 | inline void date:: |
---|
676 | year (int year) |
---|
677 | { |
---|
678 | year_ = year; |
---|
679 | } |
---|
680 | |
---|
681 | inline unsigned short date:: |
---|
682 | month () const |
---|
683 | { |
---|
684 | return month_; |
---|
685 | } |
---|
686 | |
---|
687 | inline void date:: |
---|
688 | month (unsigned short month) |
---|
689 | { |
---|
690 | month_ = month; |
---|
691 | } |
---|
692 | |
---|
693 | inline unsigned short date:: |
---|
694 | day () const |
---|
695 | { |
---|
696 | return day_; |
---|
697 | } |
---|
698 | |
---|
699 | inline void date:: |
---|
700 | day (unsigned short day) |
---|
701 | { |
---|
702 | day_ = day; |
---|
703 | } |
---|
704 | |
---|
705 | inline bool |
---|
706 | operator== (const date& a, const date& b) |
---|
707 | { |
---|
708 | const time_zone& az = a; |
---|
709 | const time_zone& bz = b; |
---|
710 | |
---|
711 | return a.year () == b.year () && |
---|
712 | a.month () == b.month () && |
---|
713 | a.day () == b.day () && |
---|
714 | az == bz; |
---|
715 | } |
---|
716 | |
---|
717 | inline bool |
---|
718 | operator!= (const date& a, const date& b) |
---|
719 | { |
---|
720 | return !(a == b); |
---|
721 | } |
---|
722 | |
---|
723 | // time |
---|
724 | // |
---|
725 | inline time:: |
---|
726 | time (unsigned short hours, unsigned short minutes, double seconds) |
---|
727 | : hours_ (hours), minutes_ (minutes), seconds_ (seconds) |
---|
728 | { |
---|
729 | } |
---|
730 | |
---|
731 | inline time:: |
---|
732 | time (unsigned short hours, unsigned short minutes, double seconds, |
---|
733 | short zh, short zm) |
---|
734 | : time_zone (zh, zm), |
---|
735 | hours_ (hours), minutes_ (minutes), seconds_ (seconds) |
---|
736 | { |
---|
737 | } |
---|
738 | |
---|
739 | inline unsigned short time:: |
---|
740 | hours () const |
---|
741 | { |
---|
742 | return hours_; |
---|
743 | } |
---|
744 | |
---|
745 | inline void time:: |
---|
746 | hours (unsigned short hours) |
---|
747 | { |
---|
748 | hours_ = hours; |
---|
749 | } |
---|
750 | |
---|
751 | inline unsigned short time:: |
---|
752 | minutes () const |
---|
753 | { |
---|
754 | return minutes_; |
---|
755 | } |
---|
756 | |
---|
757 | inline void time:: |
---|
758 | minutes (unsigned short minutes) |
---|
759 | { |
---|
760 | minutes_ = minutes; |
---|
761 | } |
---|
762 | |
---|
763 | inline double time:: |
---|
764 | seconds () const |
---|
765 | { |
---|
766 | return seconds_; |
---|
767 | } |
---|
768 | |
---|
769 | inline void time:: |
---|
770 | seconds (double seconds) |
---|
771 | { |
---|
772 | seconds_ = seconds; |
---|
773 | } |
---|
774 | |
---|
775 | inline bool |
---|
776 | operator== (const time& a, const time& b) |
---|
777 | { |
---|
778 | const time_zone& az = a; |
---|
779 | const time_zone& bz = b; |
---|
780 | |
---|
781 | return a.hours () == b.hours () && |
---|
782 | a.minutes () == b.minutes () && |
---|
783 | a.seconds () == b.seconds () && |
---|
784 | az == bz; |
---|
785 | } |
---|
786 | |
---|
787 | inline bool |
---|
788 | operator!= (const time& a, const time& b) |
---|
789 | { |
---|
790 | return !(a == b); |
---|
791 | } |
---|
792 | |
---|
793 | // date_time |
---|
794 | // |
---|
795 | inline date_time:: |
---|
796 | date_time (int year, unsigned short month, unsigned short day, |
---|
797 | unsigned short hours, unsigned short minutes, double seconds) |
---|
798 | : year_ (year), month_ (month), day_ (day), |
---|
799 | hours_ (hours), minutes_ (minutes), seconds_ (seconds) |
---|
800 | { |
---|
801 | } |
---|
802 | |
---|
803 | inline date_time:: |
---|
804 | date_time (int year, unsigned short month, unsigned short day, |
---|
805 | unsigned short hours, unsigned short minutes, double seconds, |
---|
806 | short zh, short zm) |
---|
807 | : time_zone (zh, zm), |
---|
808 | year_ (year), month_ (month), day_ (day), |
---|
809 | hours_ (hours), minutes_ (minutes), seconds_ (seconds) |
---|
810 | { |
---|
811 | } |
---|
812 | |
---|
813 | inline int date_time:: |
---|
814 | year () const |
---|
815 | { |
---|
816 | return year_; |
---|
817 | } |
---|
818 | |
---|
819 | inline void date_time:: |
---|
820 | year (int year) |
---|
821 | { |
---|
822 | year_ = year; |
---|
823 | } |
---|
824 | |
---|
825 | inline unsigned short date_time:: |
---|
826 | month () const |
---|
827 | { |
---|
828 | return month_; |
---|
829 | } |
---|
830 | |
---|
831 | inline void date_time:: |
---|
832 | month (unsigned short month) |
---|
833 | { |
---|
834 | month_ = month; |
---|
835 | } |
---|
836 | |
---|
837 | inline unsigned short date_time:: |
---|
838 | day () const |
---|
839 | { |
---|
840 | return day_; |
---|
841 | } |
---|
842 | |
---|
843 | inline void date_time:: |
---|
844 | day (unsigned short day) |
---|
845 | { |
---|
846 | day_ = day; |
---|
847 | } |
---|
848 | |
---|
849 | inline unsigned short date_time:: |
---|
850 | hours () const |
---|
851 | { |
---|
852 | return hours_; |
---|
853 | } |
---|
854 | |
---|
855 | inline void date_time:: |
---|
856 | hours (unsigned short hours) |
---|
857 | { |
---|
858 | hours_ = hours; |
---|
859 | } |
---|
860 | |
---|
861 | inline unsigned short date_time:: |
---|
862 | minutes () const |
---|
863 | { |
---|
864 | return minutes_; |
---|
865 | } |
---|
866 | |
---|
867 | inline void date_time:: |
---|
868 | minutes (unsigned short minutes) |
---|
869 | { |
---|
870 | minutes_ = minutes; |
---|
871 | } |
---|
872 | |
---|
873 | inline double date_time:: |
---|
874 | seconds () const |
---|
875 | { |
---|
876 | return seconds_; |
---|
877 | } |
---|
878 | |
---|
879 | inline void date_time:: |
---|
880 | seconds (double seconds) |
---|
881 | { |
---|
882 | seconds_ = seconds; |
---|
883 | } |
---|
884 | |
---|
885 | inline bool |
---|
886 | operator== (const date_time& a, const date_time& b) |
---|
887 | { |
---|
888 | const time_zone& az = a; |
---|
889 | const time_zone& bz = b; |
---|
890 | |
---|
891 | return a.year () == b.year () && |
---|
892 | a.month () == b.month () && |
---|
893 | a.day () == b.day () && |
---|
894 | a.hours () == b.hours () && |
---|
895 | a.minutes () == b.minutes () && |
---|
896 | a.seconds () == b.seconds () && |
---|
897 | az == bz; |
---|
898 | } |
---|
899 | |
---|
900 | inline bool |
---|
901 | operator!= (const date_time& a, const date_time& b) |
---|
902 | { |
---|
903 | return !(a == b); |
---|
904 | } |
---|
905 | |
---|
906 | // duration |
---|
907 | // |
---|
908 | inline duration:: |
---|
909 | duration (bool negative, |
---|
910 | unsigned int years, unsigned int months, unsigned int days, |
---|
911 | unsigned int hours, unsigned int minutes, double seconds) |
---|
912 | : negative_ (negative), |
---|
913 | years_ (years), months_ (months), days_ (days), |
---|
914 | hours_ (hours), minutes_ (minutes), seconds_ (seconds) |
---|
915 | { |
---|
916 | } |
---|
917 | |
---|
918 | inline bool duration:: |
---|
919 | negative () const |
---|
920 | { |
---|
921 | return negative_; |
---|
922 | } |
---|
923 | |
---|
924 | inline void duration:: |
---|
925 | negative (bool negative) |
---|
926 | { |
---|
927 | negative_ = negative; |
---|
928 | } |
---|
929 | |
---|
930 | inline unsigned int duration:: |
---|
931 | years () const |
---|
932 | { |
---|
933 | return years_; |
---|
934 | } |
---|
935 | |
---|
936 | inline void duration:: |
---|
937 | years (unsigned int years) |
---|
938 | { |
---|
939 | years_ = years; |
---|
940 | } |
---|
941 | |
---|
942 | inline unsigned int duration:: |
---|
943 | months () const |
---|
944 | { |
---|
945 | return months_; |
---|
946 | } |
---|
947 | |
---|
948 | inline void duration:: |
---|
949 | months (unsigned int months) |
---|
950 | { |
---|
951 | months_ = months; |
---|
952 | } |
---|
953 | |
---|
954 | inline unsigned int duration:: |
---|
955 | days () const |
---|
956 | { |
---|
957 | return days_; |
---|
958 | } |
---|
959 | |
---|
960 | inline void duration:: |
---|
961 | days (unsigned int days) |
---|
962 | { |
---|
963 | days_ = days; |
---|
964 | } |
---|
965 | |
---|
966 | inline unsigned int duration:: |
---|
967 | hours () const |
---|
968 | { |
---|
969 | return hours_; |
---|
970 | } |
---|
971 | |
---|
972 | inline void duration:: |
---|
973 | hours (unsigned int hours) |
---|
974 | { |
---|
975 | hours_ = hours; |
---|
976 | } |
---|
977 | |
---|
978 | inline unsigned int duration:: |
---|
979 | minutes () const |
---|
980 | { |
---|
981 | return minutes_; |
---|
982 | } |
---|
983 | |
---|
984 | inline void duration:: |
---|
985 | minutes (unsigned int minutes) |
---|
986 | { |
---|
987 | minutes_ = minutes; |
---|
988 | } |
---|
989 | |
---|
990 | inline double duration:: |
---|
991 | seconds () const |
---|
992 | { |
---|
993 | return seconds_; |
---|
994 | } |
---|
995 | |
---|
996 | inline void duration:: |
---|
997 | seconds (double seconds) |
---|
998 | { |
---|
999 | seconds_ = seconds; |
---|
1000 | } |
---|
1001 | |
---|
1002 | inline bool |
---|
1003 | operator== (const duration& a, const duration& b) |
---|
1004 | { |
---|
1005 | return a.negative () == b.negative () && |
---|
1006 | a.years () == b.years () && |
---|
1007 | a.months () == b.months () && |
---|
1008 | a.days () == b.days () && |
---|
1009 | a.hours () == b.hours () && |
---|
1010 | a.minutes () == b.minutes () && |
---|
1011 | a.seconds () == b.seconds (); |
---|
1012 | } |
---|
1013 | |
---|
1014 | inline bool |
---|
1015 | operator!= (const duration& a, const duration& b) |
---|
1016 | { |
---|
1017 | return !(a == b); |
---|
1018 | } |
---|
1019 | } |
---|
1020 | } |
---|
1021 | } |
---|