1 #ifndef OBJECTINFO__HPP
2 #define OBJECTINFO__HPP
3
4 /* $Id: objectinfo.hpp 380188 2012-11-08 18:49:33Z vasilche $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's official duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author: Eugene Vasilchenko
30 *
31 * File Description:
32 * Object information classes
33 */
34
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiobj.hpp>
37 #include <serial/serialdef.hpp>
38 #include <serial/impl/continfo.hpp>
39 #include <serial/impl/ptrinfo.hpp>
40 #include <serial/impl/stdtypes.hpp>
41 #include <serial/impl/classinfo.hpp>
42 #include <serial/impl/choice.hpp>
43 #include <serial/impl/enumerated.hpp>
44 #include <vector>
45 #include <memory>
46
47
48 /** @addtogroup ObjStreamSupport
49 *
50 * @{
51 */
52
53
54 BEGIN_NCBI_SCOPE
55
56 class CObjectTypeInfo;
57 class CConstObjectInfo;
58 class CObjectInfo;
59
60 class CPrimitiveTypeInfo;
61 class CClassTypeInfoBase;
62 class CClassTypeInfo;
63 class CChoiceTypeInfo;
64 class CContainerTypeInfo;
65 class CPointerTypeInfo;
66
67 class CMemberId;
68 class CItemInfo;
69 class CMemberInfo;
70 class CVariantInfo;
71
72 class CReadContainerElementHook;
73
74 class CObjectTypeInfoMI;
75 class CObjectTypeInfoVI;
76 class CObjectTypeInfoCV;
77 class CConstObjectInfoMI;
78 class CConstObjectInfoCV;
79 class CConstObjectInfoEI;
80 class CObjectInfoMI;
81 class CObjectInfoCV;
82 class CObjectInfoEI;
83
84 class CObjectIStreamAsnBinary;
85
86 /////////////////////////////////////////////////////////////////////////////
87 ///
88 /// CObjectTypeInfo --
89 ///
90 /// Facilitate access to the data type information.
91 /// No concrete object is referenced.
92
93 class NCBI_XSERIAL_EXPORT CObjectTypeInfo
94 {
95 public:
96 typedef CObjectTypeInfoMI CMemberIterator;
97 typedef CObjectTypeInfoVI CVariantIterator;
98 typedef CObjectTypeInfoCV CChoiceVariant;
99
100 CObjectTypeInfo(TTypeInfo typeinfo = 0);
101
102 /// Get type name
103 ///
104 /// @return
105 /// Type name string
GetName(void) const106 const string& GetName(void) const
107 {
108 return GetTypeInfo()->GetName();
109 }
110
111 /// Get data type family
112 ///
113 /// @return
114 /// Type family enumerator
115 ETypeFamily GetTypeFamily(void) const;
116
117 /// Check if object is valid
Valid(void) const118 bool Valid(void) const
119 {
120 return m_TypeInfo != 0;
121 }
122 DECLARE_OPERATOR_BOOL_PTR(m_TypeInfo);
123
124 bool operator==(const CObjectTypeInfo& type) const;
125 bool operator!=(const CObjectTypeInfo& type) const;
126
127 // --------------------------------------------------
128 // primitive type interface
129 // only when GetTypeFamily() == eTypeFamilyPrimitive
130
131 /// Get type of primitive value
132 ///
133 /// @return
134 /// Primitive value type enumerator
135 /// @note
136 /// May be used only when type family is eTypeFamilyPrimitive
137 EPrimitiveValueType GetPrimitiveValueType(void) const;
138
139 /// Is primitive value signed
140 ///
141 /// @return
142 /// TRUE when value is signed; FALSE otherwise
143 /// @note
144 /// May be used only when type family is eTypeFamilyPrimitive
145 bool IsPrimitiveValueSigned(void) const;
146
147 /// Get a set of possible values of enumeration
148 ///
149 /// @return
150 /// object that describes enumeration values
151 /// @sa CEnumeratedTypeValues
152 /// @note
153 /// May be used only when value type is ePrimitiveValueEnum
154 const CEnumeratedTypeValues& GetEnumeratedTypeValues(void) const;
155
156 // --------------------------------------------------
157 // container interface
158 // only when GetTypeFamily() == eTypeFamilyContainer
159
160 /// Get type information of an element of container
161 ///
162 /// @return
163 /// Object that provides access to element data type
164 /// @note
165 /// May be used only when type family is eTypeFamilyContainer
166 CObjectTypeInfo GetElementType(void) const;
167
168 // --------------------------------------------------
169 // class interface
170 // only when GetTypeFamily() == eTypeFamilyClass
171
172 /// Create class member iterator
173 ///
174 /// @sa CObjectTypeInfoMI
175 /// @note
176 /// May be used only when type family is eTypeFamilyClass
177 CMemberIterator BeginMembers(void) const;
178
179 /// Find class member by its name
180 ///
181 /// @sa CObjectTypeInfoMI
182 /// @note
183 /// May be used only when type family is eTypeFamilyClass
184 CMemberIterator FindMember(const string& memberName) const;
185
186 /// Find class member index by its name
187 ///
188 /// @sa CObjectTypeInfoMI
189 /// @note
190 /// May be used only when type family is eTypeFamilyClass
191 TMemberIndex FindMemberIndex(const string& name) const;
192
193 /// Find class member by its numerical tag
194 ///
195 /// @sa CObjectTypeInfoMI
196 /// @note
197 /// May be used only when type family is eTypeFamilyClass
198 CMemberIterator FindMemberByTag(int memberTag) const;
199
200 /// Find class member index by its numerical tag
201 ///
202 /// @sa CObjectTypeInfoMI
203 /// @note
204 /// May be used only when type family is eTypeFamilyClass
205 TMemberIndex FindMemberIndex(int tag) const;
206
207 // --------------------------------------------------
208 // choice interface
209 // only when GetTypeFamily() == eTypeFamilyChoice
210
211 /// Create choice variant iterator
212 ///
213 /// @sa CObjectTypeInfoVI
214 /// @note
215 /// May be used only when type family is eTypeFamilyChoice
216 CVariantIterator BeginVariants(void) const;
217
218 /// Find choice variant by its name
219 ///
220 /// @sa CObjectTypeInfoVI
221 /// @note
222 /// May be used only when type family is eTypeFamilyChoice
223 CVariantIterator FindVariant(const string& memberName) const;
224
225 /// Find choice variant index by its name
226 ///
227 /// @sa CObjectTypeInfoVI
228 /// @note
229 /// May be used only when type family is eTypeFamilyChoice
230 TMemberIndex FindVariantIndex(const string& name) const;
231
232 /// Find choice variant by its numerical tag
233 ///
234 /// @sa CObjectTypeInfoVI
235 /// @note
236 /// May be used only when type family is eTypeFamilyChoice
237 CVariantIterator FindVariantByTag(int memberTag) const;
238
239 /// Find choice variant index by its numerical tag
240 ///
241 /// @sa CObjectTypeInfoVI
242 /// @note
243 /// May be used only when type family is eTypeFamilyChoice
244 TMemberIndex FindVariantIndex(int tag) const;
245
246 // --------------------------------------------------
247 // pointer interface
248 // only when GetTypeFamily() == eTypeFamilyPointer
249
250 /// Get type information of data to which this type refers
251 ///
252 /// @note
253 /// May be used only when tyep family is eTypeFamilyPointer
254 CObjectTypeInfo GetPointedType(void) const;
255
256 // --------------------------------------------------
257 // hooks
258
259 /// Set local (for the specified stream) read hook
260 /// @param stream
261 /// Input data stream reader
262 /// @param hook
263 /// Pointer to hook object
264 void SetLocalReadHook(CObjectIStream& stream,
265 CReadObjectHook* hook) const;
266
267 /// Set global (for all streams) read hook
268 /// @param hook
269 /// Pointer to hook object
270 void SetGlobalReadHook(CReadObjectHook* hook) const;
271
272 /// Reset local read hook
273 /// @param stream
274 /// Input data stream reader
275 void ResetLocalReadHook(CObjectIStream& stream) const;
276
277 /// Reset global read hooks
278 void ResetGlobalReadHook(void) const;
279
280 /// Set local context-specific read hook
281 /// @param stream
282 /// Input data stream reader
283 /// @param path
284 /// Context (stack path)
285 /// @param hook
286 /// Pointer to hook object
287 void SetPathReadHook(CObjectIStream* stream, const string& path,
288 CReadObjectHook* hook) const;
289
290
291 /// Set local (for the specified stream) write hook
292 /// @param stream
293 /// Output data stream writer
294 /// @param hook
295 /// Pointer to hook object
296 void SetLocalWriteHook(CObjectOStream& stream,
297 CWriteObjectHook* hook) const;
298
299 /// Set global (for all streams) write hook
300 /// @param hook
301 /// Pointer to hook object
302 void SetGlobalWriteHook(CWriteObjectHook* hook) const;
303
304 /// Reset local write hook
305 /// @param stream
306 /// Output data stream writer
307 void ResetLocalWriteHook(CObjectOStream& stream) const;
308
309 /// Reset global write hooks
310 void ResetGlobalWriteHook(void) const;
311
312 /// Set local context-specific write hook
313 /// @param stream
314 /// Output data stream writer
315 /// @param path
316 /// Context (stack path)
317 /// @param hook
318 /// Pointer to hook object
319 void SetPathWriteHook(CObjectOStream* stream, const string& path,
320 CWriteObjectHook* hook) const;
321
322
323 /// Set local (for the specified stream) skip hook
324 /// @param stream
325 /// Input data stream reader
326 /// @param hook
327 /// Pointer to hook object
328 void SetLocalSkipHook(CObjectIStream& stream,
329 CSkipObjectHook* hook) const;
330
331 /// Reset local skip hook
332 /// @param stream
333 /// Input data stream reader
334 void ResetLocalSkipHook(CObjectIStream& stream) const;
335
336 /// Set local context-specific skip hook
337 /// @param stream
338 /// Input data stream reader
339 /// @param path
340 /// Context (stack path)
341 /// @param hook
342 /// Pointer to hook object
343 void SetPathSkipHook(CObjectIStream* stream, const string& path,
344 CSkipObjectHook* hook) const;
345
346
347 /// Set local (for the specified stream) copy hook
348 /// @param stream
349 /// Data copier
350 /// @param hook
351 /// Pointer to hook object
352 void SetLocalCopyHook(CObjectStreamCopier& stream,
353 CCopyObjectHook* hook) const;
354
355 /// Set global (for all streams) copy hook
356 /// @param hook
357 /// Pointer to hook object
358 void SetGlobalCopyHook(CCopyObjectHook* hook) const;
359
360 /// Reset local copy hook
361 /// @param stream
362 /// Data copier
363 void ResetLocalCopyHook(CObjectStreamCopier& stream) const;
364
365 /// Reset global read hooks
366 void ResetGlobalCopyHook(void) const;
367
368 /// Set local context-specific copy hook
369 /// @param stream
370 /// Data copier
371 /// @param path
372 /// Context (stack path)
373 /// @param hook
374 /// Pointer to hook object
375 void SetPathCopyHook(CObjectStreamCopier* stream, const string& path,
376 CCopyObjectHook* hook) const;
377
378 public:
379 // mostly for internal use
380 TTypeInfo GetTypeInfo(void) const;
381 const CPrimitiveTypeInfo* GetPrimitiveTypeInfo(void) const;
382 const CEnumeratedTypeInfo* GetEnumeratedTypeInfo(void) const;
383 const CClassTypeInfo* GetClassTypeInfo(void) const;
384 const CChoiceTypeInfo* GetChoiceTypeInfo(void) const;
385 const CContainerTypeInfo* GetContainerTypeInfo(void) const;
386 const CPointerTypeInfo* GetPointerTypeInfo(void) const;
387
388 CMemberIterator GetMemberIterator(TMemberIndex index) const;
389 CVariantIterator GetVariantIterator(TMemberIndex index) const;
390
391 typedef int TASNTag;
392 TASNTag GetASNTag() const;
393
394 protected:
395 void ResetTypeInfo(void);
396 void SetTypeInfo(TTypeInfo typeinfo);
397
398 void CheckTypeFamily(ETypeFamily family) const;
399 void WrongTypeFamily(ETypeFamily needFamily) const;
400
401 private:
402 TTypeInfo m_TypeInfo;
403
404 private:
405 CTypeInfo* GetNCTypeInfo(void) const;
406
407 bool MatchPattern(vector<int>& pattern, size_t& pos, int depth,
408 const CItemInfo* item = NULL) const;
409 friend class CObjectIStreamAsnBinary;
410 };
411
412
413 /////////////////////////////////////////////////////////////////////////////
414 ///
415 /// CConstObjectInfo --
416 ///
417 /// Facilitate read access to a particular instance of an object
418 /// of the specified type.
419
420 class NCBI_XSERIAL_EXPORT CConstObjectInfo : public CObjectTypeInfo
421 {
422 public:
423 typedef TConstObjectPtr TObjectPtrType;
424 typedef CConstObjectInfoEI CElementIterator;
425 typedef CConstObjectInfoMI CMemberIterator;
426 typedef CConstObjectInfoCV CChoiceVariant;
427
428 enum ENonCObject {
429 eNonCObject
430 };
431
432 /// Create empty CObjectInfo
433 CConstObjectInfo(void);
434 /// Initialize CObjectInfo
435 CConstObjectInfo(TConstObjectPtr objectPtr, TTypeInfo typeInfo);
436 CConstObjectInfo(pair<TConstObjectPtr, TTypeInfo> object);
437 CConstObjectInfo(pair<TObjectPtr, TTypeInfo> object);
438 /// Initialize CObjectInfo when we are sure that object
439 /// is not inherited from CObject (for efficiency)
440 CConstObjectInfo(TConstObjectPtr objectPtr, TTypeInfo typeInfo,
441 ENonCObject nonCObject);
442
443 /// Reset CObjectInfo to empty state
444 void Reset(void);
445 /// Set CObjectInfo
446 CConstObjectInfo& operator=(pair<TConstObjectPtr, TTypeInfo> object);
447 CConstObjectInfo& operator=(pair<TObjectPtr, TTypeInfo> object);
448
operator ==(const CConstObjectInfo & obj) const449 bool operator==(const CConstObjectInfo& obj) const
450 {
451 return m_ObjectPtr == obj.m_ObjectPtr;
452 }
operator !=(const CConstObjectInfo & obj) const453 bool operator!=(const CConstObjectInfo& obj) const
454 {
455 return m_ObjectPtr != obj.m_ObjectPtr;
456 }
457
458 /// Get pointer to object
459 TConstObjectPtr GetObjectPtr(void) const;
460 pair<TConstObjectPtr, TTypeInfo> GetPair(void) const;
461
462 // --------------------------------------------------
463 // primitive type interface
464
465 /// Get boolean data
466 /// @note
467 /// Value type must be compatible with the request
468 bool GetPrimitiveValueBool(void) const;
469 /// Get char data
470 char GetPrimitiveValueChar(void) const;
471
472 /// Get data as Int4
473 Int4 GetPrimitiveValueInt4(void) const;
474 /// Get data as Uint4
475 Uint4 GetPrimitiveValueUint4(void) const;
476 /// Get data as Int8
477 Int8 GetPrimitiveValueInt8(void) const;
478 /// Get data as Uint8
479 Uint8 GetPrimitiveValueUint8(void) const;
480 /// Get data as int
481 int GetPrimitiveValueInt(void) const;
482 /// Get data as unsigned int
483 unsigned GetPrimitiveValueUInt(void) const;
484 /// Get data as long
485 long GetPrimitiveValueLong(void) const;
486 /// Get data as unsigned loch
487 unsigned long GetPrimitiveValueULong(void) const;
488
489 /// Get data as double
490 double GetPrimitiveValueDouble(void) const;
491
492 /// Get string data
493 void GetPrimitiveValueString(string& value) const;
494 /// Get string data
495 string GetPrimitiveValueString(void) const;
496
497 /// Get octet string data
498 void GetPrimitiveValueOctetString(vector<char>& value) const;
499
500 /// Get bit string data
501 void GetPrimitiveValueBitString(CBitString& value) const;
502
503 /// Get data as CAnyContentObject
504 /// @sa CAnyContentObject
505 void GetPrimitiveValueAnyContent(CAnyContentObject& value) const;
506
507 // --------------------------------------------------
508 // class interface
509
510 /// Create class member iterator
511 ///
512 /// @sa CConstObjectInfoMI
513 /// @note
514 /// May be used only when type family is eTypeFamilyClass
515 CMemberIterator BeginMembers(void) const;
516
517 /// Create class member iterator that initially points to specified member
518 ///
519 /// @param index
520 /// Index of the member
521 /// @sa CConstObjectInfoMI
522 /// @note
523 /// May be used only when type family is eTypeFamilyClass
524 CMemberIterator GetClassMemberIterator(TMemberIndex index) const;
525
526 /// Find class member by its name
527 ///
528 /// @sa CConstObjectInfoMI
529 /// @note
530 /// May be used only when type family is eTypeFamilyClass
531 CMemberIterator FindClassMember(const string& memberName) const;
532
533 /// Find class member by its numerical tag
534 ///
535 /// @sa CConstObjectInfoMI
536 /// @note
537 /// May be used only when type family is eTypeFamilyClass
538 CMemberIterator FindClassMemberByTag(int memberTag) const;
539
540 /// Find class member by type iterator
541 ///
542 /// @sa CConstObjectInfoMI, CObjectTypeInfoMI
543 /// @note
544 /// May be used only when type family is eTypeFamilyClass
545 CMemberIterator GetMember(CObjectTypeInfo::CMemberIterator m) const;
546
547 // --------------------------------------------------
548 // choice interface
549
550 /// Get index of currently selected choice variant
551 ///
552 /// @note
553 /// May be used only when type family is eTypeFamilyChoice
554 TMemberIndex GetCurrentChoiceVariantIndex(void) const;
555
556 /// Get data and type information of selected choice variant
557 ///
558 /// @sa CConstObjectInfoCV
559 CChoiceVariant GetCurrentChoiceVariant(void) const;
560
561 // --------------------------------------------------
562 // pointer interface
563
564 /// Get data and type information of object to which this type refers
565 ///
566 /// @note
567 /// May be used only when type family is eTypeFamilyPointer
568 CConstObjectInfo GetPointedObject(void) const;
569
570 // --------------------------------------------------
571 // container interface
572
573 /// Create container elements iterator
574 ///
575 /// @sa CConstObjectInfoEI
576 /// @note
577 /// May be used only when type family is eTypeFamilyContainer
578 CElementIterator BeginElements(void) const;
579
580 protected:
581 void ResetObjectPtr(void);
582 void Set(TConstObjectPtr objectPtr, TTypeInfo typeInfo);
583
584 private:
585 TConstObjectPtr m_ObjectPtr; // object pointer
586 CConstRef<CObject> m_Ref; // hold reference to CObject for correct removal
587 };
588
589 /////////////////////////////////////////////////////////////////////////////
590 ///
591 /// CObjectInfo --
592 ///
593 /// Facilitate read/write access to a particular instance of an object
594 /// of the specified type.
595
596 class NCBI_XSERIAL_EXPORT CObjectInfo : public CConstObjectInfo
597 {
598 typedef CConstObjectInfo CParent;
599 public:
600 typedef TObjectPtr TObjectPtrType;
601 typedef CObjectInfoEI CElementIterator;
602 typedef CObjectInfoMI CMemberIterator;
603 typedef CObjectInfoCV CChoiceVariant;
604
605 /// Create empty CObjectInfo
606 CObjectInfo(void);
607
608 /// Initialize CObjectInfo
609 CObjectInfo(TObjectPtr objectPtr, TTypeInfo typeInfo);
610 CObjectInfo(pair<TObjectPtr, TTypeInfo> object);
611
612 /// Initialize CObjectInfo when we are sure that object
613 /// is not inherited from CObject (for efficiency)
614 CObjectInfo(TObjectPtr objectPtr, TTypeInfo typeInfo,
615 ENonCObject nonCObject);
616
617 /// Create CObjectInfo with new object
618 explicit CObjectInfo(TTypeInfo typeInfo);
619 explicit CObjectInfo(const CObjectTypeInfo& type);
620
621 /// Set CObjectInfo to point to another object
622 CObjectInfo& operator=(pair<TObjectPtr, TTypeInfo> object);
623
624 /// Get pointer to object
625 TObjectPtr GetObjectPtr(void) const;
626 pair<TObjectPtr, TTypeInfo> GetPair(void) const;
627
628 // --------------------------------------------------
629 // primitive type interface
630
631 /// Set boolean data
632 /// @note
633 /// Value type must be compatible with the request
634 void SetPrimitiveValueBool(bool value);
635 void SetPrimitiveValueChar(char value);
636
637 void SetPrimitiveValueInt4(Int4 value);
638 void SetPrimitiveValueUint4(Uint4 value);
639 void SetPrimitiveValueInt8(Int8 value);
640 void SetPrimitiveValueUint8(Uint8 value);
641 void SetPrimitiveValueInt(int value);
642 void SetPrimitiveValueUInt(unsigned value);
643 void SetPrimitiveValueLong(long value);
644 void SetPrimitiveValueULong(unsigned long value);
645
646 void SetPrimitiveValueDouble(double value);
647
648 void SetPrimitiveValueString(const string& value);
649
650 void SetPrimitiveValueOctetString(const vector<char>& value);
651
652 void SetPrimitiveValueBitString(const CBitString& value);
653
654 void SetPrimitiveValueAnyContent(const CAnyContentObject& value);
655
656
657 // --------------------------------------------------
658 // class interface
659
660 /// Find class member by type iterator
661 ///
662 /// @sa CObjectInfoMI, CObjectTypeInfoMI
663 /// @note
664 /// May be used only when type family is eTypeFamilyClass
665 CMemberIterator GetMember(CObjectTypeInfo::CMemberIterator m) const;
666
667 /// Create class member iterator
668 ///
669 /// @sa CObjectInfoMI
670 /// @note
671 /// May be used only when type family is eTypeFamilyClass
672 CMemberIterator BeginMembers(void) const;
673
674 /// Create class member iterator that initially points to specified member
675 ///
676 /// @param index
677 /// Index of the member
678 /// @sa CObjectInfoMI
679 /// @note
680 /// May be used only when type family is eTypeFamilyClass
681 CMemberIterator GetClassMemberIterator(TMemberIndex index) const;
682
683 /// Find class member by its name
684 ///
685 /// @sa CObjectInfoMI
686 /// @note
687 /// May be used only when type family is eTypeFamilyClass
688 CMemberIterator FindClassMember(const string& memberName) const;
689
690 /// Find class member by its numerical tag
691 ///
692 /// @sa CObjectInfoMI
693 /// @note
694 /// May be used only when type family is eTypeFamilyClass
695 CMemberIterator FindClassMemberByTag(int memberTag) const;
696
697 /// Create member if necessary and return member object
698 CObjectInfo SetClassMember(TMemberIndex index) const;
699
700
701 // --------------------------------------------------
702 // choice interface
703
704 /// Get data and type information of selected choice variant
705 ///
706 /// @sa CObjectInfoCV
707 /// @note
708 /// May be used only when type family is eTypeFamilyChoice
709 CChoiceVariant GetCurrentChoiceVariant(void) const;
710
711 /// Select choice variant, if necessary, and return variant object
712 ///
713 /// @note
714 /// May be used only when type family is eTypeFamilyChoice
715 CObjectInfo SetChoiceVariant(TMemberIndex index) const;
716
717 // --------------------------------------------------
718 // pointer interface
719
720 /// Get data and type information of object to which this type refers
721 ///
722 /// @note
723 /// May be used only when type family is eTypeFamilyPointer
724 CObjectInfo GetPointedObject(void) const;
725
726 /// Create if necessary and return pointed object
727 ///
728 /// @note
729 /// May be used only when type family is eTypeFamilyPointer
730 CObjectInfo SetPointedObject(void) const;
731
732 // --------------------------------------------------
733 // container interface
734
735 /// Create container elements iterator
736 ///
737 /// @sa CObjectInfoEI
738 /// @note
739 /// May be used only when type family is eTypeFamilyContainer
740 CElementIterator BeginElements(void) const;
741
742 /// Read element data from stream
743 void ReadContainer(CObjectIStream& in, CReadContainerElementHook& hook);
744
745 /// Add and return new element object
746 CObjectInfo AddNewElement(void) const;
747
748 /// add new pointer element, create new pointed object and return it
749 CObjectInfo AddNewPointedElement(void) const;
750 };
751
752 // get starting point of object hierarchy
753 template<class C>
754 inline
ObjectType(const C &)755 TTypeInfo ObjectType(const C& /*obj*/)
756 {
757 return C::GetTypeInfo();
758 }
759
760 template<class C>
761 inline
ObjectInfo(C & obj)762 pair<TObjectPtr, TTypeInfo> ObjectInfo(C& obj)
763 {
764 return pair<TObjectPtr, TTypeInfo>(&obj, C::GetTypeInfo());
765 }
766
767 // get starting point of non-modifiable object hierarchy
768 template<class C>
769 inline
ConstObjectInfo(const C & obj)770 pair<TConstObjectPtr, TTypeInfo> ConstObjectInfo(const C& obj)
771 {
772 return pair<TConstObjectPtr, TTypeInfo>(&obj, C::GetTypeInfo());
773 }
774
775 template<class C>
776 inline
ObjectInfo(const C & obj)777 pair<TConstObjectPtr, TTypeInfo> ObjectInfo(const C& obj)
778 {
779 return pair<TConstObjectPtr, TTypeInfo>(&obj, C::GetTypeInfo());
780 }
781
782 template<class C>
783 inline
RefChoiceInfo(CRef<C> & obj)784 pair<TObjectPtr, TTypeInfo> RefChoiceInfo(CRef<C>& obj)
785 {
786 return pair<TObjectPtr, TTypeInfo>(&obj, C::GetRefChoiceTypeInfo());
787 }
788
789 template<class C>
790 inline
ConstRefChoiceInfo(const CRef<C> & obj)791 pair<TConstObjectPtr, TTypeInfo> ConstRefChoiceInfo(const CRef<C>& obj)
792 {
793 return pair<TConstObjectPtr, TTypeInfo>(&obj, C::GetRefChoiceTypeInfo());
794 }
795
796
797 /* @} */
798
799
800 #include <serial/impl/objectinfo.inl>
801
802 END_NCBI_SCOPE
803
804 #endif /* OBJECTINFO__HPP */
805