activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r765208 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms: CMSException.cpp CMSException.h
Date Wed, 15 Apr 2009 14:10:08 GMT
Author: tabish
Date: Wed Apr 15 14:10:08 2009
New Revision: 765208

URL: http://svn.apache.org/viewvc?rev=765208&view=rev
Log:
Update the CMSException to hide the internal data members inside the source file using a forward
declared data class to keep the objects contained in the translation unit to prevent them
from crossing the DLL boundaries.  

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.cpp?rev=765208&r1=765207&r2=765208&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.cpp Wed Apr 15 14:10:08
2009
@@ -19,29 +19,46 @@
 
 #include <vector>
 #include <sstream>
+#include <memory>
 #include <algorithm>
 
 using namespace std;
 using namespace cms;
 
+namespace cms{
+
+	class CMSExceptionData {
+	public:
+
+		std::string message;
+		std::auto_ptr<const std::exception> cause;
+		std::vector< std::pair< std::string, int> > stackTrace;
+
+	};
+
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 CMSException::CMSException() throw() : std::exception() {
+	this->data = new CMSExceptionData();
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 CMSException::CMSException( const CMSException& ex ) throw() : std::exception() {
 
-    this->cause.reset( ex.cause.release() );
-    this->message = ex.message;
-    this->stackTrace = ex.stackTrace;
+	this->data = new CMSExceptionData();
+    this->data->cause.reset( ex.data->cause.release() );
+    this->data->message = ex.data->message;
+    this->data->stackTrace = ex.data->stackTrace;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 CMSException::CMSException( const std::string& message,
                             const std::exception* cause ) throw() : std::exception() {
 
-    this->cause.reset( cause );
-    this->message = message;
+    this->data = new CMSExceptionData();
+    this->data->cause.reset( cause );
+    this->data->message = message;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -50,24 +67,26 @@
                             const std::vector< std::pair< std::string, int> >&
stackTrace )
                                 throw() : std::exception() {
 
-    this->cause.reset( cause );
-    this->message = message;
-    this->stackTrace = stackTrace;
+    this->data = new CMSExceptionData();
+    this->data->cause.reset( cause );
+    this->data->message = message;
+    this->data->stackTrace = stackTrace;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 CMSException::~CMSException() throw() {
+	delete this->data;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 void CMSException::setMark( const char* file, const int lineNumber ) {
 
     // Add this mark to the end of the stack trace.
-    stackTrace.push_back( std::make_pair( (std::string)file, (int)lineNumber ) );
+    this->data->stackTrace.push_back( std::make_pair( (std::string)file, (int)lineNumber
) );
 
     std::ostringstream stream;
-    stream << "\tFILE: " << stackTrace[stackTrace.size()-1].first;
-    stream << ", LINE: " << stackTrace[stackTrace.size()-1].second;
+    stream << "\tFILE: " << this->data->stackTrace[this->data->stackTrace.size()-1].first;
+    stream << ", LINE: " << this->data->stackTrace[this->data->stackTrace.size()-1].second;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -87,13 +106,28 @@
     std::ostringstream stream;
 
     // Write the message and each stack entry.
-    stream << message << std::endl;
-    for( unsigned int ix=0; ix<stackTrace.size(); ++ix ){
-        stream << "\tFILE: " << stackTrace[ix].first;
-        stream << ", LINE: " << stackTrace[ix].second;
+    stream << this->data->message << std::endl;
+    for( unsigned int ix = 0; ix < this->data->stackTrace.size(); ++ix ){
+        stream << "\tFILE: " << this->data->stackTrace[ix].first;
+        stream << ", LINE: " << this->data->stackTrace[ix].second;
         stream << std::endl;
     }
 
     // Return the string from the output stream.
     return stream.str();
 }
+
+////////////////////////////////////////////////////////////////////////////////
+std::string CMSException::getMessage() const {
+    return this->data->message;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+const std::exception* CMSException::getCause() const {
+    return this->data->cause.get();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector< std::pair< std::string, int> > CMSException::getStackTrace() const
{
+    return this->data->stackTrace;
+}

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.h?rev=765208&r1=765207&r2=765208&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/cms/CMSException.h Wed Apr 15 14:10:08
2009
@@ -23,12 +23,13 @@
 #include <vector>
 #include <iostream>
 #include <exception>
-#include <memory>
 
 #include <cms/Config.h>
 
 namespace cms{
 
+	class CMSExceptionData;
+
     /**
      * This class represents an error that has occurred in cms, providers
      * can wrap provider specific exceptions in this class by setting the
@@ -40,20 +41,8 @@
     class CMS_API CMSException : public std::exception {
     private:
 
-        /**
-         * The cause of this exception.
-         */
-        std::string message;
-
-        /**
-         * The Exception that caused this one to be thrown.
-         */
-        mutable std::auto_ptr<const std::exception> cause;
-
-        /**
-         * The stack trace.
-         */
-        std::vector< std::pair< std::string, int> > stackTrace;
+    	// The actual data that defines this exception.
+    	CMSExceptionData* data;
 
     public:
 
@@ -75,9 +64,7 @@
          *
          * @return string errors message
          */
-        virtual std::string getMessage() const {
-            return this->message;
-        }
+        virtual std::string getMessage() const;
 
         /**
          * Gets the exception that caused this one to be thrown, this allows
@@ -88,9 +75,7 @@
          * @returns a const pointer reference to the causal exception, if there
          * was no cause associated with this exception then NULL is returned.
          */
-        virtual const std::exception* getCause() const {
-            return this->cause.get();
-        }
+        virtual const std::exception* getCause() const;
 
         /**
          * Provides the stack trace for every point where
@@ -98,9 +83,7 @@
          *
          * @return vector containing stack trace strings
          */
-        virtual std::vector< std::pair< std::string, int> > getStackTrace() const
{
-            return this->stackTrace;
-        }
+        virtual std::vector< std::pair< std::string, int> > getStackTrace() const;
 
         /**
          * Adds a file/line number to the stack trace.



Mime
View raw message