MCPcopy Create free account
hub / github.com/davisking/dlib / array

Class array

dlib/java/java_array.h:296–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294
295template <typename T>
296class array
297{
298public:
299
300 typedef typename find_java_array_type<T>::type java_type;
301
302 array() {}
303
304 explicit array(size_t size)
305 {
306 ref = create_java_array(T(),size);
307 is_global_ref = false;
308 }
309
310 array(java_type ref_)
311 {
312 if (ref_)
313 {
314 ref = (java_type)JNI_GetEnv()->NewGlobalRef(ref_);
315 is_global_ref = true;
316 }
317 }
318
319#ifndef SWIG
320 array(array&& item)
321 {
322 ref = item.ref;
323 is_global_ref = item.is_global_ref;
324 item.ref = NULL;
325 item.is_global_ref = false;
326 }
327 array& operator= (array&& item)
328 {
329 array(std::move(item)).swap(*this);
330 return *this;
331 }
332#endif
333
334 ~array()
335 {
336 if (ref)
337 {
338 // Don't delete the reference if it's a local reference, since the only reason
339 // we will normally be using array object's that contain local references
340 // is because we plan on returning the newly constructed array back to the JVM,
341 // which automatically frees local references using the normal JVM garbage
342 // collection scheme.
343 if (is_global_ref)
344 JNI_GetEnv()->DeleteGlobalRef(ref);
345
346 ref = NULL;
347 is_global_ref = false;
348 }
349 }
350
351 size_t size() const
352 {
353 if (ref)

Calls 2

moveFunction · 0.85
swapMethod · 0.45