PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1

Chapter 5. Coding Rule

Including the Header

Include SophiaFramewrok.hpp at the head of the source code. To use the extended interface of KDDI Corporation, you need to define the TARGET_EXTENSION_KDDI macro before the include statement as below.

#define TARGET_EXTENSION_KDDI
#include <SophiaFramework.hpp>

Types / Constants / Modifiers

Use different types from standard C++.

Table 5.1. SophiaFramework / Standard C++ / BREW: Types

SophiaFramework Standard C++ BREW (C language) Description
Bool bool boolean boolean type
Void void void void type
UInt08 unsigned char uint8 unsigned 8-bit integer
SIntN signed int int signed integer
SInt16 signed short int16 signed 16-bit integer
UInt32 unsigned long int uint32 unsigned 32-bit integer(other types: Integer types
Float32 float float 32-bit floating point
Float64 double double 64-bit floating point
Byte unsigned char byte byte type
AChar char char 1-byte character type
WChar w_char AECHAR 2-byte character type
Ptr * * pointer type(example: use BoolPtr instead of Bool*
Ref & & reference type(example: use BoolRef instead of Bool&

Table 5.2. SophiaFramework / Standard C++ / BREW: Constants

SophiaFramework Standard C++ BREW (C language) Description
null NULL NULL null pointer
true true TRUE boolean value that represents true
false false FALSE boolean value that represents false

Table 5.3. SophiaFramework / Standard C++ / BREW: Modifiers

SophiaFramework Standard C++ BREW (C language) Description
Const const const constant (example: use BoolConst instead of const Bool, BoolConstPtr instead of const BoolPtr )
Volatile volatile volatile volatile (example: use BoolVolatile instead of volatile Bool, BoolVolatilePtr instead of volatile BoolPtr )
[Note] Note
SophiaFramework Type, Constant, and Modifier differ from those of standard C++ and BREW (C language).

Error Handling

Use pseudo syntax: "catch-throw" which is compatible with C ++ for the error handling.

The value of the error is the error type.

Function Description
static_catch Catch the error.
static_try Check whether or not an error has occurred.
static_throw Set the error.
static_throws Indicate that the function may throw an error.(no precessing will be do)

Example

class MyApp : public SFCApplication {
  public:
    Void SubFunc(Void) static_throws;  // <- SubFunc throws the error
                                       // static_throws indicates the action above
    Void MainFunc(Void);
    ...
};

Void SubFunc(Void) static_throws       // <- SubFunc throws the error
                                       // static_throws indicates the action above
{
    if (static_try()) {  // checks whether an error has occurred or not
        // when there is no error

        // create the object
        XXXObjectPtr object = new XXXObject();
        if (object == null) { // when fails to create

            static_throw(SFERR_NO_MEMORY);  // throw the error
                                            // SFERR_NO_MEMORY: out of memory

            return; // static_throw does not return automatically
                    // therefore return manually
        }
    }
    ...
}

Void MainFunc(Void)
{
    ...
    SubFunc();
    switch (static_catch()) {
        // error handling for various errors
        case SFERR_NO_MEMORY: // when out of memory
            ...
        case SFERR_NO_ERROR:  // when no error has occurred
            ...
    }
    ...
}