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.

Monday, 21 July 2008

QT starting

I won't use QT if I can avoid it, because it does have some compatibility problem.

Good point is that it is free and not difficult to implement.

QT compilation and making uses,

qmake -project
qmake
make

In every GUI application there is one QApplication object, which manages various application-wide resources, such as the default font and cursor etc.

Header file <QApplication> and class name QApplication. For each class which is part of the public QT API, it has a header file with the same name, like QPushButton class has the same name header <QPushButton>.

The QApplication object must be created before any GUI-related features of Qt are used.

QApplication features:

QCoreApplication is QApplication's base class. It can be used when developing non-GUI applications.

In QCoreApplication::exec(), Qt receives and processes user and system events and passes these on to the appropriate widgets.

To change the default font,
QApplication::setFont()

Saturday, 12 July 2008

Array declare

In C#, the array is declared in the same ay as Java like,

int[] array1;
array1= new int[7];


foreach is "new" in C# to handle arrays.

string is a specific case of array. There are lots of functions developed for it, like trim to remove the whitespace etc.

Flow control in C#

The goto statement has been abandoned in lots of programming languages, but do not know why MicroSoft pick it up again in C#.

labelName:

goto labelName


It has the normal if ... else ..., switch ... case ..., do ... while ..., and for. Just like Java or C/C++, it can be broken by break.

Tuesday, 1 July 2008

C# From the beginning

In C/C++ the output uses printf. In Java it uses System.out.println. Now we are in C# and it uses Console.Writeln.

There is a keyword, region, which can be used to collapse lines of code into a single line.

Namespace has been used in C#. It has been also used in C++ and Java. By default the global namespace is applied. The keyword is namespace.

Follows are namespace examples,

namespace LevelOne
{
 // "NameOne" define
}

In global namespace, it needs to be used as LevelOne.NameOne.

For nested namespace,
namespace LevelOne
{
 namespace LevelTwo
 {
 // "NameTwo" define
 }
}

To use NameTwo in global namespace, it should be used as LevelOne.LevelTwo.NameTwo.

Tuesday, 24 June 2008

Starting VC#

My programming starts from Quick Basic, then Fortran, C/C++, Perl, and Java. Now I am quite interested in to have a look C#. Mono is the Linux version but it seems not working very well. Microsoft provides a free edition of C# under Windows, so I have the chance to have a go with it.

The book I am using is from WROX, Beginning Visual C# 2005.