Overview | Destroys the iterator and frees allocated memory. |
Original interface | CosNaming::BindingIterator Interface |
Exceptions | CORBA standard exceptions |
Intended Usage
This operation is intended to used by client applications. It is not typically overridden.
Syntax
void destroy();
Examples
The following examples demonstrate the usage of the CosNaming Module.
C++ Example
// A CosNaming usage example. // For simplicity, error and exception checking and cleanup are ommitted. #include <CosNaming.hh> #include <stdlib.h> #include <fstream.h> #define filename1 "NMUTST1.OUT" #define filename2 "NMUTST1.OUT" // Make the name "vehicles" CosNaming::Name *vehiclesBindingName = new CosNaming::Name; vehiclesBindingName->length( 1 ); (*vehiclesBindingName)[0].id = CORBA::string_dup("vehicles"); (*vehiclesBindingName)[0].kind = CORBA::string_dup(""); // Create a new naming context vehiclesNamingContext and bind it to the // root rootNamingContext with the name "vehicles" CosNaming::NamingContext_ptr vehiclesNamingContext = rootNamingContext->bind_new_context(*vehiclesBindingName); // Make the name "vehicles.large" CosNaming::Name *largevehiclesBindingName = new CosNaming::Name; largevehiclesBindingName->length( 1 ); (*largevehiclesBindingName)[0].id = CORBA::string_dup("vehicles"); (*largevehiclesBindingName)[0].kind = CORBA::string_dup("large"); // create a new naming context largevehiclesNamingContext and bind // it to the naming context vehiclesNamingContext with the name // "vehicles.large" CosNaming::NamingContext_ptr largevehiclesNamingContext = vehiclesNamingContext->bind_new_context( *largevehiclesBindingName); // Make the name "vans" CosNaming::Name *vansBindingName = new CosNaming::Name; vansBindingName->length( 1 ); (*vansBindingName)[0].id = CORBA::string_dup("vans"); (*vansBindingName)[0].kind = CORBA::string_dup(""); // create a new naming context vansNamingContext and bind it to the // naming context vehiclesNamingContext with the name "vans" CosNaming::NamingContext_ptr vansNamingContext = vehiclesNamingContext->bind_new_context(*vansBindingName); // Make the name "trucks" CosNaming::Name *trucksBindingName = new CosNaming::Name; trucksBindingName->length( 1 ); (*trucksBindingName)[0].id = CORBA::string_dup("trucks"); (*trucksBindingName)[0].kind = CORBA::string_dup(""); // create a new naming context trucksNamingContext and bind it to the // naming context vehiclesNamingContext with the name "trucks" CosNaming::NamingContext_ptr trucksNamingContext = vehiclesNamingContext->bind_new_context(*trucksBindingName); // Make the name "chrysler" CosNaming::Name *avehicleBindingName = new CosNaming::Name; avehicleBindingName->length( 1 ); (*avehicleBindingName)[0].id = CORBA::string_dup("chrysler"); (*avehicleBindingName)[0].kind = CORBA::string_dup(""); // Create an object avehicleObject ifstream strm1(filename1); char refStr[2048]; memset(refStr, 2048, '\0'); strm1 >> refStr; CORBA::Object_ptr avehicleObject = orb_p->string_to_object(refStr); // Bind the object avehicleObject to the naming context // vansNamingContext with the name "chrysler" vansNamingContext->bind(*avehicleBindingName, avehicleObject); // Create another object anothervehicleObject ifstream strm2(filename2); memset(refStr, 2048, '\0'); strm2 >> refStr; CORBA::Object_ptr anothervehicleObject = orb_p->string_to_object(refStr); // Rebind the object anothervehicleObject to the naming // context vansNamingContext with the name "chrysler" vansNamingContext->rebind(*avehicleBindingName, anothervehicleObject); // Bind the context vansNamingContext to the context // vehiclesNamingContext with the name "vans" largevehiclesNamingContext->bind_context(*vansBindingName, vansNamingContext); // Make the name "vans.mini" CosNaming::Name *miniVansBindingName = new CosNaming::Name; miniVansBindingName->length( 1 ); (*miniVansBindingName)[0].id = CORBA::string_dup("vans"); (*miniVansBindingName)[0].kind = CORBA::string_dup("mini"); // Rebind the context vansNamingContext to the context // vehiclesNamingContext with the name "vans.mini" largevehiclesNamingContext->rebind_context(*miniVansBindingName, vansNamingContext); // Unbind the object bound to vehiclesNamingContext with the // name "vans" largevehiclesNamingContext->unbind(*vansBindingName); // Unbind the object bound to vehiclesNamingContext with the // name "vans.mini" largevehiclesNamingContext->unbind(*miniVansBindingName); // Make the name "vehicles/vans/crysler.mini" CosNaming::Name *aMiniVansPathName = new CosNaming::Name; aMiniVansPathName->length( 3 ); (*aMiniVansPathName)[0].id = CORBA::string_dup("vehicles"); (*aMiniVansPathName)[0].kind = CORBA::string_dup(""); (*aMiniVansPathName)[1].id = CORBA::string_dup("vans"); (*aMiniVansPathName)[1].kind = CORBA::string_dup(""); (*aMiniVansPathName)[2].id = CORBA::string_dup("chrysler"); (*aMiniVansPathName)[2].kind = CORBA::string_dup(""); // Resolve the name from the root naming context rootNamingContext avehicleObject = rootNamingContext->resolve(*aMiniVansPathName); // list only one binding in the naming root context rootNamingContext // The remaining bindings can be retrieved from the binding iterator bi. CosNaming::BindingList_var bl; CosNaming::BindingIterator_var bi; vehiclesNamingContext->list(1, bl, bi); // Retrieve the next binding from the binding iterator CosNaming::Binding_var b; bi->next_one(b); // Retrieve the next 2 bindings from the binding iterator CosNaming::BindingList_var bl1; bi->next_n(2, bl1); // Destroy the naming context vehiclesNamingContext largevehiclesNamingContext->destroy(); // Destroy the binding iterator bi bi->destroy();