Changes between Version 1 and Version 2 of FdoSchemaDeepCopy


Ignore:
Timestamp:
10/17/07 15:29:06 (17 years ago)
Author:
gregboone
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FdoSchemaDeepCopy

    v1 v2  
    1212
    1313The following changes will be made to the FDO API in order to support the process of deep copying or cloning FDO schema and data types.
     14
     15==== !FdoSchemaCopyContext Class ====
     16
     17An !FdoSchemaCopyContext class will be added to the FDO Schema API
     18
     19!FdoSchemaCopyContext is context class that will be used to assist in process of cloning schemas and their associated elements. !FdoSchemaCopyContext is designed to contain a schema element map which will store instances of previously copied schema elements. Since FDO schema objects are often associated to one another, and a deep cloning process by design must copy the entire schema object, it is necessary to know if the associated objects have been previously copied. Implementing a mapping for the copied schema elements will avoid creating duplicate objects when cloning an FDO schema.
     20
     21The !FdoSchemaCopyContext class will have the following definition:
     22
     23
     24{{{
     25/// \brief
     26/// A Map that will allow copied schema elements to be tracked 
     27/// and will prevent duplicate elements from being copied.
     28typedef std::map <FdoSchemaElement*, FdoSchemaElement*> FdoSchemaElementMap;
     29
     30/// \brief
     31/// A Map pair that will allow copied schema elements to identified and stored
     32/// in a FdoSchemaElementMap.
     33typedef std::pair <FdoSchemaElement*, FdoSchemaElement*> FdoSchemaElementPair;
     34
     35/// \brief
     36/// A Map iterator that will allow iteration over a FdoSchemaElementMap.
     37typedef FdoSchemaElementMap::const_iterator FdoSchemaElementMapIterator;
     38
     39/// \brief
     40/// A schema context class that is used to assist in process
     41/// of cloning schema elemts. The schema element map contained
     42/// by this class assists the DeepCopy process in avoiding duplicate
     43/// schema element objects from being copied.
     44class FdoSchemaCopyContext : public FdoDisposable
     45{
     46public:
     47    /// \brief
     48    /// Creates a new instance of an FdoSchemaCopyContext
     49    ///
     50    /// \param identifiers
     51    /// An optional set of identifiers that will constrain
     52    /// the class indentifiers to copy. Use this collection to
     53    /// copy a potion of an FDO class definition
     54    ///
     55    /// \return
     56    /// Returns a new instance of FdoSchemaCopyContext
     57    ///
     58    static FdoSchemaCopyContext* Create( FdoIdentifierCollection *identifiers = NULL );
     59
     60public:
     61    /// \brief
     62    /// Gets the element map containing the copied elements
     63    /// referenced by the copy context
     64    ///
     65    /// \return
     66    /// Returns the element map containing the copied elements
     67    ///
     68    const FdoSchemaElementMap * GetSchemaElementMap();
     69
     70    /// \brief
     71    /// Inserts a source/copied pair into the element map
     72    ///
     73    /// \sourceElement
     74    /// The source element from which the element was copied
     75    ///
     76    /// \copiedElement
     77    /// The copied element created from the source element
     78    ///
     79    void InsertSchemaElement( FdoSchemaElement* sourceElement,
     80                              FdoSchemaElement* copiedElement );
     81
     82    /// \brief
     83    /// Sets the FDO identifier list that will constrain the
     84    /// list of class properties to be copied
     85    ///
     86    /// \param identifiers
     87    /// An optional set of identifiers that will constrain
     88    /// the class indentifiers to copy. Use this collection to
     89    /// copy a potion of an FDO class definition
     90    ///
     91    void SetIdentifierConstraints( FdoIdentifierCollection* identifiers );
     92
     93    /// \brief
     94    /// Find a copied element in the schema element
     95    /// map based on it's source object
     96    ///
     97    /// \param element
     98    /// Input the element to search for in the element map
     99    ///
     100    /// \return
     101    /// Returns the previously copied schema element
     102    /// if found in the collection, otherwise NULL
     103    ///
     104    template <typename T> T* FindSchemaElement( T* element )
     105    {
     106        if (m_schemaMap == NULL) {
     107            throw FdoException::Create(
     108                FdoException::NLSGetMessage(FDO_NLSID(FDO_4_UNREADY)));
     109        }
     110
     111        T* retElem = NULL;
     112
     113        FdoSchemaElementMapIterator elementIterator = m_schemaMap->find(element);
     114        if (elementIterator != m_schemaMap->end()) {
     115            retElem = dynamic_cast<T*>(elementIterator->second);
     116            if (retElem == NULL) {
     117                throw FdoException::Create(
     118                    FdoException::NLSGetMessage(FDO_NLSID(CLNT_3_NULLPOINTER)));
     119            }
     120        }
     121
     122        return FDO_SAFE_ADDREF(retElem);
     123    }
     124
     125protected:
     126    /// \brief
     127    /// Default Constructor
     128    FdoCommonSchemaCopyContext( void );
     129
     130    /// \brief
     131    /// Destructor (Virtual)
     132    virtual ~FdoCommonSchemaCopyContext();
     133
     134    /// \brief
     135    /// The Disposal method for this object. Dispose is called
     136    /// when the objects RefCount == 0. Dispose will in turn
     137    /// invoke the objects destructor
     138    virtual void Dispose();
     139
     140private:
     141    /// \brief
     142    /// The std::map containing references to the copied schema elements
     143    FdoSchemaElementMap * m_schemaMap;
     144
     145    /// \brief
     146    /// The identifier collection that will contrain the class properties
     147    /// to be copied.
     148    FdoPtr<FdoIdentifierCollection> m_identifierConstraints;
     149};
     150
     151/// \brief
     152/// FdoSchemaCopyContextP is a FdoPtr on FdoSchemaCopyContext. Provided for convenience.
     153typedef FdoPtr<FdoSchemaCopyContext> FdoSchemaCopyContextP;
     154}}}