summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog-99b16
-rw-r--r--ace/Auto_IncDec_T.cpp32
-rw-r--r--ace/Auto_IncDec_T.h83
-rw-r--r--ace/Auto_IncDec_T.i21
-rw-r--r--ace/Makefile1
-rw-r--r--tests/Auto_IncDec_Test.cpp64
-rw-r--r--tests/Makefile1
-rw-r--r--tests/run_tests.lst1
8 files changed, 219 insertions, 0 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b
index 6a48c55e908..c74d2d87a51 100644
--- a/ChangeLog-99b
+++ b/ChangeLog-99b
@@ -1,3 +1,19 @@
+Sun Nov 7 12:03:31 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
+
+ * tests/run_tests.lst: Added Auto_IncDec_Test to the tests.
+
+ * ace/Makefile,
+ tests/Makefile: Added the new Auto_IncDec* stuff to the
+ makefiles.
+
+ * ace: Added Auto_IncDec_T.{h,i,cpp} to the ACE release. This class
+ automatically increments and decrements a parameterized counter.
+ Thanks to Edan Ayal <EdanA@cti2.com> for contributing this.
+
+ * tests/Auto_IncDec_Test.cpp: Added a test for the ACE_Auto_IncDec
+ class. Thanks to Edan Ayal <EdanA@cti2.com> for contributing
+ this.
+
Fri Nov 05 14:26:38 1999 Jim Buck <jim@nowsol.com>
* ace/OS.cpp (ACE_Time_Value::set): fixed calculation of
diff --git a/ace/Auto_IncDec_T.cpp b/ace/Auto_IncDec_T.cpp
new file mode 100644
index 00000000000..d915b51e672
--- /dev/null
+++ b/ace/Auto_IncDec_T.cpp
@@ -0,0 +1,32 @@
+// $Id$
+
+#ifndef ACE_AUTO_INCDEC_T_C
+#define ACE_AUTO_INCDEC_T_C
+
+#define ACE_BUILD_DLL
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ace/Auto_IncDec_T.h"
+#include "ace/Log_Msg.h"
+
+ACE_RCSID(ace, Auto_IncDec_T, "Auto_IncDec_T.cpp, by Edan Ayal")
+
+#if !defined (__ACE_INLINE__)
+#include "ace/Auto_IncDec_T.i"
+#endif /* __ACE_INLINE__ */
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Auto_IncDec)
+
+template <class ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> void
+ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE>::dump (void) const
+{
+// ACE_TRACE ("ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE>::dump");
+
+ ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
+ ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
+}
+
+#endif /* ACE_AUTO_INCDEC_T_C */
diff --git a/ace/Auto_IncDec_T.h b/ace/Auto_IncDec_T.h
new file mode 100644
index 00000000000..024729bf7be
--- /dev/null
+++ b/ace/Auto_IncDec_T.h
@@ -0,0 +1,83 @@
+/* -*- C++ -*- */
+// $Id$
+
+//============================================================================
+//
+// = LIBRARY
+// ace
+//
+// = FILENAME
+// Auto_IncDec_T.h
+//
+// = AUTHOR
+// Edan Ayal <EdanA@cti2.com>
+//
+//============================================================================
+
+#ifndef ACE_AUTO_INCDEC_T_H
+#define ACE_AUTO_INCDEC_T_H
+
+#include "ace/OS.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+template <class ACE_SAFELY_INCREMENTABLE_DECREMENTABLE>
+class ACE_Auto_IncDec
+{
+ // = TITLE
+ // This class automatically increments and decrements a
+ // parameterized counter.
+ //
+ // = DESCRIPTION
+ // This data structure is meant to be used within a method,
+ // function, or scope. The actual parameter given for the
+ // <ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> template parameter
+ // must provide at least opertaors ++ and --.
+public:
+ // = Initialization and termination methods.
+ ACE_Auto_IncDec (ACE_SAFELY_INCREMENTABLE_DECREMENTABLE &counter);
+ // Implicitly increment the counter.
+
+ ~ACE_Auto_IncDec (void);
+ // Implicitly decrement the counter.
+
+ void dump (void) const;
+ // Dump the state of an object.
+
+protected:
+ ACE_SAFELY_INCREMENTABLE_DECREMENTABLE &counter_;
+ // Reference to the <ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> counter
+ // we're incrementing/decrementing.
+
+private:
+ // = Prevent assignment and initialization.
+ ACE_UNIMPLEMENTED_FUNC (void operator= (const
+ ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> &))
+ ACE_UNIMPLEMENTED_FUNC (ACE_Auto_IncDec (const
+ ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> &))
+};
+
+#if defined (__ACE_INLINE__)
+#include "ace/Auto_IncDec_T.i"
+// On non-Win32 platforms, this code will be inlined
+#endif /* __ACE_INLINE__ */
+
+#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
+#include "ace/Auto_IncDec_T.cpp"
+// On Win32 platforms, this code will be included as template source
+// code and will not be inlined. Therefore, we first turn off
+// ACE_INLINE, set it to be nothing, include the code, and then turn
+// ACE_INLINE back to its original setting. All this nonsense is
+// necessary, since the generic template code that needs to be
+// specialized cannot be inlined, else the compiler will ignore the
+// specialization code. Also, the specialization code *must* be
+// inlined or the compiler will ignore the specializations.
+#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
+
+#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
+#pragma implementation ("Auto_IncDec_T.cpp")
+#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
+
+#endif /* ACE_AUTO_INCDEC_T_H */
diff --git a/ace/Auto_IncDec_T.i b/ace/Auto_IncDec_T.i
new file mode 100644
index 00000000000..96658ed76c5
--- /dev/null
+++ b/ace/Auto_IncDec_T.i
@@ -0,0 +1,21 @@
+/* -*- C++ -*- */
+// $Id$
+
+// Implicitly and automatically increment the counter.
+
+template <class ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> ACE_INLINE
+ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE>::ACE_Auto_IncDec
+ (ACE_SAFELY_INCREMENTABLE_DECREMENTABLE &counter)
+ : counter_ (counter)
+{
+ ++this->counter_;
+}
+
+// Implicitly and automatically decrement the counter.
+
+template <class ACE_SAFELY_INCREMENTABLE_DECREMENTABLE> ACE_INLINE
+ACE_Auto_IncDec<ACE_SAFELY_INCREMENTABLE_DECREMENTABLE>::~ACE_Auto_IncDec (void)
+{
+ --this->counter_;
+}
+
diff --git a/ace/Makefile b/ace/Makefile
index 0cada507cbf..8d90cc16ca1 100644
--- a/ace/Makefile
+++ b/ace/Makefile
@@ -187,6 +187,7 @@ TEMPLATE_FILES = \
Acceptor \
Active_Map_Manager_T \
Asynch_Acceptor \
+ Auto_IncDec_T \
Auto_Ptr \
Based_Pointer_T \
Connector \
diff --git a/tests/Auto_IncDec_Test.cpp b/tests/Auto_IncDec_Test.cpp
new file mode 100644
index 00000000000..a9a5563b2af
--- /dev/null
+++ b/tests/Auto_IncDec_Test.cpp
@@ -0,0 +1,64 @@
+// $Id$
+
+//============================================================================
+//
+// = LIBRARY
+// tests
+//
+// = FILENAME
+// Auto_IncDec_Test.cpp
+//
+// = DESCRIPTION
+// This is a simple test of the Auto Increment/Decrement Class in
+// ACE. On platforms like Win32, ACE uses template specialization
+// to use native implementations provided by the OS to accelarate
+// these operations.
+//
+// = AUTHOR
+// Edan Ayal <EdanA@cti2.com>
+//
+//============================================================================
+
+#include "ace/Auto_IncDec_T.h"
+#include "tests/test_config.h"
+
+ACE_RCSID(tests, Auto_IncDec_Test, "Auto_IncDec_Test.cpp, by Edan Ayal")
+
+#if defined(__BORLANDC__) && __BORLANDC__ >= 0x0530
+USELIB("..\ace\aced.lib");
+//---------------------------------------------------------------------------
+#endif /* defined(__BORLANDC__) && __BORLANDC__ >= 0x0530 */
+
+int
+main (int, ASYS_TCHAR *[])
+{
+ ACE_START_TEST (ASYS_TEXT ("Auto_IncDec_Test"));
+
+ int counter = 0;
+ {
+ ACE_Auto_IncDec<int> Auto_IncDec1 (counter);
+ ACE_ASSERT (counter == 1);
+
+ ACE_Auto_IncDec<int> Auto_IncDec2 (counter);
+ ACE_ASSERT (counter == 2);
+
+ {
+ ACE_ASSERT (counter == 2);
+ ACE_Auto_IncDec<int> Auto_IncDec3 (counter);
+ ACE_ASSERT (counter == 3);
+ }
+
+ ACE_ASSERT (counter == 2);
+ }
+
+ ACE_ASSERT (counter == 0);
+
+ ACE_END_TEST;
+ return 0;
+}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class ACE_Auto_IncDec<int>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate ACE_Auto_IncDec<int>
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/tests/Makefile b/tests/Makefile
index be4c34f9491..2b7738c43b7 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -11,6 +11,7 @@
BIN = Aio_Platform_Test \
Atomic_Op_Test \
+ Auto_IncDec_Test \
Barrier_Test \
Basic_Types_Test \
Buffer_Stream_Test \
diff --git a/tests/run_tests.lst b/tests/run_tests.lst
index 0e1be1d45a9..a7ec71775d2 100644
--- a/tests/run_tests.lst
+++ b/tests/run_tests.lst
@@ -2,6 +2,7 @@ Basic_Types_Test
chorus/Env_Value_Test
Capabilities_Test
Atomic_Op_Test
+Auto_IncDec_Test
Object_Manager_Test
CDR_File_Test
CDR_Test