1 #ifndef STLTYPESIMPL__HPP
2 #define STLTYPESIMPL__HPP
3 
4 /*  $Id: stltypesimpl.hpp 547351 2017-09-28 13:18:13Z gouriano $
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 *   !!! PUT YOUR DESCRIPTION HERE !!!
33 */
34 
35 #include <corelib/ncbistd.hpp>
36 #include <serial/serialdef.hpp>
37 #include <serial/impl/continfo.hpp>
38 #include <serial/impl/memberid.hpp>
39 
40 
41 /** @addtogroup TypeInfoCPP
42  *
43  * @{
44  */
45 
46 
47 BEGIN_NCBI_SCOPE
48 
49 class NCBI_XSERIAL_EXPORT CStlClassInfoUtil
50 {
51 public:
52     static TTypeInfo Get_auto_ptr(TTypeInfo arg, TTypeInfoCreator1 f);
53     static TTypeInfo Get_CRef(TTypeInfo arg, TTypeInfoCreator1 f);
54     static TTypeInfo Get_CConstRef(TTypeInfo arg, TTypeInfoCreator1 f);
55     static TTypeInfo Get_AutoPtr(TTypeInfo arg, TTypeInfoCreator1 f);
56     static TTypeInfo Get_list(TTypeInfo arg, TTypeInfoCreator1 f);
57     static TTypeInfo GetSet_list(TTypeInfo arg, TTypeInfoCreator1 f);
58     static TTypeInfo Get_vector(TTypeInfo arg, TTypeInfoCreator1 f);
59     static TTypeInfo GetSet_vector(TTypeInfo arg, TTypeInfoCreator1 f);
60     static TTypeInfo Get_set(TTypeInfo arg, TTypeInfoCreator1 f);
61     static TTypeInfo Get_multiset(TTypeInfo arg, TTypeInfoCreator1 f);
62     static TTypeInfo Get_map(TTypeInfo arg1, TTypeInfo arg2,
63                              TTypeInfoCreator2 f);
64     static TTypeInfo Get_multimap(TTypeInfo arg1, TTypeInfo arg2,
65                                   TTypeInfoCreator2 f);
66     static TTypeInfo GetInfo(TTypeInfo& storage,
67                              TTypeInfo arg, TTypeInfoCreator1 f);
68     static TTypeInfo GetInfo(TTypeInfo& storage,
69                              TTypeInfo arg1, TTypeInfo arg2,
70                              TTypeInfoCreator2 f);
71 
72     // throw exceptions
73     NCBI_NORETURN
74     static void ThrowDuplicateElementError(void);
75     NCBI_NORETURN
76     static void CannotGetElementOfSet(void);
77 };
78 
79 class NCBI_XSERIAL_EXPORT CStlOneArgTemplate : public CContainerTypeInfo
80 {
81     typedef CContainerTypeInfo CParent;
82 public:
83     CStlOneArgTemplate(size_t size, TTypeInfo dataType,
84                        bool randomOrder, const string& name);
85     CStlOneArgTemplate(size_t size, TTypeInfo dataType,
86                        bool randomOrder);
87     CStlOneArgTemplate(size_t size, const CTypeRef& dataType,
88                        bool randomOrder);
89 
GetDataId(void) const90     const CMemberId& GetDataId(void) const
91         {
92             return m_DataId;
93         }
94     void SetDataId(const CMemberId& id);
95 
96     virtual bool IsDefault(TConstObjectPtr objectPtr) const override;
97     virtual void SetDefault(TObjectPtr objectPtr) const override;
98 
99     // private use
100     typedef bool (*TIsDefaultFunction)(TConstObjectPtr objectPtr);
101     typedef void (*TSetDefaultFunction)(TObjectPtr objectPtr);
102 
103     void SetMemFunctions(TTypeCreate create,
104                          TIsDefaultFunction isDefault,
105                          TSetDefaultFunction setDefault);
106 
107 private:
108     TIsDefaultFunction m_IsDefault;
109     TSetDefaultFunction m_SetDefault;
110 
111     CMemberId m_DataId;
112 };
113 
114 class NCBI_XSERIAL_EXPORT CStlTwoArgsTemplate : public CStlOneArgTemplate
115 {
116     typedef CStlOneArgTemplate CParent;
117 public:
118     CStlTwoArgsTemplate(size_t size,
119                         TTypeInfo keyType, TPointerOffsetType keyOffset,
120                         TTypeInfo valueType, TPointerOffsetType valueOffset,
121                         bool randomOrder);
122     CStlTwoArgsTemplate(size_t size,
123                         const CTypeRef& keyType, TPointerOffsetType keyOffset,
124                         const CTypeRef& valueType, TPointerOffsetType valueOffset,
125                         bool randomOrder);
126 
GetKeyId(void) const127     const CMemberId& GetKeyId(void) const
128         {
129             return m_KeyId;
130         }
GetValueId(void) const131     const CMemberId& GetValueId(void) const
132         {
133             return m_ValueId;
134         }
135     void SetKeyId(const CMemberId& id);
136     void SetValueId(const CMemberId& id);
137 
138 private:
139     CMemberId m_KeyId;
140     CTypeRef m_KeyType;
141     TPointerOffsetType m_KeyOffset;
142 
143     CMemberId m_ValueId;
144     CTypeRef m_ValueType;
145     TPointerOffsetType m_ValueOffset;
146 
147     static TTypeInfo CreateElementTypeInfo(TTypeInfo info);
148 };
149 
150 END_NCBI_SCOPE
151 
152 #endif  /* STLTYPESIMPL__HPP */
153 
154 
155 /* @} */
156