activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r531663 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang: Exception.cpp Exception.h Throwable.h
Date Mon, 23 Apr 2007 23:54:23 GMT
Author: tabish
Date: Mon Apr 23 16:54:22 2007
New Revision: 531663

URL: http://svn.apache.org/viewvc?view=rev&rev=531663
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Building Decaf lib

Added:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Throwable.h

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp?view=auto&rev=531663
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.cpp Mon Apr 23
16:54:22 2007
@@ -0,0 +1,158 @@
+/*
+ * 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.
+ */
+#include <stdio.h>
+#include "Exception.h"
+#include <decaf/util/logging/LoggerDefines.h>
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::util::logging;
+
+// For supporting older versions of msvc (<=2003)
+#if defined(_MSC_VER) && (_MSC_VER < 1400)
+    #define vsnprintf _vsnprintf
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception() throw(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception( const Exception& ex ) throw()
+: Throwable()
+{
+    *this = ex;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::Exception( const char* file, const int lineNumber,
+                   const char* msg, ... ) throw()
+{
+    va_list vargs;
+    va_start( vargs, msg ) ;
+    buildMessage( msg, vargs );
+
+    // Set the first mark for this exception.
+    setMark( file, lineNumber );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception::~Exception() throw(){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::setMessage( const char* msg, ... ){
+    va_list vargs;
+    va_start(vargs, msg);
+    buildMessage(msg, vargs);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::buildMessage(const char* format, va_list& vargs)
+{
+    // Allocate buffer with a guess of it's size
+    int size = 128;
+
+    // Format string
+    while( true ){
+
+        // Allocate a buffer of the specified size.
+        char* buffer = new char[size];
+
+        int written = vsnprintf(buffer, size, format, vargs);
+        if (written > -1 && written < size-1) {
+
+            // Guessed size was enough. Assign the string.
+            message.assign (buffer, written);
+
+            // assign isn't passing ownership, just copying, delete
+            // the allocated buffer.
+            delete [] buffer;
+
+            break;
+        }
+
+        // Our buffer wasn't big enough - destroy the old buffer,
+        // double the size and try again.
+        delete [] buffer;
+        size *= 2;
+    }
+
+    //activemq::logger::SimpleLogger logger("com.yadda1");
+    //logger.log( message );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::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 ) );
+
+    ostringstream stream;
+    stream << "\tFILE: " << stackTrace[stackTrace.size()-1].first;
+    stream << ", LINE: " << stackTrace[stackTrace.size()-1].second;
+
+    //activemq::logger::SimpleLogger logger("com.yadda2");
+    //logger.log( stream.str() );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception* Exception::clone() const{
+    return new ActiveMQException( *this );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::vector< std::pair< std::string, int> > Exception::getStackTrace() const{
+    return stackTrace;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::printStackTrace() const{
+    printStackTrace( std::cerr );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void Exception::printStackTrace( std::ostream& stream ) const{
+    stream << getStackTraceString();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Exception::getStackTraceString() const{
+
+    // Create the output stream.
+    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 << std::endl;
+    }
+
+    // Return the string from the output stream.
+    return stream.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Exception& Exception::operator =( const Exception& ex ){
+    this->message = ex.message;
+    this->stackTrace = ex.stackTrace;
+    return *this;
+}
+

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h?view=auto&rev=531663
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Exception.h Mon Apr 23 16:54:22
2007
@@ -0,0 +1,149 @@
+/*
+ * 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 _DECAF_LANG_EXCEPTION_EXCEPTION_H_
+#define _DECAF_LANG_EXCEPTION_EXCEPTION_H_
+
+#include <decaf/lang/Throwable.h>
+#include <activemq/exceptions/ExceptionDefines.h>
+#include <stdarg.h>
+#include <sstream>
+
+namespace decaf{
+namespace lang{
+
+    /*
+     * Base class for all exceptions.
+     */
+    class Exception : public Throwable
+    {
+    private:
+
+        /**
+         * The cause of this exception.
+         */
+        std::string message;
+
+        /**
+         * The stack trace.
+         */
+        std::vector< std::pair< std::string, int> > stackTrace;
+
+    public:
+
+        /**
+         * Default Constructor
+         */
+        Exception() throw();
+
+        /**
+         * Copy Constructor
+         */
+        Exception( const Exception& ex ) throw();
+
+        /**
+         * Constructor - Initializes the file name and line number where
+         * this message occured.  Sets the message to report, using an
+         * optional list of arguments to parse into the message
+         * @param file name where exception occurs
+         * @param line number where the exception occurred.
+         * @param message to report
+         * @param list of primitives that are formatted into the message
+         */
+        Exception( const char* file, const int lineNumber,
+                   const char* msg, ... ) throw();
+
+        virtual ~Exception() throw();
+
+        /**
+         * Gets the message for this exception.
+         * @return Text formatted error message
+         */
+        virtual std::string getMessage() const{
+            return message;
+        }
+
+        /**
+         * Implement method from std::exception
+         * @return the const char* of <code>getMessage()</code>.
+         */
+        virtual const char* what() const throw (){
+            return message.c_str();
+        }
+
+        /**
+         * Sets the cause for this exception.
+         * @param msg the format string for the msg.
+         * @param variable - params to format into the string
+         */
+        virtual void setMessage( const char* msg, ... );
+
+        /**
+         * Adds a file/line number to the stack trace.
+         * @param file The name of the file calling this method (use __FILE__).
+         * @param lineNumber The line number in the calling file (use __LINE__).
+         */
+        virtual void setMark( const char* file, const int lineNumber );
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         * @return Copy of this Exception object
+         */
+        virtual Exception* clone() const;
+
+        /**
+         * Provides the stack trace for every point where
+         * this exception was caught, marked, and rethrown.  The first
+         * item in the returned vector is the first point where the mark
+         * was set (e.g. where the exception was created).
+         * @return the stack trace.
+         */
+        virtual std::vector< std::pair< std::string, int> > getStackTrace() const;
+
+        /**
+         * Prints the stack trace to std::err
+         */
+        virtual void printStackTrace() const;
+
+        /**
+         * Prints the stack trace to the given output stream.
+         * @param stream the target output stream.
+         */
+        virtual void printStackTrace( std::ostream& stream ) const;
+
+        /**
+         * Gets the stack trace as one contiguous string.
+         * @return string with formatted stack trace data
+         */
+        virtual std::string getStackTraceString() const;
+
+        /**
+         * Assignment operator.
+         * @param const reference to another ActiveMQException
+         */
+        virtual Exception& operator =( const Exception& ex );
+
+    protected:
+
+        virtual void buildMessage( const char* format, va_list& vargs );
+
+   };
+
+}}
+
+#endif /*_DECAF_LANG_EXCEPTION_EXCEPTION_H_*/

Added: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Throwable.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Throwable.h?view=auto&rev=531663
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Throwable.h (added)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Throwable.h Mon Apr 23 16:54:22
2007
@@ -0,0 +1,89 @@
+/*
+ * 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 _DECAF_LANG_THROWABLE_H_
+#define _DECAF_LANG_THROWABLE_H_
+
+// Includes
+#include <string>
+#include <vector>
+#include <iostream>
+#include <exception>
+
+namespace cms{
+
+    /**
+     * This class represents an error that has occurred.
+     */
+    class Throwable : public std::exception {
+
+    public:
+
+        Throwable() throw() {}
+
+        virtual ~Throwable() throw() {}
+
+        /**
+         * Gets the cause of the error.
+         * @return string errors message
+         */
+        virtual std::string getMessage() const = 0;
+
+        /**
+         * Adds a file/line number to the stack trace.
+         * @param file The name of the file calling this method (use __FILE__).
+         * @param lineNumber The line number in the calling file (use __LINE__).
+         */
+        virtual void setMark( const char* file, const int lineNumber ) = 0;
+
+        /**
+         * Clones this exception.  This is useful for cases where you need
+         * to preserve the type of the original exception as well as the message.
+         * All subclasses should override.
+         * @return Copy of this Exception object
+         */
+        virtual Throwable* clone() const = 0;
+
+        /**
+         * Provides the stack trace for every point where
+         * this exception was caught, marked, and rethrown.
+         * @return vector containing stack trace strings
+         */
+        virtual std::vector< std::pair< std::string, int> > getStackTrace() const
= 0;
+
+        /**
+         * Prints the stack trace to std::err
+         */
+        virtual void printStackTrace() const = 0;
+
+        /**
+         * Prints the stack trace to the given output stream.
+         * @param stream the target output stream.
+         */
+        virtual void printStackTrace( std::ostream& stream ) const = 0;
+
+        /**
+         * Gets the stack trace as one contiguous string.
+         * @return string with formatted stack trace data
+         */
+        virtual std::string getStackTraceString() const = 0;
+
+    };
+
+}
+
+#endif /*_DECAF_LANG_THROWABLE_H_*/



Mime
View raw message