소스 검색

Implement move semantic for generated classes, update copyrights.

Tatyana Borisova 6 년 전
부모
커밋
3beab4ea24
4개의 변경된 파일33개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 1
      LICENSE
  2. 27 1
      src/generator/classgeneratorbase.cpp
  3. 2 1
      src/generator/classgeneratorbase.h
  4. 3 1
      src/generator/templates.h

+ 1 - 1
LICENSE

@@ -1,5 +1,5 @@
 MIT License
-Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
+Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Tatyana Borisova <tanusshhka@mail.ru>
 
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 

+ 27 - 1
src/generator/classgeneratorbase.cpp

@@ -1,7 +1,7 @@
 /*
  * MIT License
  *
- * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
+ * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Tatyana Borisova <tanusshhka@mail.ru>
  *
  * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf
  *
@@ -141,7 +141,9 @@ void ClassGeneratorBase::printProperties(const Descriptor *message)
     Indent();
     printConstructor();
     printCopyFunctionality(message);
+    printMoveSemantic(message);
     printEqualOperator(message);
+
     for (int i = 0; i < message->field_count(); i++) {
         printField(message->field(i), GetterTemplate);
     }
@@ -236,6 +238,30 @@ void ClassGeneratorBase::printCopyFunctionality(const ::google::protobuf::Descri
 
 }
 
+void ClassGeneratorBase::printMoveSemantic(const ::google::protobuf::Descriptor *message)
+{
+    mPrinter.Print({{"classname", mClassName}},
+                   MoveConstructorTemplate);
+
+    Indent();
+    for (int i = 0; i < message->field_count(); i++) {
+        printField(message->field(i), CopyFieldTemplate);
+    }
+    Outdent();
+
+    mPrinter.Print(SimpleBlockEnclosureTemplate);
+    mPrinter.Print({{"classname", mClassName}},
+                   MoveAssignmentOperatorTemplate);
+
+    Indent();
+    for (int i = 0; i < message->field_count(); i++) {
+        printField(message->field(i), CopyFieldTemplate);
+    }
+    Outdent();
+
+    mPrinter.Print(SimpleBlockEnclosureTemplate);
+}
+
 void ClassGeneratorBase::printConstructor()
 {
     mPrinter.Print({{"classname", mClassName}},

+ 2 - 1
src/generator/classgeneratorbase.h

@@ -1,7 +1,7 @@
 /*
  * MIT License
  *
- * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
+ * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Tatyana Borisova <tanusshhka@mail.ru>
  *
  * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf
  *
@@ -94,6 +94,7 @@ protected:
     }
 
     void printCopyFunctionality(const ::google::protobuf::Descriptor *message);
+    void printMoveSemantic(const ::google::protobuf::Descriptor *message);
     void printEqualOperator(const ::google::protobuf::Descriptor *message);
     void printProperties(const ::google::protobuf::Descriptor *message);
     void printConstructor();

+ 3 - 1
src/generator/templates.h

@@ -1,7 +1,7 @@
 /*
  * MIT License
  *
- * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>
+ * Copyright (c) 2019 Alexey Edelev <semlanik@gmail.com>, Tatyana Borisova <tanusshhka@mail.ru>
  *
  * This file is part of qtprotobuf project https://git.semlanik.org/semlanik/qtprotobuf
  *
@@ -54,8 +54,10 @@ static const char *EnumDefinitionTemplate = "enum $enum$ {\n";
 static const char *EnumFieldTemplate = "$enumvalue$ = $value$,\n";
 static const char *ConstructorTemplate = "$classname$(QObject *parent = nullptr) : QObject(parent)\n";
 static const char *CopyConstructorTemplate = "$classname$(const $classname$ &other) {\n";
+static const char *MoveConstructorTemplate = "$classname$(const $classname$ &&other) {\n";
 static const char *CopyFieldTemplate = "m_$property_name$ = other.m_$property_name$;\n";
 static const char *AssignmentOperatorTemplate = "$classname$ &operator =(const $classname$ &other) {\n";
+static const char *MoveAssignmentOperatorTemplate = "$classname$ &operator =(const $classname$ &&other) {\n";
 static const char *EqualOperatorTemplate = "bool operator ==(const $type$ &other) {\n"
                                           "    return ";
 static const char *EqualOperatorPropertyTemplate = "m_$property_name$ == other.m_$property_name$";