Renaming the class PtrCloser to not cause confusion with unique_ptr.
authorTim King <taking@google.com>
Wed, 9 Nov 2016 22:09:25 +0000 (14:09 -0800)
committerTim King <taking@google.com>
Wed, 9 Nov 2016 22:09:25 +0000 (14:09 -0800)
src/base/Makefile.am
src/base/cvc4_unique_ptr.h [deleted file]
src/base/ptr_closer.h [new file with mode: 0644]
src/expr/metakind_template.h
src/main/driver_unified.cpp

index 94e45c542448bf94785b0aabdedf9de02719b611..bf919cd818e5521e56f7c50c29b7b1a01a396416 100644 (file)
@@ -20,14 +20,14 @@ libbase_la_SOURCES = \
        configuration_private.h \
        cvc4_assert.cpp \
        cvc4_assert.h \
-       cvc4_unique_ptr.h \
        exception.cpp \
        exception.h \
        listener.cpp \
        listener.h \
        modal_exception.h \
        output.cpp \
-       output.h
+       output.h \
+       ptr_closer.h
 
 
 
diff --git a/src/base/cvc4_unique_ptr.h b/src/base/cvc4_unique_ptr.h
deleted file mode 100644 (file)
index 9642d01..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*********************                                                        */
-/*! \file cvc4_unique_ptr.h
- ** \verbatim
- ** Top contributors (to current version):
- **   Tim King
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
- ** in the top-level source directory) and their institutional affiliations.
- ** All rights reserved.  See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief A CVC4 variant of unique_ptr for C++05.
- **
- ** A CVC4 variant of unique_ptr for C++05.
- **/
-
-#include "cvc4_public.h"
-
-#ifndef __CVC4__UNIQUE_PTR_H
-#define __CVC4__UNIQUE_PTR_H
-
-namespace CVC4 {
-
-/**
- * A CVC4 variant of unique_ptr for C++05.
- *
- * This is a variant of unique_ptr that is not designed for move semantics.
- * These are appropriate to own pointer allocations on the stack that should be
- * deleted when an exception is thrown. These should be used with care within
- * heap based data structures, and never as the return value of a function.
- */
-template <class T>
-class UniquePtr {
- public:
-  UniquePtr() : d_pointer(NULL) {}
-  UniquePtr(T* pointer) : d_pointer(pointer) {}
-  ~UniquePtr() { delete d_pointer; }
-
-  void reset(T* pointer) {
-    delete d_pointer;
-    d_pointer = pointer;
-  }
-
-  /** Gives up ownership of the pointer to the caller. */
-  T* release() {
-    T* copy = d_pointer;
-    d_pointer = NULL;
-    return copy;
-  }
-
-  /** Returns the pointer. */
-  T* get() const { return d_pointer; }
-
-  /** Returns the pointer. Undefined if the pointer is null. */
-  T* operator->() const { return d_pointer; }
-
-  /** Returns true if the pointer is not-null. */
-  operator bool() const { return d_pointer != NULL; }
-
- private:
-  UniquePtr(const UniquePtr*) CVC4_UNDEFINED;
-  UniquePtr& operator=(const UniquePtr&) CVC4_UNDEFINED;
-
-  /** An owned pointer object allocated by `new` or NULL. */
-  T* d_pointer;
-}; /* class UniquePtr */
-
-} /* CVC4 namespace */
-
-#endif /* __CVC4__UNIQUE_PTR_H */
diff --git a/src/base/ptr_closer.h b/src/base/ptr_closer.h
new file mode 100644 (file)
index 0000000..9c40eee
--- /dev/null
@@ -0,0 +1,73 @@
+/*********************                                                        */
+/*! \file ptr_closer.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ **   Tim King
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2016 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved.  See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief A class to close owned pointers in the destructor.
+ **
+ ** A class to close owned pointers in the destructor.
+ **/
+
+#include "cvc4_public.h"
+
+#ifndef __CVC4__PTR_CLOSER_H
+#define __CVC4__PTR_CLOSER_H
+
+namespace CVC4 {
+
+/**
+ * A class to close owned pointers in the destructor. This plays a similar role
+ * to unique_ptr, but without move semantics. This is designed to overcome the
+ * lack of having unique_ptr in C++05.
+ *
+ * This is a variant of unique_ptr that is not designed for move semantics.
+ * These are appropriate to own pointer allocations on the stack that should be
+ * deleted when an exception is thrown. These should be used with care within
+ * heap based data structures, and never as the return value of a function.
+ */
+template <class T>
+class PtrCloser {
+ public:
+  PtrCloser() : d_pointer(NULL) {}
+  explicit PtrCloser(T* pointer) : d_pointer(pointer) {}
+  ~PtrCloser() { delete d_pointer; }
+
+  /** Deletes the currently owned copy and takes ownership of pointer. */
+  void reset(T* pointer = NULL) {
+    delete d_pointer;
+    d_pointer = pointer;
+  }
+
+  /** Gives up ownership of the pointer to the caller. */
+  T* release() {
+    T* copy = d_pointer;
+    d_pointer = NULL;
+    return copy;
+  }
+
+  /** Returns the pointer. */
+  T* get() const { return d_pointer; }
+
+  /** Returns the pointer. Undefined if the pointer is null. */
+  T* operator->() const { return d_pointer; }
+
+  /** Returns true if the pointer is not-null. */
+  operator bool() const { return d_pointer != NULL; }
+
+ private:
+  PtrCloser(const PtrCloser*) CVC4_UNDEFINED;
+  PtrCloser& operator=(const PtrCloser&) CVC4_UNDEFINED;
+
+  /** An owned pointer object allocated by `new`. Or NULL. */
+  T* d_pointer;
+}; /* class PtrCloser */
+
+} /* CVC4 namespace */
+
+#endif /* __CVC4__PTR_CLOSER_H */
index 75521e901ae63e573b4e4321a194eeb4128151eb..1c03cf4074d7163c24341538d13b8d072bb17c79 100644 (file)
@@ -338,7 +338,7 @@ ${metakind_operatorKinds}
 
 }/* CVC4::kind namespace */
 
