Explorar el Código

A few changes to the template for making new classes.

enhancement_3
Trevor Irons hace 8 años
padre
commit
7a670df5bd
Se han modificado 1 ficheros con 34 adiciones y 23 borrados
  1. 34
    23
      vim/lemma.cpp.template

+ 34
- 23
vim/lemma.cpp.template Ver fichero

@@ -65,11 +65,11 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 65
 
66 66
 $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 67
 == cpp.accessor-implementation ==
68
-//--------------------------------------------------------------------------------------
69
-//       Class:  |?CLASSNAME|
70
-//      Method:  get_|?ATTRIBUTE|
71
-//--------------------------------------------------------------------------------------
72
-inline <CURSOR>int |CLASSNAME|::get_|ATTRIBUTE| (  ) {
68
+/**
69
+ *  Class:  |?CLASSNAME|
70
+ *  Method:  Get|?ATTRIBUTE|
71
+ */
72
+inline <CURSOR>int |CLASSNAME|::Get|ATTRIBUTE| (  ) {
73 73
 	return |ATTRIBUTE|;
74 74
 }		// -----  end of method |CLASSNAME|::get_|ATTRIBUTE|  -----
75 75
 
@@ -77,7 +77,7 @@ inline <CURSOR>int |CLASSNAME|::get_|ATTRIBUTE| (  ) {
77 77
 //       Class:  |CLASSNAME|
78 78
 //      Method:  set_|ATTRIBUTE|
79 79
 //--------------------------------------------------------------------------------------
80
-inline void |CLASSNAME|::set_|ATTRIBUTE| ( int value ) {
80
+inline void |CLASSNAME|::Set|ATTRIBUTE| ( int value ) {
81 81
 	|ATTRIBUTE|	= value;
82 82
 	return ;
83 83
 }		// -----  end of method |CLASSNAME|::set_|ATTRIBUTE|  -----
@@ -122,17 +122,20 @@ $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 122
 namespace Lemma {
123 123
 
124 124
 /**
125
-   \brief  <CURSOR>
126
-   \details
125
+ * \ingroup |?MODULE|
126
+ * \brief  <CURSOR>
127
+ * \details
127 128
  */
128 129
 class |?CLASSNAME:c| : public |BASECLASS:c| {
129 130
 
130 131
 	friend std::ostream &operator<<(std::ostream &stream, const |CLASSNAME| &ob);
131 132
 
132
-    /*
133
-     *  This key is used to lock the constructor.
134
-     */
135
-    struct ctor_key {};
133
+    protected:
134
+        /*
135
+         *  This key is used to lock the constructor. It is protected so that inhereted
136
+         *  classes also have the key to contruct their base class.
137
+         */
138
+        struct ctor_key {};
136 139
 
137 140
 	public:
138 141
 
@@ -156,13 +159,13 @@ class |?CLASSNAME:c| : public |BASECLASS:c| {
156 159
          *       in c++-17, this curiosity may be resolved.
157 160
          * @see |CLASSNAME|::DeSerialize
158 161
          */
159
-        |CLASSNAME| (const YAML::Node& node);
162
+        |CLASSNAME| ( const YAML::Node& node, const ctor_key& );
160 163
 
161 164
         /**
162 165
          * Default destructor.
163 166
          * @note This method should never be called due to the mandated
164 167
          *       use of smart pointers. It is necessary to keep the method
165
-         *       public in order to allow for the use of the more efficeint
168
+         *       public in order to allow for the use of the more efficient
166 169
          *       make_shared constructor.
167 170
          */
168 171
         virtual ~|CLASSNAME| ();
@@ -193,11 +196,21 @@ class |?CLASSNAME:c| : public |BASECLASS:c| {
193 196
         // ====================  ACCESS        =======================
194 197
 
195 198
         // ====================  INQUIRY       =======================
199
+        /**
200
+         *  Returns the name of the underlying class, similiar to Python's type
201
+         *  @return string of class name
202
+         */
203
+        virtual inline std::string GetName() const {
204
+            return CName;
205
+        }
196 206
 
197 207
     protected:
198 208
 
199 209
         // ====================  LIFECYCLE     =======================
200 210
 
211
+        /** Copy is disabled */
212
+        |CLASSNAME|( const CLASSNAME& ) = delete;
213
+
201 214
     	// ====================  DATA MEMBERS  =========================
202 215
 
203 216
     private:
@@ -263,7 +276,7 @@ namespace Lemma {
263 276
 // ====================  FRIEND METHODS  =====================
264 277
 
265 278
 std::ostream &operator << (std::ostream &stream, const |CLASSNAME| &ob) {
266
-    stream << ob.Serialize()  << "\n---\n"; // End of doc --- as a direct stream should encapulste thingy
279
+    stream << ob.Serialize()  << "\n---\n"; // End of doc ---
267 280
     return stream;
268 281
 }
269 282
 
@@ -272,18 +285,18 @@ std::ostream &operator << (std::ostream &stream, const |CLASSNAME| &ob) {
272 285
 //--------------------------------------------------------------------------------------
273 286
 //       Class:  |CLASSNAME|
274 287
 //      Method:  |CLASSNAME|
275
-// Description:  constructor (protected)
288
+// Description:  constructor (locked)
276 289
 //--------------------------------------------------------------------------------------
277
-|CLASSNAME|::|CLASSNAME| (const std::string& name) : |?BASECLASS|(name) {
290
+|CLASSNAME|::|CLASSNAME| (const ctor_key&) : |?BASECLASS|( ) {
278 291
 
279 292
 }  // -----  end of method |CLASSNAME|::|CLASSNAME|  (constructor)  -----
280 293
 
281 294
 //--------------------------------------------------------------------------------------
282 295
 //       Class:  |CLASSNAME|
283 296
 //      Method:  |CLASSNAME|
284
-// Description:  DeSerializing constructor (protected)
297
+// Description:  DeSerializing constructor (locked)
285 298
 //--------------------------------------------------------------------------------------
286
-|CLASSNAME|::|CLASSNAME| (const YAML::Node& node) : |BASECLASS|(node) {
299
+|CLASSNAME|::|CLASSNAME| (const YAML::Node& node, const ctor_key&) : |BASECLASS|(node) {
287 300
 
288 301
 }  // -----  end of method |CLASSNAME|::|CLASSNAME|  (constructor)  -----
289 302
 
@@ -293,8 +306,7 @@ std::ostream &operator << (std::ostream &stream, const |CLASSNAME| &ob) {
293 306
 // Description:  public constructor returing a shared_ptr
294 307
 //--------------------------------------------------------------------------------------
295 308
 std::shared_ptr< |CLASSNAME| >  |CLASSNAME|::NewSP() {
296
-    std::shared_ptr< |CLASSNAME| > sp(new  |CLASSNAME|("|CLASSNAME|"), LemmaObjectDeleter() );
297
-    return sp;
309
+    return std::make_shared< |CLASSNAME| >( ctor_key() );
298 310
 }
299 311
 
300 312
 //--------------------------------------------------------------------------------------
@@ -325,8 +337,7 @@ std::shared_ptr<|CLASSNAME|> |CLASSNAME|::DeSerialize ( const YAML::Node& node
325 337
     if (node.Tag() !=  "|CLASSNAME|" ) {
326 338
         throw  DeSerializeTypeMismatch( "|CLASSNAME|", node.Tag());
327 339
     }
328
-    std::shared_ptr< |CLASSNAME| > Object(new |CLASSNAME|(node), LemmaObjectDeleter() );
329
-    return Object ;
340
+    return std::make_shared< |CLASSNAME| > ( node, ctor_key() );
330 341
 }		// -----  end of method |CLASSNAME|::DeSerialize  -----
331 342
 
332 343
 } // ----  end of namespace Lemma  ----

Loading…
Cancelar
Guardar