help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Creating C++ constructor member init lists


From: Sarir Khamsi
Subject: Creating C++ constructor member init lists
Date: Tue, 27 Oct 2009 13:08:46 -0700
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (windows-nt)

I'd like to write some code in some language (preferably in Emacs
Lisp) to take a C++ class and add member variables to the
constructor's member initialization list in an automated
fashion. Given something like:

   struct MyType
   {
      MyType();
      // ...
   private:
      int i1_;
      double d_;
      T1 *pT1_;
      T2 t2_;
   };

I'd like the code to generate:

   struct MyType
   {
      MyType() :
         i1_(0),
         d_(0.0),
         pT1_(0),
         t2_()
      {
      }
      // ...
   private:
      int i1_;
      double d_;
      T1 *pT1_;
      T2 t2_;
   };

It would be easy to write something that just default-constructs the
members, but I'd like to make it smart enough to init bools to
"false", ints to "0", doubles to "0.0", etc. My questions are:

 - Are there helper functions in c++-mode that can be used to
   enumerate member variables, or make life easier?
 - Is there code to do something like this already (I looked a bit and
   didn't find exactly what I wanted)?
 - Is GCC-XML worth looking into? I've looked at the output of a small
   C++ class and could use Python to do what I want.

I haven't started the coding and wanted to get other people's
input. Thanks.

Sarir

-- 
Sarir Khamsi
software guy
sarir.khamsi@raytheon.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]