summaryrefslogtreecommitdiffstats
path: root/sdo-cpp/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/EqualityHelper.h
blob: 3058bd8f72b308e583d5b355d324e9b8205dc4e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/* $Rev$ $Date$ */

#ifndef _EQUALITYHELPER_H_
#define _EQUALITYHELPER_H_

#include "commonj/sdo/RefCountingPointer.h"



namespace commonj{
namespace sdo{

/**
 * EqualityHelper provides static helper methods for equals.
 * equalsShallow compares the DataType properties of the 
 * two data objects.
 * equals performs a check on all the memebers and verifies that
 * the same data objects are children.
 */

    class EqualityHelper
{
    public:

    /**
    *  Shallow compare of DataObjects
    *  
    *    Compares two DataObjects for each property where
    *        property.getType().isDataObjectType() is false.
    *    Compares dataObject1.get(property).equals(dataObject2.get(property))
    *    Properties where property.getType().isDataObjectType() is true
    *      are not compared.
    *    DataObjects must have the same type
    *      dataObject1.getType() == dataObject2.getType()
    *  Returns true if all values of all compared properties are equal.
    *  @param dataObject1 DataObject to be compared
    *  @param dataObject2 DataObject to be compared
    *  @return true if equal 
    */
    static SDO_API bool equalShallow(DataObjectPtr dataObject1, DataObjectPtr dataObject2);
    
    /**
    *  Deep compare of DataObjects
    *    Compares dataObject1 and dataObject2 and all their contained
    *      DataObjects (property.isContainment() is true) recursively.
    *    Values of properties are comapred as in isEqualShallow,
    *      and values of properties where 
    *        property.getType().isDataObjectType() is true
    *      are compared where each value copied must be a corresponding
    *      DataObject contained by the source dataObject.
    *    The dataObject trees must be closed. 
    *    If any DataObject referenced in either tree is not part of the
    *      containment trees an IllegalArgumentException is thrown.
    *    If a ChangeSummary is part of the tree they must contain an
    *      identical summary for their respective trees.
    *   
    *  @param dataObject1 DataObject to be compared
    *  @param dataObject2 DataObject to be compared
    *  @return true if all compared aspects of all compared objects are equal 
    *  @throws IllegalArgumentException if any referenced DataObject
    *    is not part of the containment trees.
    */
    static SDO_API bool equal(DataObjectPtr dataObject1, DataObjectPtr dataObject2);

    private: 

    static bool internalEqual(DataObjectPtr dataObject1,
                                                DataObjectPtr dataObject2,
                                            bool fullEqual);

    static bool comparelist(DataObjectList& to, DataObjectList& from, Type::Types t);

    static bool compareitem(DataObjectPtr to, DataObjectPtr from, const Property& p);


   
};
};
};
#endif //_EQUALITYHELPER_H_