stltypes.hpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:35k
源码类别:

生物技术

开发平台:

C/C++

  1. /*
  2.  * ===========================================================================
  3.  * PRODUCTION $Log: stltypes.hpp,v $
  4.  * PRODUCTION Revision 1000.2  2004/06/01 19:39:10  gouriano
  5.  * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.69
  6.  * PRODUCTION
  7.  * ===========================================================================
  8.  */
  9. #ifndef STLTYPES__HPP
  10. #define STLTYPES__HPP
  11. /*  $Id: stltypes.hpp,v 1000.2 2004/06/01 19:39:10 gouriano Exp $
  12. * ===========================================================================
  13. *
  14. *                            PUBLIC DOMAIN NOTICE
  15. *               National Center for Biotechnology Information
  16. *
  17. *  This software/database is a "United States Government Work" under the
  18. *  terms of the United States Copyright Act.  It was written as part of
  19. *  the author's official duties as a United States Government employee and
  20. *  thus cannot be copyrighted.  This software/database is freely available
  21. *  to the public for use. The National Library of Medicine and the U.S.
  22. *  Government have not placed any restriction on its use or reproduction.
  23. *
  24. *  Although all reasonable efforts have been taken to ensure the accuracy
  25. *  and reliability of the software and data, the NLM and the U.S.
  26. *  Government do not and cannot warrant the performance or results that
  27. *  may be obtained by using this software or data. The NLM and the U.S.
  28. *  Government disclaim all warranties, express or implied, including
  29. *  warranties of performance, merchantability or fitness for any particular
  30. *  purpose.
  31. *
  32. *  Please cite the author in any work or product based on this material.
  33. *
  34. * ===========================================================================
  35. *
  36. * Author: Eugene Vasilchenko
  37. *
  38. * File Description:
  39. *   !!! PUT YOUR DESCRIPTION HERE !!!
  40. */
  41. #include <corelib/ncbistd.hpp>
  42. #include <corelib/ncbiobj.hpp>
  43. #include <corelib/ncbiutil.hpp>
  44. #include <set>
  45. #include <map>
  46. #include <list>
  47. #include <vector>
  48. #include <memory>
  49. #include <serial/serialutil.hpp>
  50. #include <serial/stltypesimpl.hpp>
  51. #include <serial/ptrinfo.hpp>
  52. #include <serial/objistr.hpp>
  53. /** @addtogroup TypeInfoCPP
  54.  *
  55.  * @{
  56.  */
  57. BEGIN_NCBI_SCOPE
  58. template<typename Data>
  59. class CStlClassInfo_auto_ptr
  60. {
  61. public:
  62.     typedef Data TDataType;
  63.     typedef auto_ptr<TDataType> TObjectType;
  64.     static TTypeInfo GetTypeInfo(TTypeInfo dataType)
  65.         {
  66.             return CStlClassInfoUtil::Get_auto_ptr(dataType, &CreateTypeInfo);
  67.         }
  68.     static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)
  69.         {
  70.             CPointerTypeInfo* typeInfo =
  71.                 new CPointerTypeInfo(sizeof(TObjectType), dataType);
  72.             typeInfo->SetFunctions(&GetData, &SetData);
  73.             return typeInfo;
  74.         }
  75. protected:
  76.     static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,
  77.                               TObjectPtr objectPtr)
  78.         {
  79.             return CTypeConverter<TObjectType>::Get(objectPtr).get();
  80.         }
  81.     static void SetData(const CPointerTypeInfo* /*objectType*/,
  82.                         TObjectPtr objectPtr,
  83.                         TObjectPtr dataPtr)
  84.         {
  85.             CTypeConverter<TObjectType>::Get(objectPtr).
  86.                 reset(&CTypeConverter<TDataType>::Get(dataPtr));
  87.         }
  88. };
  89. template<typename Data>
  90. class CRefTypeInfo
  91. {
  92. public:
  93.     typedef Data TDataType;
  94.     typedef CRef<TDataType> TObjectType;
  95.     static TTypeInfo GetTypeInfo(TTypeInfo dataType)
  96.         {
  97.             return CStlClassInfoUtil::Get_CRef(dataType, &CreateTypeInfo);
  98.         }
  99.     static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)
  100.         {
  101.             CPointerTypeInfo* typeInfo =
  102.                 new CPointerTypeInfo(sizeof(TObjectType), dataType);
  103.             typeInfo->SetFunctions(&GetData, &SetData);
  104.             return typeInfo;
  105.         }
  106. protected:
  107.     static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,
  108.                               TObjectPtr objectPtr)
  109.         {
  110.             return CTypeConverter<TObjectType>::Get(objectPtr).GetPointer();
  111.         }
  112.     static void SetData(const CPointerTypeInfo* /*objectType*/,
  113.                         TObjectPtr objectPtr,
  114.                         TObjectPtr dataPtr)
  115.         {
  116.             CTypeConverter<TObjectType>::Get(objectPtr).
  117.                 Reset(&CTypeConverter<TDataType>::Get(dataPtr));
  118.         }
  119. };
  120. template<typename Data>
  121. class CConstRefTypeInfo
  122. {
  123. public:
  124.     typedef Data TDataType;
  125.     typedef CConstRef<TDataType> TObjectType;
  126.     static TTypeInfo GetTypeInfo(TTypeInfo dataType)
  127.         {
  128.             return CStlClassInfoUtil::Get_CConstRef(dataType, &CreateTypeInfo);
  129.         }
  130.     static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)
  131.         {
  132.             CPointerTypeInfo* typeInfo =
  133.                 new CPointerTypeInfo(sizeof(TObjectType), dataType);
  134.             typeInfo->SetFunctions(&GetData, &SetData);
  135.             return typeInfo;
  136.         }
  137. protected:
  138.     static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,
  139.                                    TObjectPtr objectPtr)
  140.         {
  141.             // Bleh.  Need to return a void* rather than a const Data*
  142.             return const_cast<TDataType*>
  143.                 (CTypeConverter<TObjectType>::Get(objectPtr).GetPointer());
  144.         }
  145.     static void SetData(const CPointerTypeInfo* /*objectType*/,
  146.                         TObjectPtr objectPtr,
  147.                         TObjectPtr dataPtr)
  148.         {
  149.             CTypeConverter<TObjectType>::Get(objectPtr).
  150.                 Reset(&CTypeConverter<TDataType>::Get(dataPtr));
  151.         }
  152. };
  153. template<typename Data>
  154. class CAutoPtrTypeInfo
  155. {
  156. public:
  157.     typedef Data TDataType;
  158.     typedef AutoPtr<TDataType> TObjectType;
  159.     static TTypeInfo GetTypeInfo(TTypeInfo dataType)
  160.         {
  161.             return CStlClassInfoUtil::Get_AutoPtr(dataType, &CreateTypeInfo);
  162.         }
  163.     static CTypeInfo* CreateTypeInfo(TTypeInfo dataType)
  164.         {
  165.             CPointerTypeInfo* typeInfo =
  166.                 new CPointerTypeInfo(sizeof(TObjectType), dataType);
  167.             typeInfo->SetFunctions(&GetData, &SetData);
  168.             return typeInfo;
  169.         }
  170. protected:
  171.     static TObjectPtr GetData(const CPointerTypeInfo* /*objectType*/,
  172.                               TObjectPtr objectPtr)
  173.         {
  174.             return CTypeConverter<TObjectType>::Get(objectPtr).get();
  175.         }
  176.     static void SetData(const CPointerTypeInfo* /*objectType*/,
  177.                         TObjectPtr objectPtr,
  178.                         TObjectPtr dataPtr)
  179.         {
  180.             CTypeConverter<TObjectType>::Get(objectPtr).
  181.                 reset(&CTypeConverter<TDataType>::Get(dataPtr));
  182.         }
  183. };
  184. template<class Container>
  185. class CStlClassInfoFunctions
  186. {
  187. public:
  188.     typedef Container TObjectType;
  189.     typedef typename TObjectType::value_type TElementType;
  190.     static TObjectType& Get(TObjectPtr objectPtr)
  191.         {
  192.             return CTypeConverter<TObjectType>::Get(objectPtr);
  193.         }
  194.     static const TObjectType& Get(TConstObjectPtr objectPtr)
  195.         {
  196.             return CTypeConverter<TObjectType>::Get(objectPtr);
  197.         }
  198.     static TObjectPtr CreateContainer(TTypeInfo /*objectType*/)
  199.         {
  200.             return new TObjectType();
  201.         }
  202.     static bool IsDefault(TConstObjectPtr objectPtr)
  203.         {
  204.             return Get(objectPtr).empty();
  205.         }
  206.     static void SetDefault(TObjectPtr objectPtr)
  207.         {
  208.             Get(objectPtr).clear();
  209.         }
  210.     static void AddElement(const CContainerTypeInfo* containerType,
  211.                            TObjectPtr containerPtr, TConstObjectPtr elementPtr,
  212.                            ESerialRecursionMode how = eRecursive)
  213.         {
  214.             TObjectType& container = Get(containerPtr);
  215. #if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)
  216.             container.allocation_size(container.size());
  217. #endif
  218.             //container.push_back(CTypeConverter<TElementType>::Get(elementPtr));
  219.             TElementType elm;
  220.             containerType->GetElementType()->Assign
  221.                 (&elm, &CTypeConverter<TElementType>::Get(elementPtr), how);
  222.             container.push_back(elm);
  223.         }
  224.     static void AddElementIn(const CContainerTypeInfo* containerType,
  225.                              TObjectPtr containerPtr, CObjectIStream& in)
  226.         {
  227.             TObjectType& container = Get(containerPtr);
  228. #if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)
  229.             container.allocation_size(container.size());
  230. #endif
  231.             container.push_back(TElementType());
  232.             containerType->GetElementType()->ReadData(in, &container.back());
  233.             if (in.GetDiscardCurrObject()) {
  234.                 container.pop_back();
  235.                 in.SetDiscardCurrObject(false);
  236.             }
  237.         }
  238.     static void SetMemFunctions(CStlOneArgTemplate* info)
  239.         {
  240.             info->SetMemFunctions(&CreateContainer, &IsDefault, &SetDefault);
  241.         }
  242.     static void SetAddElementFunctions(CStlOneArgTemplate* info)
  243.         {
  244.             info->SetAddElementFunctions(&AddElement, &AddElementIn);
  245.         }
  246. };
  247. template<class Container>
  248. class CStlClassInfoFunctions_set : public CStlClassInfoFunctions<Container>
  249. {
  250.     typedef CStlClassInfoFunctions<Container> CParent;
  251. public:
  252.     typedef typename CParent::TObjectType TObjectType;
  253.     typedef typename TObjectType::value_type TElementType;
  254.     static void InsertElement(TObjectPtr containerPtr,
  255.                               const TElementType& element)
  256.         {
  257.             TObjectType& container = CParent::Get(containerPtr);
  258. #if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)
  259.             container.allocation_size(container.size());
  260. #endif
  261.             if ( !container.insert(element).second )
  262.                 CStlClassInfoUtil::ThrowDuplicateElementError();
  263.         }
  264.     static void AddElement(const CContainerTypeInfo* /*containerType*/,
  265.                            TObjectPtr containerPtr, TConstObjectPtr elementPtr,
  266.                            ESerialRecursionMode how = eRecursive)
  267.         {
  268.             InsertElement(containerPtr,
  269.                           CTypeConverter<TElementType>::Get(elementPtr));
  270.         }
  271.     static void AddElementIn(const CContainerTypeInfo* containerType,
  272.                              TObjectPtr containerPtr, CObjectIStream& in)
  273.         {
  274.             TElementType data;
  275.             containerType->GetElementType()->ReadData(in, &data);
  276.             InsertElement(containerPtr, data);
  277.         }
  278.     static void SetAddElementFunctions(CStlOneArgTemplate* info)
  279.         {
  280.             info->SetAddElementFunctions(&AddElement, &AddElementIn);
  281.         }
  282. };
  283. template<class Container>
  284. class CStlClassInfoFunctions_multiset :
  285.     public CStlClassInfoFunctions<Container>
  286. {
  287.     typedef CStlClassInfoFunctions<Container> CParent;
  288. public:
  289.     typedef typename CParent::TObjectType TObjectType;
  290.     typedef typename TObjectType::value_type TElementType;
  291.     static void InsertElement(TObjectPtr containerPtr,
  292.                               const TElementType& element)
  293.         {
  294.             TObjectType& container = CParent::Get(containerPtr);
  295. #if defined(_RWSTD_VER) && !defined(_RWSTD_STRICT_ANSI)
  296.             container.allocation_size(container.size());
  297. #endif
  298.             container.insert(element);
  299.         }
  300.     static void AddElement(const CContainerTypeInfo* /*containerType*/,
  301.                            TObjectPtr containerPtr, TConstObjectPtr elementPtr,
  302.                            ESerialRecursionMode how = eRecursive)
  303.         {
  304.             InsertElement(containerPtr,
  305.                           CTypeConverter<TElementType>::Get(elementPtr));
  306.         }
  307.     static void AddElementIn(const CContainerTypeInfo* containerType,
  308.                              TObjectPtr containerPtr, CObjectIStream& in)
  309.         {
  310.             TElementType data;
  311.             containerType->GetElementType()->ReadData(in, &data);
  312.             InsertElement(containerPtr, data);
  313.         }
  314.     static void SetAddElementFunctions(CStlOneArgTemplate* info)
  315.         {
  316.             info->SetAddElementFunctions(&AddElement, &AddElementIn);
  317.         }
  318. };
  319. template<class Container, class StlIterator,
  320.     typename ContainerPtr, typename ElementRef,
  321.     class TypeInfoIterator>
  322. class CStlClassInfoFunctionsIBase :
  323.     public CStlClassInfoFunctions<Container>
  324. {
  325. public:
  326.     typedef StlIterator TStlIterator;
  327.     typedef TypeInfoIterator TTypeInfoIterator;
  328.     typedef typename TTypeInfoIterator::TObjectPtr TObjectPtr;
  329.     static TStlIterator& It(TTypeInfoIterator& iter)
  330.         {
  331.             if ( sizeof(TStlIterator) <= sizeof(iter.m_IteratorData) ) {
  332.                 void* data = &iter.m_IteratorData;
  333.                 return *static_cast<TStlIterator*>(data);
  334.             }
  335.             else {
  336.                 void* data = iter.m_IteratorData;
  337.                 return *static_cast<TStlIterator*>(data);
  338.             }
  339.         }
  340.     static const TStlIterator& It(const TTypeInfoIterator& iter)
  341.         {
  342.             if ( sizeof(TStlIterator) <= sizeof(iter.m_IteratorData) ) {
  343.                 const void* data = &iter.m_IteratorData;
  344.                 return *static_cast<const TStlIterator*>(data);
  345.             }
  346.             else {
  347.                 const void* data = iter.m_IteratorData;
  348.                 return *static_cast<const TStlIterator*>(data);
  349.             }
  350.         }
  351.     static bool InitIterator(TTypeInfoIterator& iter)
  352.         {
  353.             TStlIterator stl_iter = Get(iter.GetContainerPtr()).begin();
  354.             if ( sizeof(TStlIterator) <= sizeof(iter.m_IteratorData) ) {
  355.                 void* data = &iter.m_IteratorData;
  356.                 new (data) TStlIterator(stl_iter);
  357.             }
  358.             else {
  359.                 iter.m_IteratorData = new TStlIterator(stl_iter);
  360.             }
  361.             return stl_iter != Get(iter.GetContainerPtr()).end();
  362.         }
  363.     static void ReleaseIterator(TTypeInfoIterator& iter)
  364.         {
  365.             if ( sizeof(TStlIterator) <= sizeof(iter.m_IteratorData) ) {
  366.                 void* data = &iter.m_IteratorData;
  367.                 static_cast<TStlIterator*>(data)->~StlIterator();
  368.             }
  369.             else {
  370.                 void* data = iter.m_IteratorData;
  371.                 delete static_cast<TStlIterator*>(data);
  372.             }
  373.         }
  374.     static void CopyIterator(TTypeInfoIterator& dst,
  375.                              const TTypeInfoIterator& src)
  376.         {
  377.             It(dst) = It(src);
  378.         }
  379.     static bool NextElement(TTypeInfoIterator& iter)
  380.         {
  381.             return ++It(iter) != Get(iter.GetContainerPtr()).end();
  382.         }
  383.     static TObjectPtr GetElementPtr(const TTypeInfoIterator& iter)
  384.         {
  385.             ElementRef e= *It(iter);
  386.             return &e;
  387.         }
  388. };
  389. template<class Container>
  390. class CStlClassInfoFunctionsCI :
  391.     public CStlClassInfoFunctionsIBase<Container, typename Container::const_iterator, const Container*, const typename Container::value_type&, CContainerTypeInfo::CConstIterator>
  392. {
  393.     typedef CStlClassInfoFunctionsIBase<Container, typename Container::const_iterator, const Container*, const typename Container::value_type&, CContainerTypeInfo::CConstIterator> CParent;
  394. public:
  395.     static void SetIteratorFunctions(CStlOneArgTemplate* info)
  396.         {
  397.             info->SetConstIteratorFunctions(&CParent::InitIterator,
  398.                                             &CParent::ReleaseIterator,
  399.                                             &CParent::CopyIterator,
  400.                                             &CParent::NextElement,
  401.                                             &CParent::GetElementPtr);
  402.         }
  403. };
  404. template<class Container>
  405. class CStlClassInfoFunctionsI :
  406.     public CStlClassInfoFunctionsIBase<Container, typename Container::iterator, Container*, typename Container::value_type&, CContainerTypeInfo::CIterator>
  407. {
  408.     typedef CStlClassInfoFunctionsIBase<Container, typename Container::iterator, Container*, typename Container::value_type&, CContainerTypeInfo::CIterator> CParent;
  409. public:
  410.     typedef typename CParent::TStlIterator TStlIterator;
  411.     typedef typename CParent::TTypeInfoIterator TTypeInfoIterator;
  412.     typedef typename CParent::TObjectPtr TObjectPtr;
  413.     
  414.     static bool EraseElement(TTypeInfoIterator& iter)
  415.         {
  416.             TStlIterator& it = It(iter);
  417.             Container* c = static_cast<Container*>(iter.GetContainerPtr());
  418.             it = c->erase(it);
  419.             return it != c->end();
  420.         }
  421.     static void EraseAllElements(TTypeInfoIterator& iter)
  422.         {
  423.             Container* c = static_cast<Container*>(iter.GetContainerPtr());
  424.             c->erase(It(iter), c->end());
  425.         }
  426.     static void SetIteratorFunctions(CStlOneArgTemplate* info)
  427.         {
  428.             info->SetIteratorFunctions(&CParent::InitIterator,
  429.                                        &CParent::ReleaseIterator,
  430.                                        &CParent::CopyIterator,
  431.                                        &CParent::NextElement,
  432.                                        &CParent::GetElementPtr,
  433.                                        &EraseElement, &EraseAllElements);
  434.         }
  435. };
  436. template<class Container>
  437. class CStlClassInfoFunctionsI_set :
  438.     public CStlClassInfoFunctionsIBase<Container, typename Container::iterator, Container*, typename Container::value_type&, CContainerTypeInfo::CIterator>
  439. {
  440.     typedef CStlClassInfoFunctionsIBase<Container, typename Container::iterator, Container*, typename Container::value_type&, CContainerTypeInfo::CIterator> CParent;
  441. public:
  442.     typedef typename CParent::TStlIterator TStlIterator;
  443.     typedef typename CParent::TTypeInfoIterator TTypeInfoIterator;
  444.     typedef typename CParent::TObjectPtr TObjectPtr;
  445.     
  446.     static TObjectPtr GetElementPtr(const TTypeInfoIterator& /*data*/)
  447.         {
  448.             CStlClassInfoUtil::CannotGetElementOfSet();
  449.             return 0;
  450.         }
  451.     static bool EraseElement(TTypeInfoIterator& iter)
  452.         {
  453.             TStlIterator& it = It(iter);
  454.             Container* c = static_cast<Container*>(iter.GetContainerPtr());
  455.             TStlIterator erase = it++;
  456.             c->erase(erase);
  457.             return it != c->end();
  458.         }
  459.     static void EraseAllElements(TTypeInfoIterator& iter)
  460.         {
  461.             Container* c = static_cast<Container*>(iter.GetContainerPtr());
  462.             c->erase(It(iter), c->end());
  463.         }
  464.     static void SetIteratorFunctions(CStlOneArgTemplate* info)
  465.         {
  466.             info->SetIteratorFunctions(&CParent::InitIterator,
  467.                                        &CParent::ReleaseIterator,
  468.                                        &CParent::CopyIterator,
  469.                                        &CParent::NextElement,
  470.                                        &GetElementPtr,
  471.                                        &EraseElement, &EraseAllElements);
  472.         }
  473. };
  474. template<typename Data>
  475. class CStlClassInfo_list
  476. {
  477. public:
  478.     typedef list<Data> TObjectType;
  479.     static TTypeInfo GetTypeInfo(TTypeInfo elementType)
  480.         {
  481.             return CStlClassInfoUtil::Get_list(elementType, &CreateTypeInfo);
  482.         }
  483.     static CTypeInfo* CreateTypeInfo(TTypeInfo elementType)
  484.         {
  485.             CStlOneArgTemplate* info =
  486.                 new CStlOneArgTemplate(sizeof(TObjectType), elementType,
  487.                                        false);
  488.             SetFunctions(info);
  489.             return info;
  490.         }
  491.     static CTypeInfo* CreateTypeInfo(TTypeInfo elementType, const string& name)
  492.         {
  493.             CStlOneArgTemplate* info =
  494.                 new CStlOneArgTemplate(sizeof(TObjectType), elementType,
  495.                                        false, name);
  496.             SetFunctions(info);
  497.             return info;
  498.         }
  499.     static TTypeInfo GetSetTypeInfo(TTypeInfo elementType)
  500.         {
  501.             return CStlClassInfoUtil::GetSet_list(elementType,
  502.                                                   &CreateSetTypeInfo);
  503.         }
  504.     static CTypeInfo* CreateSetTypeInfo(TTypeInfo elementType)
  505.         {
  506.             CStlOneArgTemplate* info =
  507.                 new CStlOneArgTemplate(sizeof(TObjectType), elementType,
  508.                                        true);
  509.             SetFunctions(info);
  510.             return info;
  511.         }
  512.     static void SetFunctions(CStlOneArgTemplate* info)
  513.         {
  514.             CStlClassInfoFunctions<TObjectType>::SetMemFunctions(info);
  515.             CStlClassInfoFunctions<TObjectType>::SetAddElementFunctions(info);
  516.             CStlClassInfoFunctionsCI<TObjectType>::SetIteratorFunctions(info);
  517.             CStlClassInfoFunctionsI<TObjectType>::SetIteratorFunctions(info);
  518.         }
  519. };
  520. template<typename Data>
  521. class CStlClassInfo_vector
  522. {
  523. public:
  524.     typedef vector<Data> TObjectType;
  525.     static TTypeInfo GetTypeInfo(TTypeInfo elementType)
  526.         {
  527.             return CStlClassInfoUtil::Get_vector(elementType,
  528.                                                  &CreateTypeInfo);
  529.         }
  530.     static CTypeInfo* CreateTypeInfo(TTypeInfo elementType)
  531.         {
  532.             CStlOneArgTemplate* info =
  533.                 new CStlOneArgTemplate(sizeof(TObjectType), elementType,
  534.                                        false);
  535.             SetFunctions(info);
  536.             return info;
  537.         }
  538.     static TTypeInfo GetSetTypeInfo(TTypeInfo elementType)
  539.         {
  540.             return CStlClassInfoUtil::GetSet_vector(elementType,
  541.                                                     &CreateSetTypeInfo);
  542.         }
  543.     static CTypeInfo* CreateSetTypeInfo(TTypeInfo elementType)
  544.         {
  545.             CStlOneArgTemplate* info =
  546.                 new CStlOneArgTemplate(sizeof(TObjectType), elementType,
  547.                                        true);
  548.             SetFunctions(info);
  549.             return info;
  550.         }
  551.     static void SetFunctions(CStlOneArgTemplate* info)
  552.         {
  553.             CStlClassInfoFunctions<TObjectType>::SetMemFunctions(info);
  554.             CStlClassInfoFunctions<TObjectType>::SetAddElementFunctions(info);
  555.             CStlClassInfoFunctionsCI<TObjectType>::SetIteratorFunctions(info);
  556.             CStlClassInfoFunctionsI<TObjectType>::SetIteratorFunctions(info);
  557.         }
  558. };
  559. template<typename Data>
  560. class CStlClassInfo_set
  561. {
  562. public:
  563.     typedef set<Data> TObjectType;
  564.     static TTypeInfo GetTypeInfo(TTypeInfo elementType)
  565.         {
  566.             return CStlClassInfoUtil::Get_set(elementType, &CreateTypeInfo);
  567.         }
  568.     static CTypeInfo* CreateTypeInfo(TTypeInfo elementType)
  569.         {
  570.             CStlOneArgTemplate* info =
  571.                 new CStlOneArgTemplate(sizeof(TObjectType), elementType,
  572.                                        true);
  573.             CStlClassInfoFunctions<TObjectType>::SetMemFunctions(info);
  574.             CStlClassInfoFunctions_set<TObjectType>::SetAddElementFunctions(info);
  575.             CStlClassInfoFunctionsCI<TObjectType>::SetIteratorFunctions(info);
  576.             CStlClassInfoFunctionsI_set<TObjectType>::SetIteratorFunctions(info);
  577.             return info;
  578.         }
  579. };
  580. template<typename Data>
  581. class CStlClassInfo_multiset
  582. {
  583. public:
  584.     typedef multiset<Data> TObjectType;
  585.     static TTypeInfo GetTypeInfo(TTypeInfo elementType)
  586.         {
  587.             return CStlClassInfoUtil::Get_multiset(elementType,
  588.                                                    &CreateTypeInfo);
  589.         }
  590.     static CTypeInfo* CreateTypeInfo(TTypeInfo elementType)
  591.         {
  592.             CStlOneArgTemplate* info =
  593.                 new CStlOneArgTemplate(sizeof(TObjectType), elementType,
  594.                                        true);
  595.             CStlClassInfoFunctions<TObjectType>::SetMemFunctions(info);
  596.             CStlClassInfoFunctions_multiset<TObjectType>::SetAddElementFunctions(info);
  597.             CStlClassInfoFunctionsCI<TObjectType>::SetIteratorFunctions(info);
  598.             CStlClassInfoFunctionsI_set<TObjectType>::SetIteratorFunctions(info);
  599.             return info;
  600.         }
  601. };
  602. template<typename Key, typename Value>
  603. class CStlClassInfo_map
  604. {
  605. public:
  606.     typedef map<Key, Value> TObjectType;
  607.     typedef typename TObjectType::value_type TElementType;
  608.     static TTypeInfo GetTypeInfo(TTypeInfo keyType, TTypeInfo valueType)
  609.         {
  610.             return CStlClassInfoUtil::Get_map(keyType, valueType,
  611.                                               &CreateTypeInfo);
  612.         }
  613.     static CTypeInfo* CreateTypeInfo(TTypeInfo keyType, TTypeInfo valueType)
  614.         {
  615.             TElementType* dummy = 0;
  616.             CStlTwoArgsTemplate* info =
  617.                 new CStlTwoArgsTemplate
  618.                 (sizeof(TObjectType),
  619.                  keyType,
  620.                  reinterpret_cast<TPointerOffsetType>(&dummy->first),
  621.                  valueType,
  622.                  reinterpret_cast<TPointerOffsetType>(&dummy->second),
  623.                  true);
  624.             
  625.             CStlClassInfoFunctions<TObjectType>::SetMemFunctions(info);
  626.             CStlClassInfoFunctions_set<TObjectType>::SetAddElementFunctions(info);
  627.             CStlClassInfoFunctionsCI<TObjectType>::SetIteratorFunctions(info);
  628.             CStlClassInfoFunctionsI_set<TObjectType>::SetIteratorFunctions(info);
  629.             
  630.             return info;
  631.         }
  632. };
  633. template<typename Key, typename Value>
  634. class CStlClassInfo_multimap
  635. {
  636. public:
  637.     typedef multimap<Key, Value> TObjectType;
  638.     typedef typename TObjectType::value_type TElementType;
  639.     static TTypeInfo GetTypeInfo(TTypeInfo keyType, TTypeInfo valueType)
  640.         {
  641.             return CStlClassInfoUtil::Get_multimap(keyType, valueType,
  642.                                                    &CreateTypeInfo);
  643.         }
  644.     static CTypeInfo* CreateTypeInfo(TTypeInfo keyType, TTypeInfo valueType)
  645.         {
  646.             TElementType* dummy = 0;
  647.             CStlTwoArgsTemplate* info =
  648.                 new CStlTwoArgsTemplate
  649.                 (sizeof(TObjectType),
  650.                  keyType,
  651.                  reinterpret_cast<TPointerOffsetType>(&dummy->first),
  652.                  valueType,
  653.                  reinterpret_cast<TPointerOffsetType>(&dummy->second),
  654.                  true);
  655.             
  656.             CStlClassInfoFunctions<TObjectType>::SetMemFunctions(info);
  657.             CStlClassInfoFunctions_multiset<TObjectType>::SetAddElementFunctions(info);
  658.             CStlClassInfoFunctionsCI<TObjectType>::SetIteratorFunctions(info);
  659.             CStlClassInfoFunctionsI_set<TObjectType>::SetIteratorFunctions(info);
  660.             
  661.             return info;
  662.         }
  663. };
  664. END_NCBI_SCOPE
  665. #endif  /* STLTYPES__HPP */
  666. /* @} */
  667. /* ---------------------------------------------------------------------------
  668. * $Log: stltypes.hpp,v $
  669. * Revision 1000.2  2004/06/01 19:39:10  gouriano
  670. * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.69
  671. *
  672. * Revision 1.69  2004/04/26 16:40:59  ucko
  673. * Tweak for GCC 3.4 compatibility.
  674. *
  675. * Revision 1.68  2004/04/02 16:57:35  gouriano
  676. * made it possible to create named CTypeInfo for containers
  677. *
  678. * Revision 1.67  2004/03/25 15:57:55  gouriano
  679. * Added possibility to copy and compare serial object non-recursively
  680. *
  681. * Revision 1.66  2003/08/26 19:24:47  gouriano
  682. * added possibility to discard a member of an STL container
  683. * (from a read hook)
  684. *
  685. * Revision 1.65  2003/08/14 20:03:57  vasilche
  686. * Avoid memory reallocation when reading over preallocated object.
  687. * Simplified CContainerTypeInfo iterators interface.
  688. *
  689. * Revision 1.64  2003/07/22 21:47:04  vasilche
  690. * Added SET OF implemented as vector<>.
  691. *
  692. * Revision 1.63  2003/04/15 16:19:03  siyan
  693. * Added doxygen support
  694. *
  695. * Revision 1.62  2002/12/23 18:38:51  dicuccio
  696. * Added WIn32 export specifier: NCBI_XSERIAL_EXPORT.
  697. * Moved all CVS logs to the end.
  698. *
  699. * Revision 1.61  2002/06/27 21:19:49  ucko
  700. * Fix a memory leak in CStlClassInfoFunctions<>::AddElement (used by Assign)
  701. *
  702. * Revision 1.60  2002/06/19 21:42:58  ucko
  703. * Tweak CStlClassInfo_(multi)map<>::CreateTypeInfo() to avoid GCC 3.1
  704. * warnings -- yes, we should technically be using pointer-to-member
  705. * types, but the offsets are constant in practice.
  706. *
  707. * Revision 1.59  2002/04/12 19:31:31  grichenk
  708. * Fixed containers assignment
  709. *
  710. * Revision 1.58  2001/09/04 14:08:27  ucko
  711. * Handle CConstRef analogously to CRef in type macros
  712. *
  713. * Revision 1.57  2001/05/17 14:59:47  lavr
  714. * Typos corrected
  715. *
  716. * Revision 1.56  2001/01/29 15:19:56  vasilche
  717. * Reduced memory usage on Sun.
  718. *
  719. * Revision 1.55  2000/11/07 17:25:13  vasilche
  720. * Fixed encoding of XML:
  721. *     removed unnecessary apostrophes in OCTET STRING
  722. *     removed unnecessary content in NULL
  723. * Added module names to CTypeInfo and CEnumeratedTypeValues
  724. *
  725. * Revision 1.54  2000/10/13 20:22:47  vasilche
  726. * Fixed warnings on 64 bit compilers.
  727. * Fixed missing typename in templates.
  728. *
  729. * Revision 1.53  2000/10/13 16:28:33  vasilche
  730. * Reduced header dependency.
  731. * Avoid use of templates with virtual methods.
  732. * Reduced amount of different maps used.
  733. * All this lead to smaller compiled code size (libraries and programs).
  734. *
  735. * Revision 1.52  2000/10/03 17:22:35  vasilche
  736. * Reduced header dependency.
  737. * Reduced size of debug libraries on WorkShop by 3 times.
  738. * Fixed tag allocation for parent classes.
  739. * Fixed CObject allocation/deallocation in streams.
  740. * Moved instantiation of several templates in separate source file.
  741. *
  742. * Revision 1.51  2000/09/19 20:16:53  vasilche
  743. * Fixed type in CStlClassInfo_auto_ptr.
  744. * Added missing include serialutil.hpp.
  745. *
  746. * Revision 1.50  2000/09/18 20:00:11  vasilche
  747. * Separated CVariantInfo and CMemberInfo.
  748. * Implemented copy hooks.
  749. * All hooks now are stored in CTypeInfo/CMemberInfo/CVariantInfo.
  750. * Most type specific functions now are implemented via function pointers instead of virtual functions.
  751. *
  752. * Revision 1.49  2000/09/01 18:16:47  vasilche
  753. * Added files to MSVC project.
  754. * Fixed errors on MSVC.
  755. *
  756. * Revision 1.48  2000/09/01 13:16:03  vasilche
  757. * Implemented class/container/choice iterators.
  758. * Implemented CObjectStreamCopier for copying data without loading into memory.
  759. *
  760. * Revision 1.47  2000/08/15 19:44:42  vasilche
  761. * Added Read/Write hooks:
  762. * CReadObjectHook/CWriteObjectHook for objects of specified type.
  763. * CReadClassMemberHook/CWriteClassMemberHook for specified members.
  764. * CReadChoiceVariantHook/CWriteChoiceVariant for specified choice variants.
  765. * CReadContainerElementHook/CWriteContainerElementsHook for containers.
  766. *
  767. * Revision 1.46  2000/07/10 19:32:05  vasilche
  768. * Avoid one more internal compiler error of WorkShop C++.
  769. *
  770. * Revision 1.45  2000/07/10 19:01:00  vasilche
  771. * Avoid internal WorkShop C++ compiler error.
  772. *
  773. * Revision 1.44  2000/07/03 18:42:38  vasilche
  774. * Added interface to typeinfo via CObjectInfo and CConstObjectInfo.
  775. * Reduced header dependency.
  776. *
  777. * Revision 1.43  2000/06/16 20:01:21  vasilche
  778. * Avoid use of unexpected_exception() which is unimplemented on Mac.
  779. *
  780. * Revision 1.42  2000/06/16 16:31:08  vasilche
  781. * Changed implementation of choices and classes info to allow use of the same classes in generated and user written classes.
  782. *
  783. * Revision 1.41  2000/06/01 19:06:58  vasilche
  784. * Added parsing of XML data.
  785. *
  786. * Revision 1.40  2000/05/25 13:27:13  vasilche
  787. * Fixed error with mixing list<> and set<>.
  788. *
  789. * Revision 1.39  2000/05/24 20:50:51  vasilche
  790. * Fixed compilation error.
  791. *
  792. * Revision 1.38  2000/05/24 20:08:15  vasilche
  793. * Implemented XML dump.
  794. *
  795. * Revision 1.37  2000/05/09 16:38:34  vasilche
  796. * CObject::GetTypeInfo now moved to CObjectGetTypeInfo::GetTypeInfo to reduce possible errors.
  797. * Added write context to CObjectOStream.
  798. * Inlined most of methods of helping class Member, Block, ByteBlock etc.
  799. *
  800. * Revision 1.36  2000/05/04 16:22:22  vasilche
  801. * Cleaned and optimized blocks and members.
  802. *
  803. * Revision 1.35  2000/04/10 21:01:39  vasilche
  804. * Fixed Erase for map/set.
  805. * Added iteratorbase.hpp header for basic internal classes.
  806. *
  807. * Revision 1.34  2000/04/10 18:01:52  vasilche
  808. * Added Erase() for STL types in type iterators.
  809. *
  810. * Revision 1.33  2000/03/29 15:55:22  vasilche
  811. * Added two versions of object info - CObjectInfo and CConstObjectInfo.
  812. * Added generic iterators by class -
  813. *  CTypeIterator<class>, CTypeConstIterator<class>,
  814. *  CStdTypeIterator<type>, CStdTypeConstIterator<type>,
  815. *  CObjectsIterator and CObjectsConstIterator.
  816. *
  817. * Revision 1.32  2000/03/10 15:01:42  vasilche
  818. * Fixed OPTIONAL members reading.
  819. *
  820. * Revision 1.31  2000/03/07 14:05:32  vasilche
  821. * Added stream buffering to ASN.1 binary input.
  822. * Optimized class loading/storing.
  823. * Fixed bugs in processing OPTIONAL fields.
  824. *
  825. * Revision 1.30  2000/02/17 20:02:29  vasilche
  826. * Added some standard serialization exceptions.
  827. * Optimized text/binary ASN.1 reading.
  828. * Fixed wrong encoding of StringStore in ASN.1 binary format.
  829. * Optimized logic of object collection.
  830. *
  831. * Revision 1.29  2000/01/10 19:46:34  vasilche
  832. * Fixed encoding/decoding of REAL type.
  833. * Fixed encoding/decoding of StringStore.
  834. * Fixed encoding/decoding of NULL type.
  835. * Fixed error reporting.
  836. * Reduced object map (only classes).
  837. *
  838. * Revision 1.28  2000/01/05 19:43:47  vasilche
  839. * Fixed error messages when reading from ASN.1 binary file.
  840. * Fixed storing of integers with enumerated values in ASN.1 binary file.
  841. * Added TAG support to key/value of map.
  842. * Added support of NULL variant in CHOICE.
  843. *
  844. * Revision 1.27  1999/12/28 21:04:22  vasilche
  845. * Removed three more implicit virtual destructors.
  846. *
  847. * Revision 1.26  1999/12/28 18:55:40  vasilche
  848. * Reduced size of compiled object files:
  849. * 1. avoid inline or implicit virtual methods (especially destructors).
  850. * 2. avoid std::string's methods usage in inline methods.
  851. * 3. avoid string literals ("xxx") in inline methods.
  852. *
  853. * Revision 1.25  1999/12/17 19:04:54  vasilche
  854. * Simplified generation of GetTypeInfo methods.
  855. *
  856. * Revision 1.24  1999/12/01 17:36:21  vasilche
  857. * Fixed CHOICE processing.
  858. *
  859. * Revision 1.23  1999/10/26 15:25:21  vasilche
  860. * Added multiset implementation.
  861. *
  862. * Revision 1.22  1999/10/08 21:00:39  vasilche
  863. * Implemented automatic generation of unnamed ASN.1 types.
  864. *
  865. * Revision 1.21  1999/09/27 14:17:59  vasilche
  866. * Fixed bug with overloaded constructors of Block.
  867. *
  868. * Revision 1.20  1999/09/22 20:11:51  vasilche
  869. * Modified for compilation on IRIX native c++ compiler.
  870. *
  871. * Revision 1.19  1999/09/14 18:54:06  vasilche
  872. * Fixed bugs detected by gcc & egcs.
  873. * Removed unneeded includes.
  874. *
  875. * Revision 1.18  1999/09/01 17:38:03  vasilche
  876. * Fixed vector<char> implementation.
  877. * Added explicit naming of class info.
  878. * Moved IMPLICIT attribute from member info to class info.
  879. *
  880. * Revision 1.17  1999/08/31 17:50:04  vasilche
  881. * Implemented several macros for specific data types.
  882. * Added implicit members.
  883. * Added multimap and set.
  884. *
  885. * Revision 1.16  1999/07/20 18:22:57  vasilche
  886. * Added interface to old ASN.1 routines.
  887. * Added fixed choice of subclasses to use for pointers.
  888. *
  889. * Revision 1.15  1999/07/19 15:50:20  vasilche
  890. * Added interface to old ASN.1 routines.
  891. * Added naming of key/value in STL map.
  892. *
  893. * Revision 1.14  1999/07/15 19:35:06  vasilche
  894. * Implemented map<K, V>.
  895. *
  896. * Revision 1.13  1999/07/15 16:59:55  vasilche
  897. * Fixed template use in typedef.
  898. *
  899. * Revision 1.12  1999/07/15 16:54:44  vasilche
  900. * Implemented vector<X> & vector<char> as special case.
  901. *
  902. * Revision 1.11  1999/07/13 20:18:08  vasilche
  903. * Changed types naming.
  904. *
  905. * Revision 1.10  1999/07/01 17:55:22  vasilche
  906. * Implemented ASN.1 binary write.
  907. *
  908. * Revision 1.9  1999/06/30 16:04:38  vasilche
  909. * Added support for old ASN.1 structures.
  910. *
  911. * Revision 1.8  1999/06/24 14:44:46  vasilche
  912. * Added binary ASN.1 output.
  913. *
  914. * Revision 1.7  1999/06/16 20:35:25  vasilche
  915. * Cleaned processing of blocks of data.
  916. * Added input from ASN.1 text format.
  917. *
  918. * Revision 1.6  1999/06/15 16:20:08  vasilche
  919. * Added ASN.1 object output stream.
  920. *
  921. * Revision 1.5  1999/06/11 19:15:50  vasilche
  922. * Working binary serialization and deserialization of first test object.
  923. *
  924. * Revision 1.4  1999/06/10 21:06:42  vasilche
  925. * Working binary output and almost working binary input.
  926. *
  927. * Revision 1.3  1999/06/09 18:39:00  vasilche
  928. * Modified templates to work on Sun.
  929. *
  930. * Revision 1.2  1999/06/04 20:51:39  vasilche
  931. * First compilable version of serialization.
  932. *
  933. * Revision 1.1  1999/05/19 19:56:31  vasilche
  934. * Commit just in case.
  935. *
  936. * ===========================================================================
  937. */