- Main Page
- Related Pages
- Modules
- Classes
- Files

# ArrayHelper.h

Go to the documentation of this file.

    00001 #ifndef _ARRAYHELPER_H_
    00002 #define _ARRAYHELPER_H_
    00003 //
    00004
    00005 //
    00006 // Copyright (C) 2004-2006  Autodesk, Inc.
    00007 //
    00008 // This library is free software; you can redistribute it and/or
    00009 // modify it under the terms of version 2.1 of the GNU Lesser
    00010 // General Public License as published by the Free Software Foundation.
    00011 //
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015 // Lesser General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU Lesser General Public
    00018 // License along with this library; if not, write to the Free Software
    00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    00020 //
    00021
    00022 #ifdef _WIN32
    00023 #pragma once
    00024 #endif
    00025
    00026 /// \brief
    00027 /// Class to do allocations for the FdoArray template.
    00028 /// Allocations and freeing must be done in this class in order to
    00029 /// protect against various callers that have overridden
    00030 /// the "new" and "delete" operators.
    00031 class FdoArrayHelper
    00032 {
    00033 public:
    00034     /// Metadata for an array. This precedes the actually array data in any allocation.
    00035     struct Metadata
    00036     {
    00037     /// Reference count.
    00038         FdoInt32 refCount;
    00039     /// Number of bytes used in array data.
    00040         FdoInt32 size;
    00041     /// Number of bytes allocated for array data.
    00042         FdoInt32 alloc;
    00043         void SetSizes(FdoInt32 rc, FdoInt32 s, FdoInt32 a) { refCount=rc; size=s; alloc=a; }
    00044     };
    00045
    00046     /// Declare generic array and element types.
    00047     /// An array is a single heap allocation whose first bytes are a GenericArray.
    00048     struct GenericArray
    00049     {
    00050         Metadata m_metadata;
    00051         FdoByte* GetData() { return (m_metadata.alloc<=0) ? 0 : (((FdoByte*)this) + sizeof(Metadata)); }
    00052     };
    00053
    00054     FDO_API_COMMON static GenericArray* Append(GenericArray* array, FdoInt32 numElements, FdoByte* elements, FdoInt32 elementSize);
    00055
    00056     FDO_API_COMMON static GenericArray* SetSize(GenericArray* array, FdoInt32 numElements, FdoInt32 elementSize);
    00057
    00058     FDO_API_COMMON static GenericArray* SetAlloc(GenericArray* array, FdoInt32 numElements, FdoInt32 elementSize);
    00059
    00060     FDO_API_COMMON static GenericArray* AllocMore(GenericArray* array, FdoInt32 atLeastThisMuch, bool exactly, FdoInt32 elementSize);
    00061
    00062     FDO_API_COMMON static void DisposeOfArray(GenericArray* array, FdoInt32 elementSize);
    00063
    00064 protected:
    00065
    00066     /// Constructor (makes sure that this class cannot be instantiated -- it consists of all static methods.)
    00067     FDO_API_COMMON FdoArrayHelper() {};
    00068 };
    00069 #endif
    00070
    00071

Please send us your comment about this page