The CORBA mappings for some primitive datatypes are given in the following table.
| IDL Data Type | C++ Mapping | Data Size |
| short | CORBA::Short | size >=16bits |
| unsigned short | CORBA::UShort | size >= 16 bits |
| long | CORBA::Long | size>=32 bits |
| unsigned long | CORBA::ULong | size>=32 bits |
| char | CORBA::Char | size>=8 |
| boolean | CORBA::Boolean | No Size specified |
| octet | CORBA::Octet | size>=8 |
| float | CORBA::Float | size>=32 bits |
| double | CORBA::Double | size>=64bits |
As all of the above data types follow a similar pattern, the table below demonstrates the long IDL data type. After this table, there are four examples of using the long as an in, out, inout, and return values for a some method.
| Data Type(IDL) | in | out | inout | return |
| long | CORBA::Long arg | CORBA::Long &arg | CORBA::Long &arg | CORBA::Long |
The first example is of an interface IData with a single operation TheData that takes an in argument of an long. The mappings for writing both the server and client are given.
// Example #1 :CORBA IDL - in argument of simple data types
interface IData
{
void TheData(in long data);
};
|
// Servant Code
class MyHelloServant: public virtual POA_IData
{
public:
void TheData(const CORBA::Long data);
};
/////////////////////////////////////////////////
void MyHelloServant::TheData(const CORBA::Long data)
{
cout << "Client sent:"<<data<<endl;
}
|
// Client Code
{ IData_var obj;
/* .... Initialize obj code is here ....*/
obj->TheData(1234);
CORBA::Long x=123;
obj->TheData(x);
}
|
The Example #2 demonstrates an out long argument.
// Example #2 :CORBA IDL
interface IData
{
void TheData(out long data);
};
|
// Servant Code
class MyHelloServant: public virtual POA_IData
{
public:
void TheData(CORBA::Long &data);
};
////////////////////////////////////////
void MyHelloServant::TheData(CORBA::Long &data)
{
data = 1234; // sending back 1234
}
|
// Client Code
{ IData_var obj;
/* .... Initialize obj code is here ....*/
CORBA::Long x;
obj->TheData(x);
cout << "Server sent:" << x <<endl;
}
|
The Example #3 demonstrates an inout mapping of a long.
// Example #3 :CORBA IDL
interface IData
{
void TheData(inout long data);
};
|
// Servant Code
class MyHelloServant: public virtual POA_IData
{
public:
void TheData(CORBA::Long &data);
};
/////////////////////////////////////////
void MyHelloServant::TheData(CORBA::Long &data)
{
cout << "Client sent "<<data<<endl;
data = 1234; // sending back 1234
}
|
// Client Code
{ IData_var obj;
/* .... Initialize obj code is here ....*/
CORBA::Long x=1111;
obj->TheData(x);
cout << "Server sent:" << x <<endl;
}
|
The Example #4 demonstrates a return value of a long.
// Example #4 :CORBA IDL
interface IData
{
long TheData();
};
|
// Servant Code
class MyHelloServant: public virtual POA_IData
{
public:
CORBA::Long TheData(void);
};
////////////////////////////////////////
CORBA::Long MyHelloServant::TheData(void)
{
return 1234;
}
|
// Client Code
{ IData_var obj;
/* .... Initialize obj code is here ....*/
CORBA::Long x;
x=obj->TheData();
cout << "Server sent:" << x <<endl;
}
|
When you are using boolean in your IDL code, you have to be careful about what to use to initialize the variable. If you are using an ANSI-C++ compiler, boolean variables can have a value of true or false. But, for portability, use 1 for true and 0 for false. The Next Example #4 demonstrates a return value using a boolean type.
// Example #5 :CORBA IDL
interface IData
{
boolean IsTrue();
};
|
// Servant Code
class MyHelloServant: public virtual POA_IData
{
public:
CORBA::Boolean TheData(void);
};
///////////////////////////////////////////////
CORBA::Boolean MyHelloServant::TheData(void)
{
return 1; // return TRUE
}
|
// Client Code
{ IData_var obj;
/* .... Initialize obj code is here ....*/
if(obj->IsTrue()) { cout<< "Function returned true"<<endl; }
}
|
The Last Example(#6) of using data types is a complex function that takes several different data-types.
// Example #6 :CORBA IDL
interface IData
{
boolean TheData(in long rangebegin,in long rangeend,out char ch,
inout float age);
};
|
// Servant Code
class MyHelloServant: public virtual POA_IData
{
public:
CORBA::Boolean TheData(const CORBA::Long rangebegin,const CORBA::Long rangeend
,CORBA::Char &ch,CORBA::Float age);
};
///////////////////////////////////////
CORBA::Boolean MyHelloServant::TheData(const CORBA::Long rangebegin,const CORBA::Long rangeend
,CORBA::Char &ch,CORBA::Float age)
{
ch='A'; cout<<age; age = rangebegin+rangeend; return 0;
}
|
// Client Code
{ IData_var obj;
/* .... Initialize obj code is here ....*/
CORBA::Char ch; CORBA::Float age=123;
if ( obj->TheData(10,20,ch,age);
cout << "Server sent:" << age << " "<< ch<<endl;
}
|