Browse Source

A few changes to the template for making new classes.

enhancement_3
Trevor Irons 8 years ago
parent
commit
7a670df5bd
1 changed files with 34 additions and 23 deletions
  1. 34
    23
      vim/lemma.cpp.template

+ 34
- 23
vim/lemma.cpp.template View File

65
 
65
 
66
 $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
 $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
 == cpp.accessor-implementation ==
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
 	return |ATTRIBUTE|;
73
 	return |ATTRIBUTE|;
74
 }		// -----  end of method |CLASSNAME|::get_|ATTRIBUTE|  -----
74
 }		// -----  end of method |CLASSNAME|::get_|ATTRIBUTE|  -----
75
 
75
 
77
 //       Class:  |CLASSNAME|
77
 //       Class:  |CLASSNAME|
78
 //      Method:  set_|ATTRIBUTE|
78
 //      Method:  set_|ATTRIBUTE|
79
 //--------------------------------------------------------------------------------------
79
 //--------------------------------------------------------------------------------------
80
-inline void |CLASSNAME|::set_|ATTRIBUTE| ( int value ) {
80
+inline void |CLASSNAME|::Set|ATTRIBUTE| ( int value ) {
81
 	|ATTRIBUTE|	= value;
81
 	|ATTRIBUTE|	= value;
82
 	return ;
82
 	return ;
83
 }		// -----  end of method |CLASSNAME|::set_|ATTRIBUTE|  -----
83
 }		// -----  end of method |CLASSNAME|::set_|ATTRIBUTE|  -----
122
 namespace Lemma {
122
 namespace Lemma {
123
 
123
 
124
 /**
124
 /**
125
-   \brief  <CURSOR>
126
-   \details
125
+ * \ingroup |?MODULE|
126
+ * \brief  <CURSOR>
127
+ * \details
127
  */
128
  */
128
 class |?CLASSNAME:c| : public |BASECLASS:c| {
129
 class |?CLASSNAME:c| : public |BASECLASS:c| {
129
 
130
 
130
 	friend std::ostream &operator<<(std::ostream &stream, const |CLASSNAME| &ob);
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
 	public:
140
 	public:
138
 
141
 
156
          *       in c++-17, this curiosity may be resolved.
159
          *       in c++-17, this curiosity may be resolved.
157
          * @see |CLASSNAME|::DeSerialize
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
          * Default destructor.
165
          * Default destructor.
163
          * @note This method should never be called due to the mandated
166
          * @note This method should never be called due to the mandated
164
          *       use of smart pointers. It is necessary to keep the method
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
          *       make_shared constructor.
169
          *       make_shared constructor.
167
          */
170
          */
168
         virtual ~|CLASSNAME| ();
171
         virtual ~|CLASSNAME| ();
193
         // ====================  ACCESS        =======================
196
         // ====================  ACCESS        =======================
194
 
197
 
195
         // ====================  INQUIRY       =======================
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
     protected:
207
     protected:
198
 
208
 
199
         // ====================  LIFECYCLE     =======================
209
         // ====================  LIFECYCLE     =======================
200
 
210
 
211
+        /** Copy is disabled */
212
+        |CLASSNAME|( const CLASSNAME& ) = delete;
213
+
201
     	// ====================  DATA MEMBERS  =========================
214
     	// ====================  DATA MEMBERS  =========================
202
 
215
 
203
     private:
216
     private:
263
 // ====================  FRIEND METHODS  =====================
276
 // ====================  FRIEND METHODS  =====================
264
 
277
 
265
 std::ostream &operator << (std::ostream &stream, const |CLASSNAME| &ob) {
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
     return stream;
280
     return stream;
268
 }
281
 }
269
 
282
 
272
 //--------------------------------------------------------------------------------------
285
 //--------------------------------------------------------------------------------------
273
 //       Class:  |CLASSNAME|
286
 //       Class:  |CLASSNAME|
274
 //      Method:  |CLASSNAME|
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
 }  // -----  end of method |CLASSNAME|::|CLASSNAME|  (constructor)  -----
292
 }  // -----  end of method |CLASSNAME|::|CLASSNAME|  (constructor)  -----
280
 
293
 
281
 //--------------------------------------------------------------------------------------
294
 //--------------------------------------------------------------------------------------
282
 //       Class:  |CLASSNAME|
295
 //       Class:  |CLASSNAME|
283
 //      Method:  |CLASSNAME|
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
 }  // -----  end of method |CLASSNAME|::|CLASSNAME|  (constructor)  -----
301
 }  // -----  end of method |CLASSNAME|::|CLASSNAME|  (constructor)  -----
289
 
302
 
293
 // Description:  public constructor returing a shared_ptr
306
 // Description:  public constructor returing a shared_ptr
294
 //--------------------------------------------------------------------------------------
307
 //--------------------------------------------------------------------------------------
295
 std::shared_ptr< |CLASSNAME| >  |CLASSNAME|::NewSP() {
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
     if (node.Tag() !=  "|CLASSNAME|" ) {
337
     if (node.Tag() !=  "|CLASSNAME|" ) {
326
         throw  DeSerializeTypeMismatch( "|CLASSNAME|", node.Tag());
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
 }		// -----  end of method |CLASSNAME|::DeSerialize  -----
341
 }		// -----  end of method |CLASSNAME|::DeSerialize  -----
331
 
342
 
332
 } // ----  end of namespace Lemma  ----
343
 } // ----  end of namespace Lemma  ----

Loading…
Cancel
Save