473,554 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automatic generation of header file.


Maintaining a C++ header file can be painful. I want a way to
automatically generate header files from the implementation file. Does
anybody know of a program that does this?

If not, I'd like to try writing one. The input file would consist of
function definitions and class definitions (with all methods defined
inline). The program would extract all the signatures and place them in a
header file. I can see some small problems related to namespaces and
includes, but are there any show-stoppers?

- Kannan
Jul 23 '05 #1
15 7859
Kannan Goundan wrote:
Maintaining a C++ header file can be painful. I want a way to
automatically generate header files from the implementation file.
Does anybody know of a program that does this?

If not, I'd like to try writing one. The input file would consist of
function definitions and class definitions (with all methods defined
inline). The program would extract all the signatures and place them
in a header file. I can see some small problems related to
namespaces and includes, but are there any show-stoppers?


Show-stoppers I ain't sure of, but consider if your class needs to have
a base class or two. How is that going to be automatically generated?

V
Jul 23 '05 #2
Victor Bazarov wrote:
Kannan Goundan wrote:
Maintaining a C++ header file can be painful. I want a way to
automatical ly generate header files from the implementation file.
Does anybody know of a program that does this?

If not, I'd like to try writing one. The input file would consist of
function definitions and class definitions (with all methods defined
inline). The program would extract all the signatures and place them
in a header file. I can see some small problems related to
namespaces and includes, but are there any show-stoppers?

Show-stoppers I ain't sure of, but consider if your class needs to have
a base class or two. How is that going to be automatically generated?

V


Why? He can obtain its name from the ": public BC " part of the child
class definition (which can be found in the source file if I got that
right).
You could then (given that the filenames are identical to the class
names) produce an include directive in the generated header which
includes the base class definition (#include BC.hpp).

--
Matthias Kaeppler
Jul 23 '05 #3
On Fri, 08 Apr 2005 23:45:34 -0700, Kannan Goundan <ca*****@yahoo. com> wrote:

Maintaining a C++ header file can be painful. I want a way to
automatically generate header files from the implementation file. Does
anybody know of a program that does this?

If not, I'd like to try writing one. The input file would consist of
function definitions and class definitions (with all methods defined
inline). The program would extract all the signatures and place them in a
header file. I can see some small problems related to namespaces and
includes, but are there any show-stoppers?


Being that the header file defines the api which is used by more than
just the implementation, I'd think you'd want it to not be easily
changed. Maybe you haven't been on the short end of an api change
often enough to appreciate that. :)

--
Joe Seigh
Jul 23 '05 #4
You can ease the pain of managing C++ by following
some rules that are covered in the following article:

http://www.eventhelix.com/RealtimeMa...dePatterns.htm

Deepa
--
EventStudio 2.5 - http://www.EventHelix.com/EventStudio
Generate Sequence diagrams from a simple declarative language

Jul 23 '05 #5
Joe Seigh wrote:
On Fri, 08 Apr 2005 23:45:34 -0700, Kannan Goundan <ca*****@yahoo. com> wrote:

Maintaining a C++ header file can be painful. I want a way
to automatically generate header files from the implementation
file. Does anybody know of a program that does this?

If not, I'd like to try writing one. The input file would
consist of function definitions and class definitions (with
all methods defined inline). The program would extract all
the signatures and place them in a header file. I can see
some small problems related to namespaces and includes, but
are there any show-stoppers?


Being that the header file defines the api which is used by more
than just the implementation, I'd think you'd want it to not be
easily changed. Maybe you haven't been on the short end of an
api change often enough to appreciate that. :)

--
Joe Seigh


There are a few reasons I don't like C++ header files:

1. The C++ header file also includes stuff that isn't part of an API
contract (private methods/fields, inline method implementations ).

2. I should only have to worry about API compatibility for external
APIs. When I'm changing the implementation details of my classes, I
don't want to have to make every signature change in two places.

I want to be able to do things the way they are done in Java and C#.

Jul 23 '05 #6
Kannan Goundan wrote:
Joe Seigh wrote:
On Fri, 08 Apr 2005 23:45:34 -0700, Kannan Goundan


<ca*****@yahoo. com>
wrote:

Maintainin g a C++ header file can be painful. I want a way
to automatically generate header files from the implementation
file. Does anybody know of a program that does this?

If not, I'd like to try writing one. The input file would
consist of function definitions and class definitions (with
all methods defined inline). The program would extract all
the signatures and place them in a header file. I can see
some small problems related to namespaces and includes, but
are there any show-stoppers?


Being that the header file defines the api which is used by more
than just the implementation, I'd think you'd want it to not be
easily changed. Maybe you haven't been on the short end of an
api change often enough to appreciate that. :)

--
Joe Seigh

There are a few reasons I don't like C++ header files:

1. The C++ header file also includes stuff that isn't part of an API
contract (private methods/fields, inline method implementations ).

2. I should only have to worry about API compatibility for external
APIs. When I'm changing the implementation details of my classes, I
don't want to have to make every signature change in two places.

I want to be able to do things the way they are done in Java and C#.


You can do this in C++ as you can in Java.

In Java we have classes and interfaces. When these are used as part of a
public API, everything they contain is viewable by the end user. Its
the same with C++ header files.

However, the external public API is just that, its an Application
Programming INTERFACE.

