C++ Refacotring/Seperating app?

Discussion about everything. New games, 3d math, development tips...
Post Reply
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

C++ Refacotring/Seperating app?

Post by dudMaN »

Hey all.

I recently made an entire library coding like this:

Code: Select all

class foo {
 public:
  void bar() {
   // ...
  // ...
 }
};
and now, i'm trying to release only .h and .a/.lib files, and i realise i cant do it with my current coding style, as i'd need .h and .cpp files to do it :cry:

Is there an app that can seperate that kind of code into:

Code: Select all

class foo {
 public:
  void bar();
};
and

Code: Select all

void foo::bar() {
 // ...
 // ...
}
Thanks!!

-dudMan
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Eww, get rid of those java-style brackets.

Code: Select all

class foo 
{
public:
    void bar() 
    {
        // ...
        // ...
    }
}; 
Much better...
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

hehe brackets are fun huh? Personally i prefer the 'java style' ones (though i was taught java first so maybe that's why, but i wouldn't say it's java style, just a personal style choice) so i end up converting all other people's code i come across into that style when i use it :lol:

I wouldn't have thought there's any program to do this, but it's a really simple task so you should be able to manage it yourself as you know exactly what you need to do right?

I suppose if you've got like 50 source files it might be a bit tedious, but that's why you should have planned ahead and realised you'd need to do this right from the start ;)
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

This might be an idea opportunity to learn a language that's good at text processing, like Perl or Python. ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

JP & BlindSide: java brackets ftw, and i was taught java first too :D

rogerborg: ok, i'll work on learning python =)

and i'll refactor it myself ok, most of the source files are only <100 lines so it shouldnt be a problem, but theres this one really big one thatll take all year :|

ty everyone :)

-dudMan
Complete Irrlicht Beginners Tutorial
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=24898
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

dudMaN wrote:rogerborg: ok, i'll work on learning python =)
Perl or ruby are much better for that than python. Just as a note. ;)
CuteAlien
Admin
Posts: 9930
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

I recommend using a lex/yacc combination, because I fear to make a tool that will work in all cases you will need to write a c++ parser. Doing it by hand is most likely faster.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

lex/yacc is serious overkill. You can catch all cases, when you preformat your code consistently, e.g using greatcode.
This way you can make parsing the code way easier.

Maybe you are faster when doing it with hand. But when you learn a scripting language like perl/ruby now and even when you need a bit longer this time, you will save a huge amount of time later in your career with being able to use scripting languages for simple code generation/manipulation tasks. Getting used to it early is not a disadvantage.
Post Reply