![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |
Table 23.1. Macro to change SophiaFramework behavior
| Macro | Description |
|---|---|
| TARGET_EXTENSION_KDDI | The BREW Japan Extension Package provided by KDDI is used. |
| TARGET_BUILD_DEBUG | Build is done for debugging. |
By default, the [Using KDDI Extension Interface] option is not set.
To use the BREW Japan Extension Package, TARGET_EXTENSION_KDDI macro need to be defined by the #define directive before including the SophiaFramework.hpp header file.
When the TARGET_BUILD_DEBUG macro is defined, all macros of Macro for Debugging becomes valid.
Furthermore, the TARGET_BUILD_DEBUG macro will be automatically defined when building modules for the BREW Simulator.
The following macros are for using the proper code depending on the kind of BREW version or compiler, etc.
Table 23.2. Macro to declare code object
| Macro | Description |
|---|---|
| TARGET_COMPILER_MSVCPP | The target compiler is Visual C++. |
| TARGET_COMPILER_ARMCPP | The target compiler is ARM. |
| TARGET_COMPILER_GNUCPP | The target compiler is GNU g++. |
| TARGET_ENDIAN_BIG | Big endian. |
| TARGET_ENDIAN_LITTLE | Little endian. |
| TARGET_ENVIRONMENT_SIMULATOR | BREW Simulator. |
| TARGET_ENVIRONMENT_PHYSICAL | Physical device. |
| TARGET_VERSION_MAJOR | BREW SDK Major version. |
| TARGET_VERSION_MINOR | BREW SDK Minor version. |
| TARGET_VERSION_REVISION | BREW SDK Revision. |
| TARGET_VERSION_BUILD | BREW SDK Build number. |
| TARGET_VERSION_EQ | Defined BREW SDK version and given version are identical. |
| TARGET_VERSION_NE | Defined BREW SDK version and given version are different. |
| TARGET_VERSION_LT | Defined BREW SDK version is less than given version. |
| TARGET_VERSION_LE | Defined BREW SDK version is not greater than given version. |
| TARGET_VERSION_GT | Defined BREW SDK version is greater than given version. |
| TARGET_VERSION_GE | Defined BREW SDK version is not less than given version. |
| TARGET_BUILD_RELEASE | Build is done for release. |
![]() |
Note |
|---|---|
| The above are macros for SophiaFramework only, which cannot be redefined by the developer. | |
TARGET_COMPILER_MSVCPP, TARGET_COMPILER_ARMCPP, and TARGET_COMPILER_GNUCPP are the macros for using the proper code depending on the kind of compiler.
UInt32 test(Void)
{
#if defined TARGET_COMPILER_ARMCPP
UInt32 temp;
asm {
LDR temp, [pc, #-8]
}
return temp;
#endif
return 0;
}
TARGET_ENDIAN_BIG and TARGET_ENDIAN_LITTLE are the macros for using the proper code depending on the kind of endian.
TARGET_ENVIRONMENT_SIMULATOR and TARGET_ENVIRONMENT_PHYSICAL are the macros for using the proper code depending on the simulator or the kind of runtime device.
TARGET_VERSION_MAJOR, TARGET_VERSION_MINOR, TARGET_VERSION_REVISION, and TARGET_VERSION_BUILD are the macros for displaying the BREW SDK version, which is automatically set depending on the kind of BREW SDK to be used for compilation.
For example, if the BREW SDK version is 2.1.0 and the Build Number is 20, the values are set as follows:
TARGET_VERSION_MINOR = 1, TARGET_VERSION_REVISION = 0, TARGET_VERSION_BUILD = 20.
TARGET_VERSION_EQ, TARGET_VERSION_NE, TARGET_VERSION_LT, TARGET_VERSION_LE, TARGET_VERSION_GT, and TARGET_VERSION_GE are the macros for comparing the BREW SDK version with a specified arguments, which are Major version, Minor version, and Revision in this order.
#if TARGET_VERSION_GE(2,1,0) // for BREW SDK 2.1.0 or over ... #else // for under BREW SDK 2.1.0 ... #endif
Table 23.3. Macro to show maximum and minimum values
| Macro | Meaning |
|---|---|
| BOOL_MAXIMUM | maximum value of Bool type |
| BOOL_MINIMUM | minimum value of Bool type |
| SINTN_MAXIMUM | maximum value of SIntN type |
| SINTN_MINIMUM | minimum value of SIntN type |
| UINTN_MAXIMUM | maximum value of UIntN type |
| UINTN_MINIMUM | minimum value of UIntN type |
| SINT08_MAXIMUM | maximum value of SInt08 type |
| SINT08_MINIMUM | minimum value of SInt08 type |
| UINT08_MAXIMUM | maximum value of UInt08 type |
| UINT08_MINIMUM | minimum value of UInt08 type |
| SINT16_MAXIMUM | maximum value of SInt16 type |
| SINT16_MINIMUM | minimum value of SInt16 type |
| UINT16_MAXIMUM | maximum value of UInt16 type |
| UINT16_MINIMUM | minimum value of UInt16 type |
| SINT32_MAXIMUM | SInt32 type maximum value |
| SINT32_MINIMUM | SInt32 type minimum value |
| UINT32_MAXIMUM | maximum value of UInt32 type |
| UINT32_MINIMUM | minimum value of UInt32 type |
| SINT64_MAXIMUM | maximum value of SInt64 type |
| SINT64_MINIMUM | minimum value of SInt64 type |
| UINT64_MAXIMUM | maximum value of UInt64 type |
| UINT64_MINIMUM | minimum value of UInt64 type |
| FLOAT32_MAXIMUM | maximum value of Float32 type |
| FLOAT32_MINIMUM | minimum value of Float32 type |
| FLOAT64_MAXIMUM | maximum value of Float64 type |
| FLOAT64_MINIMUM | minimum value of Float64 type |
Related Information: Type
Related Information: Error Type
The pseudo exception handling mechanism similar to the exception handling mechanism in standard C++ language is provided with SophiaFramework.
Table 23.4. Pseudo exception mechanism
| Function | Description |
|---|---|
| static_catch | Get the current error. |
| static_try | Confirm whether the error is set or not. |
| static_throw | Set the error. |
The static_throws is available as a mark of function where errors might be set using this pseudo exception handling mechanism. (No processing will be done.)
Pseudo exception mechanism is provided as the static_exception class.
template <typename T>
class static_exception {
public:
T const& static_catch(Void) const;
protected:
Bool static_try(Void) const;
Void static_throw(static_exception<T> const& param);
Void static_throw(T const& param);
};
The above pseudo exception mechanism can be used in the classes such as SFCApplication or SFRApplication, which are derived from the static_exception<T> class.
![]() |
The difference with the standard C++ exception handling mechanism |
|---|---|
The execution control will not exit the function at which the static_throw statement is executed. To exit there, set the return statement immediately after the static_throw statement. | |
class MyApp : public SFCApplication {
SFMSEALCOPY(MyApp)
private:
Void SubFunc(Void) static_throws;
SFCError MyAllocation(Void) { ... } // function where errors might occur
public:
Void MainFunc(Void);
...
};
Void SubFunc(Void) static_throws
{
// confirm current error
if (static_try()) {
// when no error is set
static_throw(MyAllocation()); // set error
}
...
}
Void MainFunc(Void)
{
...
SubFunc();
switch (static_catch()) {
// error handling
...
}
...
}
The SFMTYPEDEFBASE macro declares the reference, pointer, and handle types.
SFMTYPEDEFBASE(Base)
The SFMTYPEDEFBASE macro takes the type name as an argument, and generates the following type declarations.
typedef Base& BaseRef; typedef Base* BasePtr; typedef Base** BaseHandle;
The SFMTYPEDEFVOLATILE macro declares the reference, pointer, handle types with the volatile modifier.
SFMTYPEDEFVOLATILE(Base)
The SFMTYPEDEFVOLATILE macro takes the type name as an argument, and generates the following type declarations.
typedef Base volatile BaseVolatile; typedef BaseVolatile& BaseVolatileRef; typedef BaseVolatile* BaseVolatilePtr; typedef BaseVolatile** BaseVolatileHandle;
The SFMTYPEDEFCONST macro declares the reference, pointer, handle types with the const modifier.
SFMTYPEDEFCONST(Base)
The SFMTYPEDEFCONST macro takes the type name as an argument, and generates the following type declarations.
typedef Base const BaseConst; typedef BaseConst& BaseConstRef; typedef BaseConst* BaseConstPtr; typedef BaseConst** BaseConstHandle;
The SFMTYPEDEFVOLATILECONST macro declares the reference, pointer, handle types with the volatile const modifier.
SFMTYPEDEFVOLATILECONST(Base)
The SFMTYPEDEFVOLATILECONST macro takes the type name as an argument, and generates the following type declarations.
typedef Base volatile const BaseVolatileConst; typedef BaseVolatileConst& BaseVolatileConstRef; typedef BaseVolatileConst* BaseVolatileConstPtr; typedef BaseVolatileConst** BaseVolatileConstHandle;
The SFMTYPEDEFPACK macro calls the SFMTYPEDEFBASE macro for a certain type, its type with volatile modifier, its type with const modifier, and its type with volatile const modifier.
SFMTYPEDEFPACK(Base)
The SFMTYPEDEFPACK macro takes the type name as an argument, and declares the types equivalent to the following macros.
SFMTYPEDEFBASE(Base) SFMTYPEDEFVOLATILE(Base) SFMTYPEDEFCONST(Base) SFMTYPEDEFVOLATILECONST(Base)
The SFMTYPEDEFTYPE macro calls the SFMTYPEDEFPACK macro for a certain type, its pointer type, and its handle type.
SFMTYPEDEFTYPE(Base)
The SFMTYPEDEFTYPE macro takes the type name as an argument, and declares the types equivalent to the following macros.
SFMTYPEDEFPACK(Base) SFMTYPEDEFPACK(BasePtr) SFMTYPEDEFPACK(BaseHandle)
The SFMTYPEDEFALIAS macro calls the SFMTYPEDEFTYPE macro for the pre-defined alias of a certain type.
SFMTYPEDEFALIAS(Type, Alias)
The SFMTYPEDEFALIAS macro takes the type name and its alias as arguments, and declares the types equivalent to the following macros.
typedef Type Alias; SFMTYPEDEFTYPE(Alias);
The SFMTYPEDEFCLASS macro declares a class and its related types.
SFMTYPEDEFCLASS(Class)
The SFMTYPEDEFCLASS macro takes the class name as an argument, and declares the types equivalent to the following macros.
class Class; SFMTYPEDEFTYPE(Class);
SFMTYPEDEFCLASS(A)
class A {
...
}
The SFMTYPEDEFTYPE macro is expanded as follows.
SFMTYPEDEFCLASS(MyClass);
class MyClass {
private:
...
};
class MyClass;
typedef MyClass& MyClassRef;
typedef MyClass* MyClassPtr;
typedef MyClass** MyClassHandle;
typedef MyClass volatile MyClassVolatile;
typedef MyClass volatile& MyClassVolatileRef;
typedef MyClass volatile* MyClassVolatilePtr;
typedef MyClass volatile** MyClassVolatileHandle;
typedef MyClass const MyClassConst;
typedef MyClass const& MyClassConstRef;
typedef MyClass const* MyClassConstPtr;
typedef MyClass const** MyClassConstHandle;
typedef MyClass volatile const MyClassVolatileConst;
typedef MyClass volatile const& MyClassVolatileConstRef;
typedef MyClass volatile const* MyClassVolatileConstPtr;
typedef MyClass volatile const** MyClassVolatileConstHandle;
typedef (MyClass*)& MyClassPtrRef;
typedef (MyClass*)* MyClassPtrPtr;
typedef (MyClass*)** MyClassPtrHandle;
typedef MyClass* volatile MyClassPtrVolatile;
typedef MyClass* volatile& MyClassPtrVolatileRef;
typedef MyClass* volatile* MyClassPtrVolatilePtr;
typedef MyClass* volatile** MyClassPtrVolatileHandle;
typedef MyClass* const MyClassPtrConst;
typedef MyClass* const& MyClassPtrConstRef;
typedef MyClass* const* MyClassPtrConstPtr;
typedef MyClass* const** MyClassPtrConstHandle;
typedef MyClass* volatile const MyClassPtrVolatileConst;
typedef MyClass* volatile const& MyClassPtrVolatileConstRef;
typedef MyClass* volatile const* MyClassPtrVolatileConstPtr;
typedef MyClass* volatile const** MyClassPtrVolatileConstHandle;
typedef (MyClass**)& MyClassHandleRef;
typedef (MyClass**)* MyClassHandlePtr;
typedef (MyClass**)** MyClassHandleHandle;
typedef MyClass** volatile MyClassHandleVolatile;
typedef MyClass** volatile& MyClassHandleVolatileRef;
typedef MyClass** volatile* MyClassHandleVolatilePtr;
typedef MyClass** volatile** MyClassHandleVolatileHandle;
typedef MyClass** const MyClassHandleConst;
typedef MyClass** const& MyClassHandleConstRef;
typedef MyClass** const* MyClassHandleConstPtr;
typedef MyClass** const** MyClassHandleConstHandle;
typedef MyClass** volatile const MyClassHandleVolatileConst;
typedef MyClass** volatile const& MyClassHandleVolatileConstRef;
typedef MyClass** volatile const* MyClassHandleVolatileConstPtr;
typedef MyClass** volatile const**MyClassHandleVolatileConstHandle;
class MyClass {
private:
...
};
The SFMTYPEDEFWRAPPER macro declares a wrapper class name and its related types.
SFMTYPEDEFWRAPPER(Class)
The SFMTYPEDEFWRAPPER macro takes the class name as an argument, and declares the types equivalent to the following macros.
SFMTYPEDEFCLASS(Class) SFMTYPEDEFALIAS(SFXBrewPointer<Class>, Class##Smp) SFMTYPEDEFALIAS(SFXBrewPointer<Class volatile>, Class##VolatileSmp) SFMTYPEDEFALIAS(SFXBrewPointer<Class const>, Class##ConstSmp) SFMTYPEDEFALIAS(SFXBrewPointer<Class volatile const>, Class##VolatileConstSmp)
The SFMTYPEDEFSTRUCT macro declares a structure and its related types.
SFMTYPEDEFSTRUCT(Struct)
The SFMTYPEDEFSTRUCT macro takes the structure name as an argument, and declare the types equivalent to the following macros.
struct Struct; SFMTYPEDEFTYPE(Struct);
The SFMTYPEDEFUNION macro declares a union and its related types.
SFMTYPEDEFUNION(Union)
The SFMTYPEDEFUNION macro takes the union name as an argument, and declares the types equivalent to the following macros.
union Union; SFMTYPEDEFTYPE(Union);
There are macros that prohibit the developer from copying or assigning an instance.
The SFMSEALCONSTRUCT macro prohibits the developer from creating an instance.
SFMSEALCONSTRUCT(Class)
You cannot create the instance of class which consists of static members only.
The SFMSEALCONSTRUCT macro takes the class name as an argument, and is expanded as follows.
private: explicit Class(void); Class(Class const&); ~Class(void); const Class& operator=(Class const&);
SFMTYPEDEFCLASS(A) class A { SFMSEALCONSTRUCT(A) ... }
The SFMSEALWRAPPER macro prohibits the developer from creating an instance of wrapper class.
SFMSEALWRAPPER(Class)
For a wrapper class, use the SFMSEALWRAPPER macro instead of SFMSEALCONSTRUCT.
The SFMSEALCOPY macro prohibits the developer from copying an instance, and define a copy constructor and an assign operator both of which are private.
SFMSEALCOPY(Class)
In the classes such as for buffer management, the problem on copying an instance can be avoided.
The SFMSEALCOPY macro takes the class name as an argument, and is expanded as follows.
private: Class(Class const&); Class& operator=(Class const&);
The SFMSEALASSIGN macro prohibits the developer from assigning an instance, and defines an assign operator of private.
SFMSEALASSIGN(Class)
The problem on assigning an instance can be avoided.
The SFMSEALASSIGN macro takes the class name as an argument, and is expanded as follows.
private: Class& operator=(Class const&);
The type conversion operators available in Visual C++ such as reinterpret_cast, static_cast, dynamic_cast, and const_cast cannot be used in the ARM compiler such as RealView Compilation Tools for BREW 1.2.
![]() |
Note |
|---|---|
| SophiaFramework replaces these type conversion operators with the type conversion operators of C language, though these operators depend on variable and function as the table below. | |
Table 23.5. Standard C++ and SophiaFramework Type Conversion Operators
| Standard C++ | For SophiaFramework variable | For SophiaFramework function |
|---|---|---|
| reinterpret_cast | reinterpret_cast | reinterpret_function_cast |
| static_cast | static_cast | static_function_cast |
| dynamic_cast | dynamic_cast | dynamic_function_cast |
| const_cast | const_cast | const_function_cast |
![]() |
The dynamic_cast operator on real device |
|---|---|
Although the ARM compiler replaces the dynamic_cast with the type cast operator of C language, there is no guarantee that a type will downcast to the correct type. | |
![]() |
Type conversion macro for constants |
|---|---|
When the type conversion macro is used for constants, its binary file after compilation tends to be bigger. | |
The interface_cast operator is the type conversion operator to convert a pointer to the BREW interface into a pointer to the corresponding SophiaFramework class, and vice versa.
More specifically, the interface_cast operator casts between the I????? interface of BREW and the SFB????? class of SophiaFramework, and between the AEE????? interface of BREW and the SFX????? class of SophiaFramework regarding color, shape, callback.
The code to use the interface_cast operator is as below.
SFBFileMgrSmp xfilemgr; // SFBFileMgr class(smart pointer)
IFileMgr* ifilemgr; // IFileMgr interface
ifilemgr = interface_cast(xfilemgr.Get()); // SFBFileMgr class -> IFileMgr interface
SFBFileMgrSmp xfilemgr; // SFBFileMgr class(smart pointer)
IFileMgr* ifilemgr; // IFileMgr interface
xfilemgr.Set(interface_cast(ifilemgr)); // IFileMgr interface -> SFBFileMgr class
The atomic_cast operator is the type conversion operator to convert a pointer to the class such as Shape and Color where the AtomRec structure is defined into a pointer to its AtomRec structure, and vice versa.
The code to use the atomic_cast operator is as below.
Void my_func(SFXRectangleConst rects[2])
{
// do something.
......
}
SFXRectangle::AtomRecConst rects[] = {
{0, 0, 100, 100},
{0, 0, 50, 50}
};
my_func(atomic_cast(rects));
The lengthof macro is for getting the length of array.
#define lengthof(Array) (sizeof((Array)) / sizeof((Array)[0]))
The align64of macro is for calculating the size of type aligned at the 8-bytes boundary.
Beside the align64of macro, there are the align08of, align16of, and align32of macros for 1-byte, 2-bytes, and 4-bytes boundaries respectively.
#define align08of(type) ((sizeof(type) + 0) & ~0) #define align16of(type) ((sizeof(type) + 1) & ~1) #define align32of(type) ((sizeof(type) + 3) & ~3) #define align64of(type) ((sizeof(type) + 7) & ~7)
The cluster64of macro is for calculating how many 8-bytes clusters are neccessary for the type aligned at 8-bytes boundary.
Beside the cluster64of macro, there are the cluster08of, cluster16of, and cluster32of macros for 1-byte, 2-bytes, and 4-bytes boundaries respectively.
#define cluster08of(type) ((sizeof(type) + 0) >> 0) #define cluster16of(type) ((sizeof(type) + 1) >> 1) #define cluster32of(type) ((sizeof(type) + 3) >> 2) #define cluster64of(type) ((sizeof(type) + 7) >> 3)
The following are the macros for generating the character literal as an identifier for object such as responder type or responder attribute.
Table 23.6. Macro for generating literal
| Macro | Description |
|---|---|
| one_char_code(x) | Generate 1-character literal. |
| two_char_code(x, y) | Generate 2-characters literal. |
| four_char_code(w, x, y, z) | Generate 4-characters literal. |
Each argument is a value of AChar type (a value of binary type can be also specified).
![]() |
For four_char_code macro |
|---|---|
The 4-characters literals of lower-case alphabet are reserved for SophiaFramework. | |
Generate the 4-characters literal.
SFCType val = four_char_code('A', 'b', 'c', 'd');
ACharPtr p = reinterpret_cast<ACharPtr>(&val);
The alignment on the memory of these generated values is the same regardless of endian.
In the example above, the value of *p will be 'A'.
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|