activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r738874 - in /activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool: AmqCppClassesGenerator.java AmqCppHeadersGenerator.java
Date Thu, 29 Jan 2009 15:00:09 GMT
Author: tabish
Date: Thu Jan 29 15:00:09 2009
New Revision: 738874

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

Add copy constructor and assignment operator to Id Commands and add unimplemented versions
in all other classes to prevent unexpected copying in those.  The Id commands should now be
usable as Keys in Maps and sortable.  

Modified:
    activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java
    activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java

Modified: activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java?rev=738874&r1=738873&r2=738874&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppClassesGenerator.java
Thu Jan 29 15:00:09 2009
@@ -136,6 +136,7 @@
         generateLicence(out);
 
         boolean comparable = className.endsWith("Id");
+        boolean assignable = className.endsWith("Id");
 
 out.println("#include <activemq/commands/"+className+".h>");
 out.println("#include <activemq/state/CommandVisitor.h>");
@@ -179,6 +180,13 @@
         }
 out.println("}");
 out.println("");
+    if( assignable ) {
+out.println("////////////////////////////////////////////////////////////////////////////////");
+out.println(""+className+"::"+className+"( const "+className+"& other ) {");
+out.println("    this->copyDataStructure( &other );");
+out.println("}");
+out.println("");
+    }
 out.println("////////////////////////////////////////////////////////////////////////////////");
 out.println(""+className+"::~"+className+"() {");
 out.println("");
@@ -222,6 +230,11 @@
 out.println("////////////////////////////////////////////////////////////////////////////////");
 out.println("void "+className+"::copyDataStructure( const DataStructure* src ) {");
 out.println("");
+out.println("    // Protect against invalid self assignment.");
+out.println("    if( this == src ) {");
+out.println("        return;");
+out.println("    }");
+out.println("");
 
         if( baseClass != null ) {
 out.println("    // Copy the data of the base class or classes");
@@ -277,18 +290,11 @@
     }
 
 out.println("}");
-
-
-// getDataStructureType
-
 out.println("");
 out.println("////////////////////////////////////////////////////////////////////////////////");
 out.println("unsigned char "+className+"::getDataStructureType() const {");
 out.println("    return "+className+"::ID_" + className.toUpperCase() + ";");
 out.println("}");
-
-// toString
-
 out.println("");
 out.println("////////////////////////////////////////////////////////////////////////////////");
 out.println("std::string "+className+"::toString() const {");
@@ -585,6 +591,14 @@
 out.println("    return this->compareTo( value ) < 0;");
 out.println("}");
         }
+
+        if( assignable ) {
+out.println("////////////////////////////////////////////////////////////////////////////////");
+out.println(""+className+"& "+className+"::operator= ( const "+className+"& other
) {");
+out.println("    this->copyDataStructure( &other );");
+out.println("}");
+out.println("");
+        }
     }
 
     public String getTargetDir() {

Modified: activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java?rev=738874&r1=738873&r2=738874&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java
(original)
+++ activemq/activemq-cpp/trunk/src/main/java/org/apache/activemq/openwire/tool/AmqCppHeadersGenerator.java
Thu Jan 29 15:00:09 2009
@@ -39,7 +39,8 @@
         generateLicence(out);
 
         boolean comparable = className.endsWith( "Id" );
-        
+        boolean assignable = className.endsWith( "Id" );
+
 out.println("");
 out.println("#ifndef _ACTIVEMQ_COMMANDS_"+className.toUpperCase()+"_H_");
 out.println("#define _ACTIVEMQ_COMMANDS_"+className.toUpperCase()+"_H_");
@@ -52,9 +53,9 @@
 out.println("#include <activemq/util/Config.h>");
 out.println("#include <activemq/commands/"+baseClass+".h>");
 
-		if( comparable ) {
-out.println("#include <decaf/lang/Comparable.h>");			
-		}
+        if( comparable ) {
+out.println("#include <decaf/lang/Comparable.h>");
+        }
 
 List properties = getProperties();
 for (Iterator iter = properties.iterator(); iter.hasNext();) {
@@ -89,19 +90,19 @@
 out.println("     *  Command and marshaling code for OpenWire format for "+className );
 out.println("     *");
 out.println("     *");
-out.println("     *  NOTE!: This file is autogenerated - do not modify!");
+out.println("     *  NOTE!: This file is auto generated - do not modify!");
 out.println("     *         if you need to make a change, please see the Java Classes");
 out.println("     *         in the activemq-openwire-generator module");
 out.println("     *");
 out.println("     */");
 out.print("    class AMQCPP_API "+className+" : " );
 
-		if( comparable ) {
+        if( comparable ) {
 out.println("public "+ baseClass +", public decaf::lang::Comparable<"+className+">
{" );
-		} else {
+        } else {
 out.print("public "+ baseClass +" {" );
 out.println("");
-		}
+        }
 out.println("    protected:");
 out.println("");
 
@@ -131,6 +132,13 @@
 
        String typeName = className.toUpperCase();
 
+       if( !assignable ) {
+out.println("");
+out.println("    protected:");
+out.println("");
+out.println("        "+className+"( const "+className+"& other );");
+out.println("        "+className+"& operator= ( const "+className+"& other );");
+       }
 out.println("");
 out.println("    public:");
 out.println("");
@@ -139,11 +147,14 @@
 out.println("    public:");
 out.println("");
 out.println("        "+className+"();");
+            if( assignable ) {
+out.println("        "+className+"( const "+className+"& other );");
+            }
 out.println("        virtual ~"+className+"();");
 out.println("");
 out.println("        /**");
 out.println("         * Get the unique identifier that this object and its own");
-out.println("         * Marshaller share.");
+out.println("         * Marshaler share.");
 out.println("         * @returns new DataStructure type copy.");
 out.println("         */");
 out.println("        virtual unsigned char getDataStructureType() const;");
@@ -188,9 +199,9 @@
 out.println("");
 
         }
-        
+
         if( baseClass.equals( "BaseCommand" ) ) {
-        	
+
 out.println("        /**" );
 out.println("         * Allows a Visitor to visit this command and return a response to the"
);
 out.println("         * command based on the command type being visited.  The command will
call" );
@@ -201,7 +212,7 @@
 out.println("        virtual commands::Command* visit( activemq::state::CommandVisitor* visitor
)" );
 out.println("            throw( exceptions::ActiveMQException );" );
 out.println("");
-        	
+
         }
 
         for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
@@ -245,7 +256,11 @@
 out.println("        virtual bool operator<( const "+className+"& value ) const;");
 out.println("");
         }
-        
+
+        if( assignable ) {
+out.println("        "+className+"& operator= ( const "+className+"& other );");
+        }
+
 out.println("    };");
 out.println("");
 out.println("}}");



Mime
View raw message