Explorar el Código

Implement not equal operator

- Add not equal opertator generation
- Fix couple of generation issues
Alexey Edelev hace 6 años
padre
commit
14710506ca

+ 4 - 2
src/generator/classgeneratorbase.cpp

@@ -153,7 +153,7 @@ void ClassGeneratorBase::printProperties(const Descriptor *message)
     printConstructor();
     printCopyFunctionality(message);
     printMoveSemantic(message);
-    printEqualOperator(message);
+    printComparisonOperators(message);
 
     for (int i = 0; i < message->field_count(); i++) {
         printField(message->field(i), GetterTemplate);
@@ -333,7 +333,7 @@ void ClassGeneratorBase::printPublic()
     mPrinter.Print(PublicBlockTemplate);
 }
 
-void ClassGeneratorBase::printEqualOperator(const Descriptor *message)
+void ClassGeneratorBase::printComparisonOperators(const Descriptor *message)
 {    
     bool isFirst = true;
     PropertyMap properties;
@@ -360,4 +360,6 @@ void ClassGeneratorBase::printEqualOperator(const Descriptor *message)
 
     mPrinter.Print(";\n");
     mPrinter.Print(SimpleBlockEnclosureTemplate);
+
+    mPrinter.Print({{"type", mClassName}}, NotEqualOperatorTemplate);
 }

+ 1 - 1
src/generator/classgeneratorbase.h

@@ -96,7 +96,7 @@ protected:
 
     void printCopyFunctionality(const ::google::protobuf::Descriptor *message);
     void printMoveSemantic(const ::google::protobuf::Descriptor *message);
-    void printEqualOperator(const ::google::protobuf::Descriptor *message);
+    void printComparisonOperators(const ::google::protobuf::Descriptor *message);
     void printProperties(const ::google::protobuf::Descriptor *message);
     void printConstructor();
     void printPublic();

+ 4 - 1
src/generator/templates.h

@@ -59,9 +59,12 @@ static const char *CopyFieldTemplate = "m_$property_name$ = other.m_$property_na
 static const char *AssignmentOperatorTemplate = "$classname$ &operator =(const $classname$ &other) {\n";
 static const char *AssignmentOperatorReturnTemplate = "return *this;\n";
 static const char *MoveAssignmentOperatorTemplate = "$classname$ &operator =(const $classname$ &&other) {\n";
-static const char *EqualOperatorTemplate = "bool operator ==(const $type$ &other) {\n"
+static const char *EqualOperatorTemplate = "bool operator ==(const $type$ &other) const {\n"
                                           "    return ";
 static const char *EqualOperatorPropertyTemplate = "m_$property_name$ == other.m_$property_name$";
+static const char *NotEqualOperatorTemplate = "bool operator !=(const $type$ &other) const {\n"
+                                              "    return !this->operator ==(other);\n"
+                                              "}\n\n";
 
 static const char *GetterTemplate = "$type$ $property_name$() const {\n"
                                     "    return m_$property_name$;\n"