Bonmin  1.7
BonArraysHelpers.hpp
Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation 2007
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, International Business Machines Corporation
00007 //
00008 // Date : 10/06/2007
00009 
00010 #include "CoinHelperFunctions.hpp"
00011 #ifndef BonArraysHelpers_H
00012 #define BonArraysHelpers_H
00013 
00014 namespace Bonmin {
00015 template <class X> void
00016 resizeAndCopyArray(X *& array, unsigned int oldSize, unsigned int newSize){
00017  if(newSize == 0){
00018    if(oldSize > 0){
00019      delete [] array;
00020      array = NULL;
00021    }
00022    return;
00023  }
00024  X * buffy = new X[newSize];
00025  if(oldSize > 0){
00026    if(oldSize < newSize)
00027      CoinCopyN(array, oldSize, buffy);
00028    else
00029      CoinCopyN(array, newSize, buffy);
00030    delete [] array;
00031  }
00032  array = buffy;
00033 }
00034 
00035 template <class X> void
00036 resizeAndCopyArray(X *& array, unsigned int oldSize, unsigned int newSize,
00037                    unsigned int& capacity){
00038  if(newSize > capacity){
00039    X * buffy = new X[newSize];
00040    if(oldSize > 0){
00041      CoinCopyN(array, oldSize, buffy);
00042      delete [] array;
00043     }
00044    array = buffy;
00045   }
00046   else {
00047     newSize = oldSize;
00048   }
00049 }
00050 }// Ends Bonmin namespace
00051 #endif
00052