4 // Default constructor.
16 Grid_i::Grid_i (CORBA::Short x
,
24 // First try to locate the matrix in the pool. If it is there then
25 // it has already been created. In such a case we just get that
26 // memory and assign it to array_
30 if (mem_pool
->find ("Array", tmp_array
) != -1)
32 array_
= reinterpret_cast <CORBA::Long
**> (tmp_array
);
36 // Allocate memory for the matrix.
37 ACE_ALLOCATOR (array_
,
38 static_cast<CORBA::Long
**> (mem_pool
->malloc (y
* sizeof (CORBA::Long
*))));
39 //array_ = (CORBA::Long **) mem_pool->malloc (y * sizeof (CORBA::Long *));
43 for (int ctr
= 0; ctr
< y
; ctr
++)
45 ACE_ALLOCATOR (array_
[ctr
],
46 static_cast<CORBA::Long
*> (mem_pool
->malloc (x
*
47 sizeof (CORBA::Long
))));
49 //array_[ctr] = (CORBA::Long *)mem_pool->malloc (x *
50 // sizeof (CORBA::Long));
53 mem_pool
->bind ("Array", array_
);
59 // Default destructor.
65 // Set a value in the grid.
68 Grid_i::set (CORBA::Short x
,
76 throw Grid::RANGE_ERROR ();
81 // Get a value from the grid.
84 Grid_i::get (CORBA::Short x
,
91 throw Grid::RANGE_ERROR ();
107 return this->height_
;
111 Grid_i::width (CORBA::Short x
)
117 Grid_i::height (CORBA::Short y
)
127 for (int i
= 0; i
< height_
; i
++)
128 this->pool_t_
->free (array_
[i
]);
131 this->pool_t_
->free (array_
);
133 ACE_DEBUG ((LM_DEBUG
,
135 "Grid has been destroyed"));
139 Grid_i::set_pool (pool_t
*pool
)
141 this->pool_t_
= pool
;
145 Grid_Factory_i::Grid_Factory_i ()
154 Grid_Factory_i::~Grid_Factory_i ()
156 delete this->pool_t_
;
162 Grid_Factory_i::make_grid (CORBA::Short width
,
165 ACE_DEBUG ((LM_DEBUG
,
166 " (%P|%t) Making a new Grid\n"));
168 // Set a default value for width.
170 width
= Grid_Factory::DEFAULT_WIDTH
;
172 // Set a default value for height.
174 height
= Grid_Factory::DEFAULT_HEIGHT
;
177 ACE_NEW_THROW_EX (pool_t_
,
179 CORBA::NO_MEMORY ());
181 // pool_t_ = new pool_t (pool_name_);
183 // This attempts to create a new Grid_i and throws an exception and
184 // returns a null value if it fails
186 Grid_i
*grid_ptr
= new Grid_i (width
,
190 throw CORBA::NO_MEMORY ();
194 grid_ptr
->set_pool (pool_t_
);
196 // Register the Grid pointer.
197 return grid_ptr
->_this ();
200 // Set the ORB pointer.
203 Grid_Factory_i::orb (CORBA::ORB_ptr o
)
205 this->orb_
= CORBA::ORB::_duplicate (o
);
210 Grid_Factory_i::shutdown ()
212 ACE_DEBUG ((LM_DEBUG
,
214 "Grid Factory is shutting down"));
216 // Instruct the ORB to shutdown.
217 this->orb_
->shutdown ();
221 Grid_Factory_i::cleanup ()
223 const char *name
= "Array";
225 if (this->pool_t_
->unbind (name
) == -1)
226 ACE_DEBUG ((LM_DEBUG
,
227 "\n Failed to unbind "));
231 Grid_Factory_i::pool_name (const ACE_TCHAR
*name
)
233 this->pool_name_
= ACE_OS::strdup (name
);