-#line 341 "${template}"
+#line 342 "${template}"
 
 namespace theory {
 
index e9e703b5f817e2ec630ddf9c5685599c46c2bffd..e43c8a6ee2d328d93967c20937dda024048bab3c 100644 (file)
@@ -26,8 +26,8 @@
 #include "cvc4autoconfig.h"
 
 #include "base/configuration.h"
-#include "base/cvc4_unique_ptr.h"
 #include "base/output.h"
+#include "base/ptr_closer.h"
 #include "expr/expr_iomanip.h"
 #include "expr/expr_manager.h"
 #include "main/command_executor.h"
@@ -242,7 +242,7 @@ int runCvc4(int argc, char* argv[], Options& opts) {
   }
 # endif
 
-  UniquePtr<Parser> replayParser;
+  PtrCloser<Parser> replayParser;
   if( opts.getReplayInputFilename() != "" ) {
     std::string replayFilename = opts.getReplayInputFilename();
     ParserBuilder replayParserBuilder(exprMgr, replayFilename, opts);
@@ -348,7 +348,7 @@ int runCvc4(int argc, char* argv[], Options& opts) {
 
       vector< vector<Command*> > allCommands;
       allCommands.push_back(vector<Command*>());
-      UniquePtr<Parser> parser(parserBuilder.build());
+      PtrCloser<Parser> parser(parserBuilder.build());
       if(replayParser) {
         // have the replay parser use the file's declarations
         replayParser->useDeclarationsFrom(parser.get());
@@ -503,7 +503,7 @@ int runCvc4(int argc, char* argv[], Options& opts) {
 #endif /* CVC4_COMPETITION_MODE && !CVC4_SMTCOMP_APPLICATION_TRACK */
       }
 
-      UniquePtr<Parser> parser(parserBuilder.build());
+      PtrCloser<Parser> parser(parserBuilder.build());
       if(replayParser) {
         // have the replay parser use the file's declarations
         replayParser->useDeclarationsFrom(parser.get());