CORBA Programming Reference
Frees memory allocated to a string.
void CORBA::string_free(char * Str);
This member function deallocates memory that was previously allocated to a string using the CORBA::string_alloc()
or
CORBA::string_dup()
member
functions. Passing a nil pointer to this function is acceptable and results in no action being performed.
This function may not throw CORBA exceptions.
char* s = CORBA::string_dup("hello world");
CORBA::string_free(s);
CORBA::string_alloc
CORBA::string_dup
Both bounded and unbounded wide string types are mapped to CORBA::WChar*
in C++. In addition, the CORBA module defines WString_var
and WString_out
classes. Each of these classes provides the same member functions with the same semantics as their string counterparts, except of course they deal with wide strings and wide characters.
Dynamic allocation and deallocation of wide strings must be performed via the following functions:
// C++
namespace CORBA {
// ...
WChar *wstring_alloc(ULong len);
WChar *wstring_dup(const WChar* ws);
void wstring_free(WChar*);
};
These member functions have the same semantics as the same functions for the string type, except they operate on wide strings.
A compliant mapping implementation provides overloaded operator<<
(insertion) and operator>>
(extraction) operators for using WString_var
and WString_out
directly with C++ iostreams.
For descriptions of these member functions, see the corresponding function for Strings.
Listing 14-1 shows a code example that uses wide strings and wide characters.
Listing 14-1 Wide Strings Example
// Get a string from the user:
cout << "String?";
char mixed[256]; // this should be big enough!
char lower[256];
char upper[256];
wchar_t wmixed[256];
cin >> mixed;
// Convert the string to a wide char string,
// because this is what the server will expect.
mbstowcs(wmixed, mixed, 256);
// Convert the string to upper case:
CORBA::WString_var v_upper = CORBA::wstring_dup(wmixed);
v_simple->to_upper(v_upper.inout());
wcstombs(upper, v_upper.in(), 256);
cout << upper << endl;
// Convert the string to lower case:
CORBA::WString_var v_lower = v_simple->to_lower(wmixed);
wcstombs(lower, v_lower.in(), 256);
cout << lower << endl;
// Everything succeeded:
return 0;
A TypeCode represents OMG IDL type information.
No constructors for TypeCodes are defined. However, in addition to the mapped interface, for each basic and defined OMG IDL type, an implementation provides access to a TypeCode pseudo-object reference (TypeCode_ptr
) of the form _tc_<type>
that may be used to set types in Any
, as arguments for equal
, and so on. In the names of these TypeCode reference constants, <type>
refers to the local name of the type within its defining scope. Each C++ _tc_<type>
constant is defined at the same scoping level as its matching type.
Like all other serverless objects, the C++ mapping for TypeCode provides a _nil()
operation that returns a nil object reference for a TypeCode. This operation can be used to initialize TypeCode references embedded within constructed types. However, a nil TypeCode reference may never be passed as an argument to an operation, since TypeCodes
are effectively passed as values, not as object references.
The mapping of these member functions to C++ is as follows:
class CORBA
{
class TypeCode
{
public:
class Bounds { ... };
class BadKind { ... };
Boolean equal(TypeCode_ptr) const;
TCKind kind() const;
Long param_count() const;
Any *parameter(Long) const;
RepositoryId id () const;
}; // TypeCode
}; // CORBA
TypeCode has the following special memory management rule: