Bonmin 1.8.9
Loading...
Searching...
No Matches
BonArraysHelpers.hpp
Go to the documentation of this file.
1// (C) Copyright International Business Machines Corporation 2007
2// All Rights Reserved.
3// This code is published under the Eclipse Public License.
4//
5// Authors :
6// Pierre Bonami, International Business Machines Corporation
7//
8// Date : 10/06/2007
9
11#ifndef BonArraysHelpers_H
12#define BonArraysHelpers_H
13
14namespace Bonmin {
15template <class X> void
16resizeAndCopyArray(X *& array, unsigned int oldSize, unsigned int newSize){
17 if(newSize == 0){
18 if(oldSize > 0){
19 delete [] array;
20 array = NULL;
21 }
22 return;
23 }
24 X * buffy = new X[newSize];
25 if(oldSize > 0){
26 if(oldSize < newSize)
27 CoinCopyN(array, oldSize, buffy);
28 else
29 CoinCopyN(array, newSize, buffy);
30 delete [] array;
31 }
32 array = buffy;
33}
34
35template <class X> void
36resizeAndCopyArray(X *& array, unsigned int oldSize, unsigned int newSize,
37 unsigned int& capacity){
38 if(newSize > capacity){
39 X * buffy = new X[newSize];
40 if(oldSize > 0){
41 CoinCopyN(array, oldSize, buffy);
42 delete [] array;
43 }
44 array = buffy;
45 }
46 else {
47 newSize = oldSize;
48 }
49}
50}// Ends Bonmin namespace
51#endif
52
void CoinCopyN(const T *from, const CoinBigIndex size, T *to)
(C) Copyright International Business Machines Corporation 2007
void resizeAndCopyArray(X *&array, unsigned int oldSize, unsigned int newSize)