summaryrefslogtreecommitdiffstats
path: root/das-cpp/trunk/runtime/core/include/apache/das/RefCountingPointer.h
diff options
context:
space:
mode:
Diffstat (limited to 'das-cpp/trunk/runtime/core/include/apache/das/RefCountingPointer.h')
-rw-r--r--das-cpp/trunk/runtime/core/include/apache/das/RefCountingPointer.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/das-cpp/trunk/runtime/core/include/apache/das/RefCountingPointer.h b/das-cpp/trunk/runtime/core/include/apache/das/RefCountingPointer.h
new file mode 100644
index 0000000000..22a2ef7f08
--- /dev/null
+++ b/das-cpp/trunk/runtime/core/include/apache/das/RefCountingPointer.h
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+#ifndef REF_COUNTING_POINTER_H
+#define REF_COUNTING_POINTER_H
+
+#include <iostream>
+
+#include "apache/das/DASNullPointerException.h"
+
+namespace apache {
+ namespace das {
+
+ template <class T>
+class RefCountingPointer {
+
+ public:
+ /*SDO_API*/ RefCountingPointer(T* realPtr = 0, bool objectOwner = true);
+ RefCountingPointer(const RefCountingPointer<T>& rhs, bool objectOwner = true);
+ /*SDO_API*/ RefCountingPointer(T& rhs, bool objectOwner = true);
+ /*SDO_API*/ virtual ~RefCountingPointer(void);
+ /*SDO_API*/ RefCountingPointer& operator=(const RefCountingPointer<T>& rhs);
+
+ /*SDO_API*/ bool operator==(RefCountingPointer<T>& test) const;
+ /*SDO_API*/ T* operator->() const;
+ /*SDO_API*/ T& operator*() const;
+ /*SDO_API*/ bool operator!() const;
+ bool isObjectOwner(void) const;
+
+#ifdef MFT
+ // MFT == member function templates
+ // Notes on the items below.
+ // In our code, we use subclasses to expose the API, and super
+ // classes to implement. E,g DataObject and DataObjectImpl.
+ // In some cases, we know that the DataObject given to us is a
+ // DataObjectImpl, and cast it. With RefCountingPointers, however,
+ // the cast cannot work, as the RefCountingPointer to the superclass
+ // is not related to the RCP to the subclass. Recent changes in the
+ // C++ language allow this to work by defining an operator which
+ // causes a pointer of the other type to be returned, as long as pointee
+ // is acceptable as a parameter to the cosntructor of the other type
+ // of pointer. This works in C++.NET, but not in C++6:
+ operator RefCountingPointer<otherType>()
+ {
+ return RefCountingPointer<otherType>(pointee);
+ }
+
+ // Since we are using C6, a possible workround is to provide a method
+ // which returns the dumb pointer, then construct a pointer to the
+ // base class from the pointer returned. This is that the operator T* does.
+ // The code in DataObject could be simpler if we used C7,and we should
+ // discusss changing.
+#else
+ operator T*() {return pointee;}
+#endif
+
+ template <class otherType>
+ operator RefCountingPointer<otherType>()
+ {
+ return RefCountingPointer<otherType>(pointee);
+ }
+
+ friend std::ostream& operator<< (std::ostream &os, const RefCountingPointer<T>& ptr)
+ {
+ if (!ptr)
+ {
+ os << "NULL" << std::endl;
+ }
+ else
+ {
+ ptr->printSelf(os);
+ }
+
+ return os;
+ }
+
+ private:
+ T *pointee;
+ bool objectOwner;
+ void init();
+
+};
+
+ };
+};
+
+#endif //REF_COUNTING_POINTER_H