activemq-commits mailing list archives

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

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

Added logic to the code generators to make commands that are Id types extend Decaf Comparable
so that they can be used as keys in Maps.  

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=738710&r1=738709&r2=738710&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 02:01:15 2009
@@ -134,10 +134,16 @@
 
     protected void generateFile(PrintWriter out) throws Exception {
         generateLicence(out);
+
+        boolean comparable = className.endsWith("Id");
+
 out.println("#include <activemq/commands/"+className+".h>");
 out.println("#include <activemq/state/CommandVisitor.h>");
 out.println("#include <activemq/exceptions/ActiveMQException.h>");
 out.println("#include <decaf/lang/exceptions/NullPointerException.h>");
+        if( comparable ) {
+out.println("#include <apr_strings.h>");
+        }
 out.println("");
 out.println("using namespace std;");
 out.println("using namespace activemq;");
@@ -455,7 +461,7 @@
 out.println("    return visitor->process"+className+"( this );");
 out.println("}");
    }
-   
+
        for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
             JProperty property = (JProperty) iter.next();
             String type = toCppType(property.getType());
@@ -509,6 +515,73 @@
 out.println("}");
         }
 out.println("");
+
+        if( comparable ) {
+out.println("");
+out.println("////////////////////////////////////////////////////////////////////////////////");
+out.println("int " + className + "::compareTo( const "+className+"& value ) const {");
+out.println("");
+out.println("    if( this == &value ) {");
+out.println("        return 0;");
+out.println("    }");
+out.println("");
+
+        for( Iterator iter = properties.iterator(); iter.hasNext(); ) {
+            JProperty property = (JProperty) iter.next();
+            String type = toCppType(property.getType());
+            String propertyName = property.getSimpleName();
+            String parameterName = decapitalize(propertyName);
+            String getter = property.getGetter().getSimpleName();
+            String setter = property.getSetter().getSimpleName();
+
+            if( !property.getType().isPrimitiveType() &&
+                !property.getType().getSimpleName().equals("ByteSequence") &&
+                !property.getType().getSimpleName().equals("String") &&
+                !type.startsWith("std::vector") ) {
+
+out.println("    int "+parameterName+"Comp = this->"+parameterName+"->compareTo( *(
value."+parameterName+" ) );");
+out.println("    if( "+parameterName+"Comp != 0 ) {");
+out.println("        return "+parameterName+"Comp;");
+out.println("    }");
+out.println("");
+
+            } else if( property.getType().getSimpleName().equals("String") ) {
+
+out.println("    int "+parameterName+"Comp = apr_strnatcasecmp( this->"+parameterName+".c_str(),
value."+parameterName+".c_str() );");
+out.println("    if( "+parameterName+"Comp != 0 ) {");
+out.println("        return "+parameterName+"Comp;");
+out.println("    }");
+out.println("");
+            } else {
+
+out.println("    if( this->"+parameterName+" > value."+parameterName+" ) {");
+out.println("        return 1;");
+out.println("    } else if( this->"+parameterName+" < value."+parameterName+" ) {");
+out.println("        return -1;");
+out.println("    }");
+out.println("");
+
+            }
+        }
+
+out.println("    return 0;");
+out.println("}");
+out.println("");
+out.println("////////////////////////////////////////////////////////////////////////////////");
+out.println("bool " + className + "::equals( const "+className+"& value ) const {");
+out.println("    return this->equals( &value );");
+out.println("}");
+out.println("");
+out.println("////////////////////////////////////////////////////////////////////////////////");
+out.println("bool " + className + "::operator==( const "+className+"& value ) const {");
+out.println("    return this->compareTo( value ) == 0;");
+out.println("}");
+out.println("");
+out.println("////////////////////////////////////////////////////////////////////////////////");
+out.println("bool " + className + "::operator<( const "+className+"& value ) const
{");
+out.println("    return this->compareTo( value ) < 0;");
+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=738710&r1=738709&r2=738710&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 02:01:15 2009
@@ -38,6 +38,8 @@
     protected void generateFile(PrintWriter out) {
         generateLicence(out);
 
+        boolean comparable = className.endsWith( "Id" );
+        
 out.println("");
 out.println("#ifndef _ACTIVEMQ_COMMANDS_"+className.toUpperCase()+"_H_");
 out.println("#define _ACTIVEMQ_COMMANDS_"+className.toUpperCase()+"_H_");
@@ -50,6 +52,10 @@
 out.println("#include <activemq/util/Config.h>");
 out.println("#include <activemq/commands/"+baseClass+".h>");
 
+		if( comparable ) {
+out.println("#include <decaf/lang/Comparable.h>");			
+		}
+
 List properties = getProperties();
 for (Iterator iter = properties.iterator(); iter.hasNext();) {
     JProperty property = (JProperty) iter.next();
@@ -88,7 +94,14 @@
 out.println("     *         in the activemq-openwire-generator module");
 out.println("     *");
 out.println("     */");
-out.println("    class AMQCPP_API "+className+" : public "+ baseClass +" {" );
+out.print("    class AMQCPP_API "+className+" : " );
+
+		if( comparable ) {
+out.println("public "+ baseClass +", public decaf::lang::Comparable<"+className+">
{" );
+		} else {
+out.print("public "+ baseClass +" {" );
+out.println("");
+		}
 out.println("    protected:");
 out.println("");
 
@@ -222,6 +235,17 @@
 out.println("");
         }
 
+        if( comparable ) {
+out.println("        virtual int compareTo( const "+className+"& value ) const;");
+out.println("");
+out.println("        virtual bool equals( const "+className+"& value ) const;");
+out.println("");
+out.println("        virtual bool operator==( const "+className+"& value ) const;");
+out.println("");
+out.println("        virtual bool operator<( const "+className+"& value ) const;");
+out.println("");
+        }
+        
 out.println("    };");
 out.println("");
 out.println("}}");



Mime
View raw message