Thursday, 25 September 2008

ENUM in C

I never know ENUM in C can be used in this way.

enum
{
CT3ID = 0,
CT3_HD,
CT3_IM,
CT3_MACHINE,
CT3FORM_ID,
CT3FORM_OUTPUT,
CT3FORM_RETURN,
CT3_REGION,
CT3_POLAR,
CT3_INAIR,
CT3_OUTLINE,
CT3_OPTIMISE,
CT3_COMP,
};

int main(){
printf("%d\n",CT3_IM);
return 0;
}

Friday, 5 September 2008

Document with Doxygen

This is a quite cool tool for your documentation.

It generates the documents based on the structure of the software and the comments in the codes. Of course there are some specific ways to comment in the codes which makes the generated codes more beautiful but it still works with the normal comments in the codes.

You can download it from its official website, Doxygen, or install it from Synaptic Package Manager if you are using Ubuntu. You may also like to install Graphviz to let Doxygen to generate more advanced graphs.

It is also easy to use Doxygen. Before it generates the documentation, it asks for a configuration file, which also can be generated automatically.

Use command
doxygen -g

It generates a template. And then you need to edit this file for your own purpose.

Set your project name first:
PROJECT_NAME = "myproject"

Set following to YES:
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES


If you like treeview, switch it on by setting:
GENERATE_TREEVIEW = YES

If you like the graphs, set:
HAVE_DOT = YES
CALL_GRAPH = YES

By default, it generates html and latex, but you also can generate other formats and the options are in the template file.

You can change the switches as you like, and it will show you the different features. Once you finish all settings, let Doxygen do the rest.
doxygen

It generates the documents you want!

JUnit testing in netbeans

Netbeans has JUnit test, which allows you to create your own test packages.

"Tools -> Create JUnit Tests" will generate a few Java tests in "Test packages". You either can use automatically generated tests to test your classes or write more test classes for your own tests.

Here is a very good example.

Tuesday, 2 September 2008

classes in C#

Class is used in C# as well as C++.

In the book,'Beginning Visual C== 2005', it is not very well described. I get lost in chapter 8 and chapter 9.

You might have to do some web search to understand what is described in this book.

Like C++, C# also has the abstract class by adding a keyword 'abstract' in front of the class name. Sealed class is new in C#, which is not inheritable. Sealed can avoid being override.

Interface is allowed in C#, which won't allow access modifiers like public, private, protected etc. There is no code body in interface and no field member as well.

Wednesday, 27 August 2008

ITK/VTK installation

It is a useful image processing tool.

Download the package from the website and uncompress it.

Login as root and put all the codes under /usr/local/bin.

The installation is quite simple.

ccmake .
cmake .
make

Job done.

Saturday, 26 July 2008

Debug in VS

Use print like function to out put the feedback from the code, like Console.WriteLine.

But use this method, there could be too many outputs from the program. In VS, you can choose View -> Output to see the information about compilation and execution.

Instead of using Console.WriteLine, there are other two options Debug.WriteLine and Trace.WriteLine. The first option only works in debug builds and second only works in release build. And both write to the Output window. They are included in System.Diagnostics.

In VS, user also can set up break point like other IDE does.

Tuesday, 22 July 2008

Functions in C#

Most functions in C# are the same as other programming languages.

To pass array in C#, it uses params <type>[] <name>

For example,
Define: static int SumVals(parame int[] vals)
Use: SumVals(1,2,3,4,5);

Pass the parameter by reference in C#, ref is the keyword. In this case even without returning the value from the function, the variable also can be changed.

For example,
Define: static void ShowChange(ref int val)
Use: ShowChange(MyVal);

Another similar way to pass the value is using the out keyword. The difference is that,
1. It is illegal to use an unassigned variable as a ref parameter, but it is fine as an out parameter;
2. An out parameter must be treated as an unassigned value;

Main() function can contain the 'string[] args' or have no argument.