summaryrefslogtreecommitdiff
path: root/cpp/include/IceUtil/AutoArray.h
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-02-06 14:21:00 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-02-06 14:21:00 +0000
commit79496603519f5356862f5bd537dd0b161d33d4be (patch)
tree9d445c1157b839098e3276dcaa10328b00866fc2 /cpp/include/IceUtil/AutoArray.h
parentFixed one-shot constructors. (diff)
downloadice-79496603519f5356862f5bd537dd0b161d33d4be.tar.bz2
ice-79496603519f5356862f5bd537dd0b161d33d4be.tar.xz
ice-79496603519f5356862f5bd537dd0b161d33d4be.zip
Added support for alternate sequences Added custom test
Diffstat (limited to 'cpp/include/IceUtil/AutoArray.h')
-rw-r--r--cpp/include/IceUtil/AutoArray.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/cpp/include/IceUtil/AutoArray.h b/cpp/include/IceUtil/AutoArray.h
new file mode 100644
index 00000000000..5a15d991404
--- /dev/null
+++ b/cpp/include/IceUtil/AutoArray.h
@@ -0,0 +1,67 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice-E is licensed to you under the terms described in the
+// ICEE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#ifndef ICEE_AUTO_ARRAY_H
+#define ICEE_AUTO_ARRAY_H
+
+namespace IceUtil
+{
+
+template<typename T>
+class auto_array
+{
+public:
+
+ auto_array(T* ptr = 0) :
+ _ptr(ptr)
+ {
+ }
+
+ ~auto_array()
+ {
+ if(_ptr != 0)
+ {
+ delete[] _ptr;
+ }
+ }
+
+ void reset(T* ptr = 0)
+ {
+ if(_ptr != 0)
+ {
+ delete[] _ptr;
+ }
+ _ptr = ptr;
+ }
+
+ T& operator[](size_t i) const
+ {
+ return _ptr[i];
+ }
+
+ T* get() const
+ {
+ return _ptr;
+ }
+
+ void swap(auto_array& a)
+ {
+ T* tmp = a._ptr;
+ a._ptr = _ptr;
+ _ptr = tmp;
+ }
+
+private:
+
+ T* _ptr;
+};
+
+}; // End of namespace IceUtil
+
+#endif