int main (int argc, char * argv [])
{
int i;
for (i = 0; i < 10; i++)
{
int ret = myfunc (0, 1, 2);
if (ret <= 10) return ret;
}
return 0;
}
Your classes must all be clearly documented, to allow other developers to use them, and yourself to remember how they work. You'll have to document at file level, class level and member level.
/* $Id: Copyright (C) <year> <your name> Part of the Adonthell Project http://adonthell.linuxgames.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. See the COPYING file for more details. */ /** * @file <filename> * @author <yourname> <<your_email@adress>> * * @brief <Briefly describe what's in this file> * * */
The first block is for Copyright issues. You clearly show that this file is distributed under the terms of the GPL ; that it comes with no warranty and that you are the copyright holder of the file. The Copyright line has to show all the years this file has been worked on. Several persons may hold the copyright of a file. In this case, put one Copyright line per person. The $Id: line is for the CVS system. It will put useful information on this line when the file will be committed, indicating who last modified this file, when, and which version number it is.
The second block is for referencing this file into Doxygen's documentation system. It's quite explicit and MANDATORY if you want to document the classes in this file.
/**
* This very powerful class blah blah....
* blah blah blah blah blah
* blah blah blah blah.
*
* @bug Uh, I still have to write the members.
*
*/
class my_very_cool_class
{
.....
}
Don't hesitate to use Doxygen's special tags, like \note or \bug.
class my_class
{
public:
/**
* Returns the square root of the parameter.
* @param a_number Number to calculate the square root of.
* @return Square root of a_number.
*/
float sqrt (float a_number);
}
Once you have done this, and rebuild the documentation, your class will appear in the Class Hierarchy diagram, with it's own documentation page and automatically generated Inheritance Diagram. Have a look at the Image Class Page for a sample of the result you can expect, and the image.h file (see the source code) to see how it has been done.
class animation
{
public:
// Constructor
animation ();
// Destructor
~animation ();
u_int16 length ()
{
return length_;
}
u_int16 height ()
{
return height_;
}
image * get_image (u_int16 pos)
{
return frame[pos];
}
.....
private:
u_int16 length_;
u_int16 height_;
vector <image> frame;
}
class image
{
public:
// Default constructor (the one available from Python)
image ();
#ifndef SWIG
// Creates an image of size (l, h)
image (u_int16 l, u_int16 h);
#endif
// This method makes it possible to reach the state of the second constructor
// from Python by doing: im = image (); im.resize (l, h);
// Moreover, it's also useful in other cases.
void resize (u_int16 l, u_int16 h);
...
};
class myclass
{
public:
......
/**
* Drawing method 1
*/
void draw (int x, int y);
#ifndef SWIG
/**
* Drawing method 2
* @attention Not available from Python. Use draw_part () instead.
* @sa draw_part ()
*/
void draw (int x, int y, int l, int h);
#endif
/**
* Synonym of draw (x, y, l, h) to guarantee it's availability from Python.
*/
void draw_part (int x, int y, int l, int h)
{
draw (x, y, l, h);
}
/**
* Copy operator (similar to copy ()).
*
* @attention Not available from Python. Use copy () instead.
* @sa copy ()
*/
myclass& operator = (const myclass & src);
/**
* Synonym of operator = to guarantee its access from Python.
*
* @sa operator =
*/
void copy (const myclass& src)
{
*this = src;
}
...
}
Don't forget to comment your methods accordingly to their access.
Functions synonym to Operators should have explicit names. As an operator could have several meanings (+ could be said "add" or "concat", for example) you are free to choose whatever name fits best with your usage.
Instead of passing your objects by value, you'll pass them by reference. That way, no memory is allocated, and actions are performed directly on your object. To make it obvious which methods modify the object you're passing and which don't, the following conventions has been set up:
void doesntmodify (const myclass & myobject);
void modify (myclass * myobject);
class myclass { ... private: myclass (myclass & src); };
1.5.6