What we do in Java, is define a series of Interfaces which are our
public API, no concrete classes should be exposed. We do the same in
C++, we use Pure Abstract Classes (which are mere header files) as our
public API and again no concrete C++ class should be exposed.

Jul 23 '05 #7
Victor Bazarov wrote:
Show-stoppers I ain't sure of, but consider if your class needs to
have a base class or two. How is that going to be automatically
generated?
Matthias Kaeppler wrote: Why? He can obtain its name from the ": public BC " part of the
child class definition (which can be found in the source file if I
got that right).
You could then (given that the filenames are identical to the class
names) produce an include directive in the generated header which
includes the base class definition (#include BC.hpp).


I was planning on allowing an optional "public" modifier to cover that
case.

#include "Base.h" @public
#include "Helper.h"
struct PointerOnly; @public

Includes and forward declarations marked "@public" would be put in the
header file, others would be put in the CPP file. This would, I think,
allow for most of the flexibility you'd have if you were writing the
header and CPP files by hand.

However, I've also been considering providing more automation (such as
the one Matthias described) for those who are willing to follow certain
naming/coding conventions.

Jul 23 '05 #8
> Kannan Goundan wrote:
[snip]
There are a few reasons I don't like C++ header files:

1. The C++ header file also includes stuff that isn't part of
an API contract (private methods/fields, inline method
implementations ).

2. I should only have to worry about API compatibility for
external APIs. When I'm changing the implementation details
of my classes, I don't want to have to make every signature
change in two places.

I want to be able to do things the way they are done in Java
and C#.

Andrew McDonagh wrote: You can do this in C++ as you can in Java.

In Java we have classes and interfaces. When these are used as
part of a public API, everything they contain is viewable by
the end user. Its the same with C++ header files.

However, the external public API is just that, its an
Application Programming INTERFACE.

What we do in Java, is define a series of Interfaces which are
our public API, no concrete classes should be exposed. We do
the same in C++, we use Pure Abstract Classes (which are mere
header files) as our public API and again no concrete C++ class
should be exposed.


The problem I was trying to solve is the one of having to maintain C++
header files. I want a program to generate my header files for me.
That's what I meant when I said I wanted something like Java.

About only exposing pure abstract classes... I'm not convinced that all
libraries can withstand such a limitation. First of all, there's the
performance hit virtual calls. Second, all objects will have to be
heap allocated. You'll have to use some wrapper class to get RAII.
Third, you can't inherit from a class in the library. You'd have to
roll your own fake adaptor-like inheritance technique. This will be
slower because of the extra indirection and will punish the heap by
creating two objects for every instance of the base class.

This may be acceptable for many libraries (large objects, relatively
few app->library calls), but definitely not for all. BTW, I use the
term API for any library interface. If you use it to describe only a
certain category of libraries then my objections may not apply.

Jul 23 '05 #9
Kannan Goundan wrote:

There are a few reasons I don't like C++ header files:

1. The C++ header file also includes stuff that isn't part of an API
contract (private methods/fields, inline method implementations ).

You don't have to put any private methods or fields in the header files,
nor do you have to write inline methods either.

I want to be able to do things the way they are done in Java and C#.


The main problem you'll encounter is the compile-the-world syndrome
unless you are very careful about not recreating the headers unless
absolutely necessary.

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2435
by: Rasmus Fogh | last post by:
Someone raised the question of automatic code generation a few weeks back. And yes, we (CCPN) are using automatic Python code generation in a major way. Basically we are making data models in UML, and using automatic code generation to make Python APIs, XML I/O etc. (more below). We can be found at http://www.ccpn.ac.uk/index.html As a...
6
10227
by: Matt | last post by:
I have begun designing and programming in C++ after a several years away from software engineering/programming. I am looking for an "automatic C++ header generator." I have what seems to be fairly simple requirements: 1) command-line oriented tool 2) input .cpp files, output .h files 3) do not change the .cpp files if directed
2
5505
by: guoqi zheng | last post by:
dear sir, I am using itextShap for pdf generation. I know I can insert image into it, I can add header to it as well. However, I can not add an image as a header. Does any one has experience with it and know how to insert an image header to the pdf file? This image is our company logo which we would like it to appear on every
4
2521
by: Petterson Mikael | last post by:
Hi, Anyone out there that knows of a automatic test generation tool for cpp? Another requirement is that the test results should be presented in xml. All hints appreciated. cheers, //mikael
0
312
by: JoshforRefugee | last post by:
heard that we can do automatic code generation using macros, but not sure how can I pursue this. Here is my problem. In my env, I have class A,B and C. All of them has constructors, and few common methods, like reset, and execute. now my env(main) class actually is where I am creating this objects. in .h A myA; B myB;
25
2634
by: sidd | last post by:
In the following code: int i = 5; ---it goes to .data segment int j; ---it goes to bss segment int main() { int c; int i = 5; ---stack
1
1552
by: toto | last post by:
Dear friends, I'm quite new in template programming but they are giving me a very hard time. I'm using gcc as a compiler and I'm mainly develop for linux and windows. My problem is that I have a template class defined and into a file, say class.h, and implemented into another (class.cc). If I put the implementation in the same header...
0
7579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7499
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8013
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5414
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3539
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3530
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.