LCOV - code coverage report
Current view: top level - util - CubitFileMetaData.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 0 530 0.0 %
Date: 2020-06-30 00:58:45 Functions: 0 30 0.0 %
Branches: 0 420 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*******************************************************************************
       2                 :            :     COPYRIGHT 2002 CATERPILLAR INC.  ALL RIGHTS RESERVED
       3                 :            : 
       4                 :            :     This program is the property of Caterpillar Inc., includes Caterpillar's
       5                 :            :     confidential and trade secret information, and is maintained as an
       6                 :            :     unpublished copyrighted work.  It is not to be copied or used by others
       7                 :            :     except under license from Caterpillar.  This program is also protected as an
       8                 :            :     unpublished work in accordance with the copyright act of 1976.  In the event
       9                 :            :     of either inadvertent or deliberate publication, Caterpillar Inc. intends to
      10                 :            :     maintain copyright protection for this work under the relevant copyright
      11                 :            :     laws pertaining to published works.  The inclusion of a copyright notice
      12                 :            :     hereon is precautionary only, and does not imply publication or disclosure.
      13                 :            : 
      14                 :            :  
      15                 :            :  Filename      : CubitFileMetaData.cpp
      16                 :            : 
      17                 :            :  Purpose       : Implements meta-data (descriptions) in the Cubit file.
      18                 :            :            
      19                 :            :  Special Notes :
      20                 :            : 
      21                 :            :  Creator       : Will A. Helden
      22                 :            : 
      23                 :            :  Creation Date : 02/15/02
      24                 :            : 
      25                 :            :  Owner         : Will A. Helden
      26                 :            : 
      27                 :            : *******************************************************************************/
      28                 :            : 
      29                 :            : #include "CubitFileMetaData.hpp"
      30                 :            : #include "CubitFileIOWrapper.hpp"
      31                 :            : #include <cstring>
      32                 :            : 
      33                 :            : using namespace NCubitFile;
      34                 :            : 
      35                 :            : ///////////////////////////////////////////////////////////////////////////////
      36                 :            : // CMetaData -
      37                 :            : ///////////////////////////////////////////////////////////////////////////////
      38                 :            : 
      39                 :          0 : CMetaData::CMetaData(UnsignedInt32 xintGrowSizeBy)
      40                 :            : {
      41                 :          0 :     mHeader.mintMetaDataSchema = 0;
      42                 :          0 :     mHeader.mintMetaDataCompress = 0;
      43                 :          0 :     mHeader.mintMetaDataCount = 0;
      44                 :            : 
      45         [ #  # ]:          0 :     mintGrowSizeBy = xintGrowSizeBy ? xintGrowSizeBy : 64;
      46                 :          0 :     mintBufferSize = 0;
      47                 :          0 :     mpaEntries = NULL;
      48                 :            : 
      49                 :            :     // Initialize the return buffer - allocated structures needed to return
      50                 :            :     // the results of meta data queries will be owned and freed by this object.
      51                 :            :     mSearchBuff.mintNumOwners = mSearchBuff.mintNumNames =
      52                 :          0 :         mSearchBuff.mintNumMetaData = 0;
      53                 :          0 :     mSearchBuff.mpaintOwners = NULL;
      54                 :          0 :     mSearchBuff.mpapachrNames = NULL;
      55                 :          0 :     mSearchBuff.mintMetaDataType = eUnsignedInt32;
      56                 :          0 :     mSearchBuff.mpaValues = NULL;
      57                 :          0 :     mSearchBuff.mpaintNumValues = NULL;
      58                 :          0 : }
      59                 :            : 
      60                 :          0 : CMetaData::~CMetaData()
      61                 :            : {
      62                 :            :     // Free the meta data.
      63                 :          0 :     FreeAll();
      64                 :            : 
      65                 :            :     // Free the search return buffer.
      66         [ #  # ]:          0 :     if(mSearchBuff.mpaintOwners)
      67         [ #  # ]:          0 :         delete [] mSearchBuff.mpaintOwners;
      68         [ #  # ]:          0 :     if(mSearchBuff.mpapachrNames)
      69         [ #  # ]:          0 :         delete [] mSearchBuff.mpapachrNames;
      70         [ #  # ]:          0 :     if(mSearchBuff.mpaValues) {
      71   [ #  #  #  #  :          0 :         switch(mSearchBuff.mintMetaDataType) {
                   #  # ]
      72                 :            :         case eUnsignedInt32:
      73         [ #  # ]:          0 :             delete [] (UnsignedInt32*)mSearchBuff.mpaValues;
      74                 :          0 :             break;
      75                 :            :         case eString:
      76         [ #  # ]:          0 :             delete [] (ConstCharPtr*)mSearchBuff.mpaValues;
      77                 :          0 :             break;
      78                 :            :         case eDouble:
      79         [ #  # ]:          0 :             delete [] (double*)mSearchBuff.mpaValues;
      80                 :          0 :             break;
      81                 :            :         case eUnsignedInt32Array:
      82         [ #  # ]:          0 :             delete [] (ConstUnsignedInt32Ptr*)mSearchBuff.mpaValues;
      83                 :          0 :             break;
      84                 :            :         case eDoubleArray:
      85         [ #  # ]:          0 :             delete [] (ConstDoublePtr*)mSearchBuff.mpaValues;
      86                 :          0 :             break;
      87                 :            :         }
      88                 :            :     }
      89         [ #  # ]:          0 :     if(mSearchBuff.mpaintNumValues)
      90         [ #  # ]:          0 :         delete [] mSearchBuff.mpaintNumValues;
      91         [ #  # ]:          0 : }
      92                 :            : 
      93                 :          0 : void CMetaData::GrowSize()
      94                 :            : // Grows the meta-data storage structure by the predetermined growth size.
      95                 :            : {
      96                 :            :     // Try to allocate a new storage structure.
      97                 :          0 :     UnsignedInt32 lintNewBufferSize = mintBufferSize + mintGrowSizeBy;
      98                 :            :     SCubitFileMetaDataEntry* lpaNewEntries =
      99         [ #  # ]:          0 :         new SCubitFileMetaDataEntry[lintNewBufferSize];
     100         [ #  # ]:          0 :     if(!lpaNewEntries)
     101                 :          0 :         throw CCubitFile::eMemoryError;
     102                 :            : 
     103                 :            :     // Copy the existing data into the front new structure.
     104         [ #  # ]:          0 :     if(mpaEntries) {
     105                 :            :         memcpy(lpaNewEntries, mpaEntries,
     106                 :          0 :             mintBufferSize * sizeof(SCubitFileMetaDataEntry));
     107                 :            :     }
     108                 :            :     // Initialize the remaining part of the new structure.
     109         [ #  # ]:          0 :     for(UnsignedInt32 lintEntry = mintBufferSize; lintEntry <
     110                 :            :         lintNewBufferSize; lintEntry++) {
     111                 :          0 :         lpaNewEntries[lintEntry].mintMetaDataOwner = 0;
     112                 :          0 :         lpaNewEntries[lintEntry].mintMetaDataType = eUnsignedInt32;
     113                 :          0 :         lpaNewEntries[lintEntry].mpachrName = NULL;
     114                 :          0 :         lpaNewEntries[lintEntry].muValue.mint = 0;
     115                 :          0 :         lpaNewEntries[lintEntry].mintNumValues = 0;
     116                 :            :     }
     117                 :            :     // Replace the old structure with the new one and free the old one.
     118         [ #  # ]:          0 :     if(mpaEntries)
     119         [ #  # ]:          0 :         delete [] mpaEntries;
     120                 :          0 :     mintBufferSize = lintNewBufferSize;
     121                 :          0 :     mpaEntries = lpaNewEntries;
     122                 :          0 : }
     123                 :            : 
     124                 :          0 : UnsignedInt32 CMetaData::AddEntry(UnsignedInt32 xintOwner,
     125                 :            :                                   ConstCharPtr xpachrName)
     126                 :            : // Creates a valueless meta-data entry for the passed id and name.
     127                 :            : // Private function, returns the index of the new entry, throws exceptions.
     128                 :            : {
     129         [ #  # ]:          0 :     if(mHeader.mintMetaDataCount == mintBufferSize)
     130                 :          0 :         GrowSize();
     131                 :          0 :     mpaEntries[mHeader.mintMetaDataCount].mintMetaDataOwner = xintOwner;
     132                 :          0 :     UnsignedInt32 lintNameLength = std::strlen(xpachrName);
     133                 :          0 :     mpaEntries[mHeader.mintMetaDataCount].mpachrName =
     134                 :          0 :         new char[lintNameLength + 1];
     135         [ #  # ]:          0 :     if(!mpaEntries[mHeader.mintMetaDataCount].mpachrName)
     136                 :          0 :         throw CCubitFile::eMemoryError;
     137                 :          0 :     std::strcpy(mpaEntries[mHeader.mintMetaDataCount].mpachrName, xpachrName);
     138                 :          0 :     return mHeader.mintMetaDataCount++;
     139                 :            : }
     140                 :            : 
     141                 :          0 : UnsignedInt32 CMetaData::Find(UnsignedInt32 xintOwner,
     142                 :            :                               ConstCharPtr xpachrName,
     143                 :            :                               UnsignedInt32& xintIndex)
     144                 :            : // Search for the index of a piece of data with the declared owner and name.
     145                 :            : // Private function, returns true/false, no exceptions thrown.
     146                 :            : {
     147         [ #  # ]:          0 :     if(!mHeader.mintMetaDataCount)  return 0;  // false, not found
     148         [ #  # ]:          0 :     for(UnsignedInt32 lintEntry = 0; lintEntry <
     149                 :            :         mHeader.mintMetaDataCount; lintEntry++) {
     150         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataOwner == xintOwner) {
     151         [ #  # ]:          0 :             if(!std::strcmp(xpachrName, mpaEntries[lintEntry].mpachrName)) {
     152                 :          0 :                 xintIndex = lintEntry;
     153                 :          0 :                 return 1;  // true, found
     154                 :            :             }
     155                 :            :         }
     156                 :            :     }
     157                 :          0 :     return 0;  // false, not found
     158                 :            : }
     159                 :            : 
     160                 :            : 
     161                 :            : ///////////////////////////////////////////////////////////////////////////////
     162                 :            : // Get/Set Value Methods
     163                 :            : ///////////////////////////////////////////////////////////////////////////////
     164                 :            : 
     165                 :          0 : UnsignedInt32 CMetaData::GetValue(UnsignedInt32 xintOwner,
     166                 :            :                                   ConstCharPtr xpachrName,
     167                 :            :                                   UnsignedInt32& xintValue)
     168                 :            : // Retrieve integer valued meta-data by id and name.
     169                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     170                 :            : {
     171                 :            :     UnsignedInt32 lintEntry;
     172 [ #  # ][ #  # ]:          0 :     if(Find(xintOwner, xpachrName, lintEntry)) {
     173         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataType == eUnsignedInt32) {
     174                 :          0 :             xintValue = mpaEntries[lintEntry].muValue.mint;
     175                 :          0 :             return CCubitFile::eSuccess;
     176                 :            :         }
     177                 :            :     }
     178                 :          0 :     xintValue = 0;
     179                 :          0 :     return CCubitFile::eNotFound;
     180                 :            : }
     181                 :            : 
     182                 :          0 : UnsignedInt32 CMetaData::GetValue(UnsignedInt32 xintOwner,
     183                 :            :                                   ConstCharPtr xpachrName,
     184                 :            :                                   ConstCharPtr& xpachrValue)
     185                 :            : // Retrieve string valued meta-data by id and name.
     186                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     187                 :            : {
     188                 :            :     UnsignedInt32 lintEntry;
     189 [ #  # ][ #  # ]:          0 :     if(Find(xintOwner, xpachrName, lintEntry)) {
     190         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataType == eString) {
     191                 :          0 :             xpachrValue = mpaEntries[lintEntry].muValue.mpachr;
     192                 :          0 :             return CCubitFile::eSuccess;
     193                 :            :         }
     194                 :            :     }
     195                 :          0 :     xpachrValue = NULL;
     196                 :          0 :     return CCubitFile::eNotFound;
     197                 :            : }
     198                 :            : 
     199                 :          0 : UnsignedInt32 CMetaData::GetValue(UnsignedInt32 xintOwner,
     200                 :            :                                   ConstCharPtr xpachrName,
     201                 :            :                                   double& xdblValue)
     202                 :            : // Retrieve double valued meta-data by id and name.
     203                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     204                 :            : {
     205                 :            :     UnsignedInt32 lintEntry;
     206 [ #  # ][ #  # ]:          0 :     if(Find(xintOwner, xpachrName, lintEntry)) {
     207         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataType == eDouble) {
     208                 :          0 :             xdblValue = mpaEntries[lintEntry].muValue.mdbl;
     209                 :          0 :             return CCubitFile::eSuccess;
     210                 :            :         }
     211                 :            :     }
     212                 :          0 :     xdblValue = 0.0;
     213                 :          0 :     return CCubitFile::eNotFound;
     214                 :            : }
     215                 :            : 
     216                 :          0 : UnsignedInt32 CMetaData::GetValue(UnsignedInt32 xintOwner,
     217                 :            :                                   ConstCharPtr xpachrName,
     218                 :            :                                   const UnsignedInt32*& xpaintValue,
     219                 :            :                                   UnsignedInt32& xintNumValues)
     220                 :            : // Retrieve integer array valued meta-data by id and name.
     221                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     222                 :            : {
     223                 :            :     UnsignedInt32 lintEntry;
     224 [ #  # ][ #  # ]:          0 :     if(Find(xintOwner, xpachrName, lintEntry)) {
     225         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataType == eUnsignedInt32Array) {
     226                 :          0 :             xpaintValue = mpaEntries[lintEntry].muValue.mpaint;
     227                 :          0 :             xintNumValues = mpaEntries[lintEntry].mintNumValues;
     228                 :          0 :             return CCubitFile::eSuccess;
     229                 :            :         }
     230                 :            :     }
     231                 :          0 :     xpaintValue = NULL;
     232                 :          0 :     xintNumValues = 0;
     233                 :          0 :     return CCubitFile::eNotFound;
     234                 :            : }
     235                 :            : 
     236                 :          0 : UnsignedInt32 CMetaData::GetValue(UnsignedInt32 xintOwner,
     237                 :            :                                   ConstCharPtr xpachrName,
     238                 :            :                                   const double*& xpadblValue,
     239                 :            :                                   UnsignedInt32& xintNumValues)
     240                 :            : // Retrieve double array valued meta-data by id and name.
     241                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     242                 :            : {
     243                 :            :     UnsignedInt32 lintEntry;
     244 [ #  # ][ #  # ]:          0 :     if(Find(xintOwner, xpachrName, lintEntry)) {
     245         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataType == eDoubleArray) {
     246                 :          0 :             xpadblValue = mpaEntries[lintEntry].muValue.mpadbl;
     247                 :          0 :             xintNumValues = mpaEntries[lintEntry].mintNumValues;
     248                 :          0 :             return CCubitFile::eSuccess;
     249                 :            :         }
     250                 :            :     }
     251                 :          0 :     xpadblValue = NULL;
     252                 :          0 :     xintNumValues = 0;
     253                 :          0 :     return CCubitFile::eNotFound;
     254                 :            : }
     255                 :            : 
     256                 :            : //-----------------------------------------------------------------------------
     257                 :            : 
     258                 :          0 : UnsignedInt32 CMetaData::SetValue(UnsignedInt32 xintOwner,
     259                 :            :                                   ConstCharPtr xpachrName,
     260                 :            :                                   UnsignedInt32 xintValue)
     261                 :            : // Assign integer valued meta-data to an id and name.
     262                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     263                 :            : {
     264         [ #  # ]:          0 :     if(!xpachrName)
     265                 :          0 :         return CCubitFile::ePassedNullPointer;
     266                 :            : 
     267                 :            :     try {
     268                 :            :         UnsignedInt32 lintEntry;
     269 [ #  # ][ #  # ]:          0 :         if(Find(xintOwner, xpachrName, lintEntry))
     270         [ #  # ]:          0 :             FreeValueAt(lintEntry);
     271                 :            :         else
     272         [ #  # ]:          0 :             lintEntry = AddEntry(xintOwner, xpachrName);
     273                 :          0 :         mpaEntries[lintEntry].mintMetaDataType = eUnsignedInt32;
     274                 :          0 :         mpaEntries[lintEntry].muValue.mint = xintValue;
     275         [ #  # ]:          0 :         return CCubitFile::eSuccess;
     276                 :            :     }
     277                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     278                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     279                 :            : }
     280                 :            : 
     281                 :          0 : UnsignedInt32 CMetaData::SetValue(UnsignedInt32 xintOwner,
     282                 :            :                                   ConstCharPtr xpachrName,
     283                 :            :                                   ConstCharPtr xpachrValue)
     284                 :            : // Assign string valued meta-data to an id and name.
     285                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     286                 :            : {
     287         [ #  # ]:          0 :     if(!xpachrName)
     288                 :          0 :         throw CCubitFile::ePassedNullPointer;
     289                 :            : 
     290                 :            :     try {
     291                 :            :         UnsignedInt32 lintEntry, lintLength;
     292 [ #  # ][ #  # ]:          0 :         if(Find(xintOwner, xpachrName, lintEntry))
     293         [ #  # ]:          0 :             FreeValueAt(lintEntry);
     294                 :            :         else
     295         [ #  # ]:          0 :             lintEntry = AddEntry(xintOwner, xpachrName);
     296                 :            : 
     297                 :          0 :         mpaEntries[lintEntry].mintMetaDataType = eString;
     298         [ #  # ]:          0 :         lintLength = xpachrValue ? std::strlen(xpachrValue) : 0;
     299         [ #  # ]:          0 :         if(lintLength) {
     300         [ #  # ]:          0 :             mpaEntries[lintEntry].muValue.mpachr = new char[lintLength + 1];
     301         [ #  # ]:          0 :             if(!mpaEntries[lintEntry].muValue.mpachr)
     302                 :          0 :                 throw CCubitFile::eMemoryError;
     303                 :          0 :             std::strcpy(mpaEntries[lintEntry].muValue.mpachr, xpachrValue);
     304                 :            :         }
     305                 :            :         else
     306                 :          0 :             mpaEntries[lintEntry].muValue.mpachr = NULL;
     307                 :            : 
     308         [ #  # ]:          0 :         return CCubitFile::eSuccess;
     309                 :            :     }
     310                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     311                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     312                 :            : }
     313                 :            : 
     314                 :          0 : UnsignedInt32 CMetaData::SetValue(UnsignedInt32 xintOwner,
     315                 :            :                                   ConstCharPtr xpachrName, double xdblValue)
     316                 :            : // Assign double valued meta-data to an id and name.
     317                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     318                 :            : {
     319         [ #  # ]:          0 :     if(!xpachrName)
     320                 :          0 :         throw CCubitFile::ePassedNullPointer;
     321                 :            : 
     322                 :            :     try {
     323                 :            :         UnsignedInt32 lintEntry;
     324 [ #  # ][ #  # ]:          0 :         if(Find(xintOwner, xpachrName, lintEntry))
     325         [ #  # ]:          0 :             FreeValueAt(lintEntry);
     326                 :            :         else
     327         [ #  # ]:          0 :             lintEntry = AddEntry(xintOwner, xpachrName);
     328                 :          0 :         mpaEntries[lintEntry].mintMetaDataType = eDouble;
     329                 :          0 :         mpaEntries[lintEntry].muValue.mdbl = xdblValue;
     330         [ #  # ]:          0 :         return CCubitFile::eSuccess;
     331                 :            :     }
     332                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     333                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     334                 :            : }
     335                 :            : 
     336                 :          0 : UnsignedInt32 CMetaData::SetValue(UnsignedInt32 xintOwner,
     337                 :            :                                   ConstCharPtr xpachrName,
     338                 :            :                                   const UnsignedInt32* xpaintValue,
     339                 :            :                                   UnsignedInt32 xintNumValues)
     340                 :            : // Assign integer array valued meta-data to an id and name.
     341                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     342                 :            : {
     343         [ #  # ]:          0 :     if(!xpachrName)
     344                 :          0 :         throw CCubitFile::ePassedNullPointer;
     345                 :            : 
     346                 :            :     try {
     347                 :            :         UnsignedInt32 lintEntry;
     348 [ #  # ][ #  # ]:          0 :         if(Find(xintOwner, xpachrName, lintEntry))
     349         [ #  # ]:          0 :             FreeValueAt(lintEntry);
     350                 :            :         else
     351         [ #  # ]:          0 :             lintEntry = AddEntry(xintOwner, xpachrName);
     352                 :            : 
     353                 :          0 :         mpaEntries[lintEntry].mintMetaDataType = eUnsignedInt32Array;
     354 [ #  # ][ #  # ]:          0 :         if(xpaintValue && xintNumValues) {
     355                 :          0 :             mpaEntries[lintEntry].muValue.mpaint =
     356 [ #  # ][ #  # ]:          0 :                 new UnsignedInt32[xintNumValues];
     357         [ #  # ]:          0 :             if(!mpaEntries[lintEntry].muValue.mpaint)
     358                 :          0 :                 throw CCubitFile::eMemoryError;
     359                 :          0 :             memcpy(mpaEntries[lintEntry].muValue.mpaint, xpaintValue,
     360                 :          0 :                 xintNumValues * sizeof(UnsignedInt32));
     361                 :          0 :             mpaEntries[lintEntry].mintNumValues = xintNumValues;
     362                 :            :         }
     363                 :            :         else {
     364                 :          0 :             mpaEntries[lintEntry].muValue.mpaint = NULL;
     365                 :          0 :             mpaEntries[lintEntry].mintNumValues = 0;
     366                 :            :         }
     367                 :            : 
     368         [ #  # ]:          0 :         return CCubitFile::eSuccess;
     369                 :            :     }
     370                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     371                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     372                 :            : }
     373                 :            : 
     374                 :          0 : UnsignedInt32 CMetaData::SetValue(UnsignedInt32 xintOwner,
     375                 :            :                                   ConstCharPtr xpachrName,
     376                 :            :                                   const double* xpadblValue,
     377                 :            :                                   UnsignedInt32 xintNumValues)
     378                 :            : // Assign double array valued meta-data to an id and name.
     379                 :            : // Public function, returns CCubitFile::EErrorCode, no exceptions thrown.
     380                 :            : {
     381         [ #  # ]:          0 :     if(!xpachrName)
     382                 :          0 :         throw CCubitFile::ePassedNullPointer;
     383                 :            : 
     384                 :            :     try {
     385                 :            :         UnsignedInt32 lintEntry;
     386 [ #  # ][ #  # ]:          0 :         if(Find(xintOwner, xpachrName, lintEntry))
     387         [ #  # ]:          0 :             FreeValueAt(lintEntry);
     388                 :            :         else
     389         [ #  # ]:          0 :             lintEntry = AddEntry(xintOwner, xpachrName);
     390                 :            : 
     391                 :          0 :         mpaEntries[lintEntry].mintMetaDataType = eDoubleArray;
     392 [ #  # ][ #  # ]:          0 :         if(xpadblValue && xintNumValues) {
     393                 :          0 :             mpaEntries[lintEntry].muValue.mpadbl =
     394 [ #  # ][ #  # ]:          0 :                 new double[xintNumValues];
     395         [ #  # ]:          0 :             if(!mpaEntries[lintEntry].muValue.mpadbl)
     396                 :          0 :                 throw CCubitFile::eMemoryError;
     397                 :          0 :             memcpy(mpaEntries[lintEntry].muValue.mpadbl, xpadblValue,
     398                 :          0 :                 xintNumValues * sizeof(double));
     399                 :          0 :             mpaEntries[lintEntry].mintNumValues = xintNumValues;
     400                 :            :         }
     401                 :            :         else {
     402                 :          0 :             mpaEntries[lintEntry].muValue.mpadbl = NULL;
     403                 :          0 :             mpaEntries[lintEntry].mintNumValues = 0;
     404                 :            :         }
     405                 :            : 
     406         [ #  # ]:          0 :         return CCubitFile::eSuccess;
     407                 :            :     }
     408                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     409                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     410                 :            : }
     411                 :            : 
     412                 :            : 
     413                 :            : 
     414                 :            : ///////////////////////////////////////////////////////////////////////////////
     415                 :            : // Search Methods
     416                 :            : ///////////////////////////////////////////////////////////////////////////////
     417                 :            : 
     418                 :            : 
     419                 :            : //-----------------------------------------------------------------------------
     420                 :            : 
     421                 :            : //-----------------------------------------------------------------------------
     422                 :            : 
     423                 :          0 : UnsignedInt32 CMetaData::GetMetaDataAll(UnsignedInt32& xintNumFound,
     424                 :            :                                         const ConstCharPtr*& xpapachrName,
     425                 :            :                                         const UnsignedInt32*& xpaintOwner,
     426                 :            :                                         const UnsignedInt32*& xpaintValue)
     427                 :            : // Search the meta-data for all entries of type integer.
     428                 :            : {
     429                 :          0 :     xintNumFound = 0;
     430                 :          0 :     xpapachrName = NULL;
     431                 :          0 :     xpaintOwner = NULL;
     432                 :          0 :     xpaintValue = NULL;
     433         [ #  # ]:          0 :     try {  RebuildSearchBuff(eUnsignedInt32);  }
     434                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     435                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     436                 :            : 
     437         [ #  # ]:          0 :     if((xintNumFound = SearchAll(eUnsignedInt32)) > 0) {
     438                 :          0 :         xpapachrName = mSearchBuff.mpapachrNames;
     439                 :          0 :         xpaintOwner = mSearchBuff.mpaintOwners;
     440                 :          0 :         xpaintValue = (UnsignedInt32*)mSearchBuff.mpaValues;
     441                 :            :     }
     442         [ #  # ]:          0 :     return CCubitFile::eSuccess;
     443                 :            : }
     444                 :            : 
     445                 :          0 : UnsignedInt32 CMetaData::GetMetaDataAll(UnsignedInt32& xintNumFound,
     446                 :            :                                         const ConstCharPtr*& xpapachrName,
     447                 :            :                                         const UnsignedInt32*& xpaintOwner,
     448                 :            :                                         const ConstCharPtr*& xpapachrValue)
     449                 :            : // Search the meta-data for all entries of type string.
     450                 :            : {
     451                 :          0 :     xintNumFound = 0;
     452                 :          0 :     xpapachrName = NULL;
     453                 :          0 :     xpaintOwner = NULL;
     454                 :          0 :     xpapachrValue = NULL;
     455         [ #  # ]:          0 :     try {  RebuildSearchBuff(eString);  }
     456                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     457                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     458                 :            : 
     459         [ #  # ]:          0 :     if((xintNumFound = SearchAll(eString)) > 0) {
     460                 :          0 :         xpapachrName = mSearchBuff.mpapachrNames;
     461                 :          0 :         xpaintOwner = mSearchBuff.mpaintOwners;
     462                 :          0 :         xpapachrValue = (ConstCharPtr*)mSearchBuff.mpaValues;
     463                 :            :     }
     464         [ #  # ]:          0 :     return CCubitFile::eSuccess;
     465                 :            : }
     466                 :            : 
     467                 :          0 : UnsignedInt32 CMetaData::GetMetaDataAll(UnsignedInt32& xintNumFound,
     468                 :            :                                         const ConstCharPtr*& xpapachrName,
     469                 :            :                                         const UnsignedInt32*& xpaintOwner,
     470                 :            :                                         const double*& xpadblValue)
     471                 :            : // Search the meta-data for all entries of type double.
     472                 :            : {
     473                 :          0 :     xintNumFound = 0;
     474                 :          0 :     xpapachrName = NULL;
     475                 :          0 :     xpaintOwner = NULL;
     476                 :          0 :     xpadblValue = NULL;
     477         [ #  # ]:          0 :     try {  RebuildSearchBuff(eDouble);  }
     478                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     479                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     480                 :            : 
     481         [ #  # ]:          0 :     if((xintNumFound = SearchAll(eDouble)) > 0) {
     482                 :          0 :         xpapachrName = mSearchBuff.mpapachrNames;
     483                 :          0 :         xpaintOwner = mSearchBuff.mpaintOwners;
     484                 :          0 :         xpadblValue = (double*)mSearchBuff.mpaValues;
     485                 :            :     }
     486         [ #  # ]:          0 :     return CCubitFile::eSuccess;
     487                 :            : }
     488                 :            : 
     489                 :          0 : UnsignedInt32 CMetaData::GetMetaDataAll(UnsignedInt32& xintNumFound,
     490                 :            :                                         const ConstCharPtr*& xpapachrName,
     491                 :            :                                         const UnsignedInt32*& xpaintOwner,
     492                 :            :                                         const ConstUnsignedInt32Ptr*& xpapaintValue,
     493                 :            :                                         const UnsignedInt32*& xpaintNumValues)
     494                 :            : // Search the meta-data for all entries of type integer array.
     495                 :            : {
     496                 :          0 :     xintNumFound = 0;
     497                 :          0 :     xpapachrName = NULL;
     498                 :          0 :     xpaintOwner = NULL;
     499                 :          0 :     xpapaintValue = NULL;
     500                 :          0 :     xpaintNumValues = NULL;
     501         [ #  # ]:          0 :     try {  RebuildSearchBuff(eUnsignedInt32Array);  }
     502                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     503                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     504                 :            : 
     505         [ #  # ]:          0 :     if((xintNumFound = SearchAll(eUnsignedInt32Array)) > 0) {
     506                 :          0 :         xpapachrName = mSearchBuff.mpapachrNames;
     507                 :          0 :         xpaintOwner = mSearchBuff.mpaintOwners;
     508                 :          0 :         xpapaintValue = (ConstUnsignedInt32Ptr*)mSearchBuff.mpaValues;
     509                 :          0 :         xpaintNumValues = mSearchBuff.mpaintNumValues;
     510                 :            :     }
     511         [ #  # ]:          0 :     return CCubitFile::eSuccess;
     512                 :            : }
     513                 :            : 
     514                 :          0 : UnsignedInt32 CMetaData::GetMetaDataAll(UnsignedInt32& xintNumFound,
     515                 :            :                                         const ConstCharPtr*& xpapachrName,
     516                 :            :                                         const UnsignedInt32*& xpaintOwner,
     517                 :            :                                         const ConstDoublePtr*& xpapadblValue,
     518                 :            :                                         const UnsignedInt32*& xpaintNumValues)
     519                 :            : // Search the meta-data for all entries of type double array.
     520                 :            : {
     521                 :          0 :     xintNumFound = 0;
     522                 :          0 :     xpapachrName = NULL;
     523                 :          0 :     xpaintOwner = NULL;
     524                 :          0 :     xpapadblValue = NULL;
     525                 :          0 :     xpaintNumValues = NULL;
     526         [ #  # ]:          0 :     try {  RebuildSearchBuff(eDoubleArray);  }
     527                 :          0 :     catch(CCubitFile::EErrorCode xeErrorCode)  {  return xeErrorCode;  }
     528                 :          0 :     catch(...)  {  return CCubitFile::eUnknownError;  }
     529                 :            : 
     530         [ #  # ]:          0 :     if((xintNumFound = SearchAll(eDoubleArray)) > 0) {
     531                 :          0 :         xpapachrName = mSearchBuff.mpapachrNames;
     532                 :          0 :         xpaintOwner = mSearchBuff.mpaintOwners;
     533                 :          0 :         xpapadblValue = (ConstDoublePtr*)mSearchBuff.mpaValues;
     534                 :          0 :         xpaintNumValues = mSearchBuff.mpaintNumValues;
     535                 :            :     }
     536         [ #  # ]:          0 :     return CCubitFile::eSuccess;
     537                 :            : }
     538                 :            : 
     539                 :            : 
     540                 :            : //-----------------------------------------------------------------------------
     541                 :            : 
     542                 :          0 : void CMetaData::RebuildSearchBuff(UnsignedInt32 xintSearchType)
     543                 :            : // Grow the search return buffer of the class to match the current storage
     544                 :            : // buffer size and fit it for the passed return type.
     545                 :            : {
     546         [ #  # ]:          0 :     if(!mintBufferSize)  return;
     547                 :            : 
     548         [ #  # ]:          0 :     if(mSearchBuff.mintNumOwners < mintBufferSize) {
     549         [ #  # ]:          0 :         if(mSearchBuff.mpaintOwners)
     550         [ #  # ]:          0 :             delete [] mSearchBuff.mpaintOwners;
     551         [ #  # ]:          0 :         mSearchBuff.mpaintOwners = new UnsignedInt32[mintBufferSize];
     552                 :          0 :         mSearchBuff.mintNumOwners = mintBufferSize;
     553         [ #  # ]:          0 :         if(!mSearchBuff.mpaintOwners) {
     554                 :          0 :             mSearchBuff.mintNumOwners = 0;
     555                 :          0 :             throw CCubitFile::eMemoryError;
     556                 :            :         }
     557                 :            :     }
     558         [ #  # ]:          0 :     if(mSearchBuff.mintNumNames < mintBufferSize) {
     559         [ #  # ]:          0 :         if(mSearchBuff.mpapachrNames)
     560         [ #  # ]:          0 :             delete [] mSearchBuff.mpapachrNames;
     561         [ #  # ]:          0 :         mSearchBuff.mpapachrNames = new ConstCharPtr[mintBufferSize];
     562                 :          0 :         mSearchBuff.mintNumNames = mintBufferSize;
     563         [ #  # ]:          0 :         if(!mSearchBuff.mpapachrNames) {
     564                 :          0 :             mSearchBuff.mintNumNames = 0;
     565                 :          0 :             throw CCubitFile::eMemoryError;
     566                 :            :         }
     567                 :            :     }
     568 [ #  # ][ #  # ]:          0 :     if((mSearchBuff.mintNumMetaData < mintBufferSize) ||
     569                 :          0 :         (mSearchBuff.mintMetaDataType != xintSearchType)) {
     570         [ #  # ]:          0 :         if(mSearchBuff.mpaValues) {
     571   [ #  #  #  #  :          0 :             switch(mSearchBuff.mintMetaDataType) {
                   #  # ]
     572                 :            :             case eUnsignedInt32:
     573         [ #  # ]:          0 :                 delete [] (UnsignedInt32*)mSearchBuff.mpaValues;  break;
     574                 :            :             case eString:
     575         [ #  # ]:          0 :                 delete [] (ConstCharPtr*)mSearchBuff.mpaValues;  break;
     576                 :            :             case eDouble:
     577         [ #  # ]:          0 :                 delete [] (double*)mSearchBuff.mpaValues;  break;
     578                 :            :             case eUnsignedInt32Array:
     579         [ #  # ]:          0 :                 delete [] (ConstUnsignedInt32Ptr*)mSearchBuff.mpaValues;  break;
     580                 :            :             case eDoubleArray:
     581         [ #  # ]:          0 :                 delete [] (ConstDoublePtr*)mSearchBuff.mpaValues;  break;
     582                 :            :             }
     583                 :            :         }
     584         [ #  # ]:          0 :         if(mSearchBuff.mpaintNumValues)
     585         [ #  # ]:          0 :             delete [] mSearchBuff.mpaintNumValues;
     586                 :          0 :         mSearchBuff.mintMetaDataType = xintSearchType;
     587                 :          0 :         mSearchBuff.mintNumMetaData = mintBufferSize;
     588                 :            : 
     589   [ #  #  #  #  :          0 :         switch(mSearchBuff.mintMetaDataType) {
                   #  # ]
     590                 :            :         case eUnsignedInt32:
     591         [ #  # ]:          0 :             mSearchBuff.mpaValues = new UnsignedInt32[mintBufferSize];
     592                 :          0 :             break;
     593                 :            :         case eString:
     594         [ #  # ]:          0 :             mSearchBuff.mpaValues = new ConstCharPtr[mintBufferSize];
     595                 :          0 :             break;
     596                 :            :         case eDouble:
     597         [ #  # ]:          0 :             mSearchBuff.mpaValues = new double[mintBufferSize];
     598                 :          0 :             break;
     599                 :            :         case eUnsignedInt32Array:
     600         [ #  # ]:          0 :             mSearchBuff.mpaValues = new ConstUnsignedInt32Ptr[mintBufferSize];
     601                 :          0 :             break;
     602                 :            :         case eDoubleArray:
     603         [ #  # ]:          0 :             mSearchBuff.mpaValues = new ConstDoublePtr[mintBufferSize];
     604                 :          0 :             break;
     605                 :            :         }
     606         [ #  # ]:          0 :         if(!mSearchBuff.mpaValues) {
     607                 :          0 :             mSearchBuff.mintNumMetaData = 0;
     608                 :          0 :             throw CCubitFile::eMemoryError;
     609                 :            :         }
     610                 :            : 
     611         [ #  # ]:          0 :         switch(mSearchBuff.mintMetaDataType) {
     612                 :            :         case eUnsignedInt32Array:
     613                 :            :         case eDoubleArray:
     614         [ #  # ]:          0 :             mSearchBuff.mpaintNumValues = new UnsignedInt32[mintBufferSize];
     615         [ #  # ]:          0 :             if(!mSearchBuff.mpaintNumValues) {
     616                 :          0 :                 mSearchBuff.mintMetaDataType = 0;
     617   [ #  #  #  #  :          0 :                 switch(mSearchBuff.mintMetaDataType) {
                   #  # ]
     618                 :            :                 case eUnsignedInt32:
     619         [ #  # ]:          0 :                     delete [] (UnsignedInt32*)mSearchBuff.mpaValues;  break;
     620                 :            :                 case eString:
     621         [ #  # ]:          0 :                     delete [] (ConstCharPtr*)mSearchBuff.mpaValues;  break;
     622                 :            :                 case eDouble:
     623         [ #  # ]:          0 :                     delete [] (double*)mSearchBuff.mpaValues;  break;
     624                 :            :                 case eUnsignedInt32Array:
     625         [ #  # ]:          0 :                     delete [] (ConstUnsignedInt32Ptr*)mSearchBuff.mpaValues;  break;
     626                 :            :                 case eDoubleArray:
     627         [ #  # ]:          0 :                     delete [] (ConstDoublePtr*)mSearchBuff.mpaValues;  break;
     628                 :            :                 }
     629                 :          0 :                 mSearchBuff.mpaValues = NULL;
     630                 :          0 :                 throw CCubitFile::eMemoryError;
     631                 :            :             }
     632                 :          0 :             break;
     633                 :            :         default:
     634                 :          0 :             mSearchBuff.mpaintNumValues = NULL;
     635                 :            :         }
     636                 :            :     }
     637                 :            : }
     638                 :            : 
     639                 :          0 : UnsignedInt32 CMetaData::SearchByID(UnsignedInt32 xintSearchType,
     640                 :            :                                     UnsignedInt32 xintOwner)
     641                 :            : // Traverses the meta-data entries to find entries with an owner id matching
     642                 :            : // the passed one and copies the values and names of those entries to the
     643                 :            : // search buffer.
     644                 :            : // Private function, returns the number of entries meeting the search criteria,
     645                 :            : // no exceptions thrown.
     646                 :            : {
     647         [ #  # ]:          0 :     if(!mHeader.mintMetaDataCount)  return 0;  // none found
     648                 :            : 
     649                 :          0 :     UnsignedInt32 lintNumFound = 0;
     650         [ #  # ]:          0 :     for(UnsignedInt32 lintEntry = 0; lintEntry <
     651                 :            :         mHeader.mintMetaDataCount; lintEntry++) {
     652         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataOwner == xintOwner) {
     653         [ #  # ]:          0 :             if(mpaEntries[lintEntry].mintMetaDataType == xintSearchType) {
     654                 :          0 :                 mSearchBuff.mpapachrNames[lintNumFound] =
     655                 :          0 :                     mpaEntries[lintEntry].mpachrName;
     656   [ #  #  #  #  :          0 :                 switch(xintSearchType) {
                   #  # ]
     657                 :            :                 case eUnsignedInt32:
     658                 :          0 :                     ((UnsignedInt32*)mSearchBuff.mpaValues)[lintNumFound] =
     659                 :          0 :                         mpaEntries[lintEntry].muValue.mint;
     660                 :          0 :                     break;
     661                 :            :                 case eString:
     662                 :          0 :                     ((ConstCharPtr*)mSearchBuff.mpaValues)[lintNumFound] =
     663                 :          0 :                         mpaEntries[lintEntry].muValue.mpachr;
     664                 :          0 :                     break;
     665                 :            :                 case eDouble:
     666                 :          0 :                     ((double*)mSearchBuff.mpaValues)[lintNumFound] =
     667                 :          0 :                         mpaEntries[lintEntry].muValue.mdbl;
     668                 :          0 :                     break;
     669                 :            :                 case eUnsignedInt32Array:
     670                 :          0 :                     ((ConstUnsignedInt32Ptr*)mSearchBuff.mpaValues)[lintNumFound] =
     671                 :          0 :                         mpaEntries[lintEntry].muValue.mpaint;
     672                 :          0 :                     mSearchBuff.mpaintNumValues[lintNumFound] =
     673                 :          0 :                         mpaEntries[lintEntry].mintNumValues;
     674                 :          0 :                     break;
     675                 :            :                 case eDoubleArray:
     676                 :          0 :                     ((ConstDoublePtr*)mSearchBuff.mpaValues)[lintNumFound] =
     677                 :          0 :                         mpaEntries[lintEntry].muValue.mpadbl;
     678                 :          0 :                     mSearchBuff.mpaintNumValues[lintNumFound] =
     679                 :          0 :                         mpaEntries[lintEntry].mintNumValues;
     680                 :          0 :                     break;
     681                 :            :                 }
     682                 :          0 :                 lintNumFound++;
     683                 :            :             }
     684                 :            :         }
     685                 :            :     }
     686                 :          0 :     return lintNumFound;  // return number found
     687                 :            : }
     688                 :            : 
     689                 :          0 : UnsignedInt32 CMetaData::SearchByName(UnsignedInt32 xintSearchType,
     690                 :            :                                       const char* xpachrName)
     691                 :            : // Traverses the meta-data entries to find entries with an name matching
     692                 :            : // the passed one and copies the owner id's and names of those entries to the
     693                 :            : // search buffer.
     694                 :            : // Private function, returns the number of entries meeting the search criteria,
     695                 :            : // no exceptions thrown.
     696                 :            : {
     697         [ #  # ]:          0 :     if(!mHeader.mintMetaDataCount)  return 0;  // none found
     698                 :            : 
     699                 :          0 :     UnsignedInt32 lintNumFound = 0;
     700         [ #  # ]:          0 :     for(UnsignedInt32 lintEntry = 0; lintEntry <
     701                 :            :         mHeader.mintMetaDataCount; lintEntry++) {
     702         [ #  # ]:          0 :         if(!std::strcmp(xpachrName, mpaEntries[lintEntry].mpachrName)) {
     703         [ #  # ]:          0 :             if(mpaEntries[lintEntry].mintMetaDataType == xintSearchType) {
     704                 :          0 :                 mSearchBuff.mpaintOwners[lintNumFound] =
     705                 :          0 :                     mpaEntries[lintEntry].mintMetaDataOwner;
     706   [ #  #  #  #  :          0 :                 switch(xintSearchType) {
                   #  # ]
     707                 :            :                 case eUnsignedInt32:
     708                 :          0 :                     ((UnsignedInt32*)mSearchBuff.mpaValues)[lintNumFound] =
     709                 :          0 :                         mpaEntries[lintEntry].muValue.mint;
     710                 :          0 :                     break;
     711                 :            :                 case eString:
     712                 :          0 :                     ((ConstCharPtr*)mSearchBuff.mpaValues)[lintNumFound] =
     713                 :          0 :                         mpaEntries[lintEntry].muValue.mpachr;
     714                 :          0 :                     break;
     715                 :            :                 case eDouble:
     716                 :          0 :                     ((double*)mSearchBuff.mpaValues)[lintNumFound] =
     717                 :          0 :                         mpaEntries[lintEntry].muValue.mdbl;
     718                 :          0 :                     break;
     719                 :            :                 case eUnsignedInt32Array:
     720                 :          0 :                     ((ConstUnsignedInt32Ptr*)mSearchBuff.mpaValues)[lintNumFound] =
     721                 :          0 :                         mpaEntries[lintEntry].muValue.mpaint;
     722                 :          0 :                     mSearchBuff.mpaintNumValues[lintNumFound] =
     723                 :          0 :                         mpaEntries[lintEntry].mintNumValues;
     724                 :          0 :                     break;
     725                 :            :                 case eDoubleArray:
     726                 :          0 :                     ((ConstDoublePtr*)mSearchBuff.mpaValues)[lintNumFound] =
     727                 :          0 :                         mpaEntries[lintEntry].muValue.mpadbl;
     728                 :          0 :                     mSearchBuff.mpaintNumValues[lintNumFound] =
     729                 :          0 :                         mpaEntries[lintEntry].mintNumValues;
     730                 :          0 :                     break;
     731                 :            :                 }
     732                 :          0 :                 lintNumFound++;
     733                 :            :             }
     734                 :            :         }
     735                 :            :     }
     736                 :          0 :     return lintNumFound;  // return number found
     737                 :            : }
     738                 :            : 
     739                 :          0 : UnsignedInt32 CMetaData::SearchAll(UnsignedInt32 xintSearchType)
     740                 :            : // Traverses the meta-data entries to find all entries of the passed type.
     741                 :            : // Private function, returns the number of entries meeting the search criteria,
     742                 :            : // no exceptions thrown.
     743                 :            : {
     744         [ #  # ]:          0 :     if(!mHeader.mintMetaDataCount)  return 0;  // none found
     745                 :            : 
     746                 :          0 :     UnsignedInt32 lintNumFound = 0;
     747         [ #  # ]:          0 :     for(UnsignedInt32 lintEntry = 0; lintEntry <
     748                 :            :         mHeader.mintMetaDataCount; lintEntry++) {
     749         [ #  # ]:          0 :         if(mpaEntries[lintEntry].mintMetaDataType == xintSearchType) {
     750                 :          0 :             mSearchBuff.mpapachrNames[lintNumFound] =
     751                 :          0 :                 mpaEntries[lintEntry].mpachrName;
     752                 :          0 :             mSearchBuff.mpaintOwners[lintNumFound] =
     753                 :          0 :                 mpaEntries[lintEntry].mintMetaDataOwner;
     754   [ #  #  #  #  :          0 :             switch(xintSearchType) {
                   #  # ]
     755                 :            :             case eUnsignedInt32:
     756                 :          0 :                 ((UnsignedInt32*)mSearchBuff.mpaValues)[lintNumFound] =
     757                 :          0 :                     mpaEntries[lintEntry].muValue.mint;
     758                 :          0 :                 break;
     759                 :            :             case eString:
     760                 :          0 :                 ((ConstCharPtr*)mSearchBuff.mpaValues)[lintNumFound] =
     761                 :          0 :                     mpaEntries[lintEntry].muValue.mpachr;
     762                 :          0 :                 break;
     763                 :            :             case eDouble:
     764                 :          0 :                 ((double*)mSearchBuff.mpaValues)[lintNumFound] =
     765                 :          0 :                     mpaEntries[lintEntry].muValue.mdbl;
     766                 :          0 :                 break;
     767                 :            :             case eUnsignedInt32Array:
     768                 :          0 :                 ((ConstUnsignedInt32Ptr*)mSearchBuff.mpaValues)[lintNumFound] =
     769                 :          0 :                     mpaEntries[lintEntry].muValue.mpaint;
     770                 :          0 :                 mSearchBuff.mpaintNumValues[lintNumFound] =
     771                 :          0 :                     mpaEntries[lintEntry].mintNumValues;
     772                 :          0 :                 break;
     773                 :            :             case eDoubleArray:
     774                 :          0 :                 ((ConstDoublePtr*)mSearchBuff.mpaValues)[lintNumFound] =
     775                 :          0 :                     mpaEntries[lintEntry].muValue.mpadbl;
     776                 :          0 :                 mSearchBuff.mpaintNumValues[lintNumFound] =
     777                 :          0 :                     mpaEntries[lintEntry].mintNumValues;
     778                 :          0 :                 break;
     779                 :            :             }
     780                 :          0 :             lintNumFound++;
     781                 :            :         }
     782                 :            :     }
     783                 :          0 :     return lintNumFound;  // return number found
     784                 :            : }
     785                 :            : 
     786                 :            : 
     787                 :            : 
     788                 :            : ///////////////////////////////////////////////////////////////////////////////
     789                 :            : // Deletion functions
     790                 :            : ///////////////////////////////////////////////////////////////////////////////
     791                 :            : 
     792                 :          0 : UnsignedInt32 CMetaData::ClearMetaDataForID(UnsignedInt32 xintOwner)
     793                 :            : // Delete all meta-data entries with the same owner.
     794                 :            : {
     795         [ #  # ]:          0 :     if(mHeader.mintMetaDataCount) {
     796         [ #  # ]:          0 :         for(UnsignedInt32 lintEntry = 0; lintEntry <
     797                 :            :             mHeader.mintMetaDataCount; lintEntry++) {
     798         [ #  # ]:          0 :             if(mpaEntries[lintEntry].mintMetaDataOwner == xintOwner)
     799                 :          0 :                 FreeAt(lintEntry);
     800                 :            :         }
     801                 :            :     }
     802                 :          0 :     return CCubitFile::eSuccess;
     803                 :            : }
     804                 :            : 
     805                 :          0 : void CMetaData::FreeValueAt(UnsignedInt32 xintEntry)
     806                 :            : // Frees any allocated memory associated with the value of the meta-data stored
     807                 :            : // at the passed index.  Private function, no exceptions thrown.
     808                 :            : {
     809   [ #  #  #  # ]:          0 :     switch(mpaEntries[xintEntry].mintMetaDataType) {
     810                 :            :     case eString:
     811         [ #  # ]:          0 :         if(mpaEntries[xintEntry].muValue.mpachr)
     812         [ #  # ]:          0 :             delete [] mpaEntries[xintEntry].muValue.mpachr;
     813                 :          0 :         mpaEntries[xintEntry].muValue.mpachr = NULL;
     814                 :          0 :         break;
     815                 :            :     case eUnsignedInt32Array:
     816         [ #  # ]:          0 :         if(mpaEntries[xintEntry].muValue.mpaint)
     817         [ #  # ]:          0 :             delete [] mpaEntries[xintEntry].muValue.mpaint;
     818                 :          0 :         mpaEntries[xintEntry].muValue.mpaint = NULL;
     819                 :          0 :         break;
     820                 :            :     case eDoubleArray:
     821         [ #  # ]:          0 :         if(mpaEntries[xintEntry].muValue.mpadbl)
     822         [ #  # ]:          0 :             delete [] mpaEntries[xintEntry].muValue.mpadbl;
     823                 :          0 :         mpaEntries[xintEntry].muValue.mpadbl = NULL;
     824                 :          0 :         break;
     825                 :            :     }
     826                 :          0 : }
     827                 :            : 
     828                 :          0 : void CMetaData::FreeAt(UnsignedInt32 xintEntry)
     829                 :            : // Frees the meta-data at the passed index and moves all data at higher indices
     830                 :            : // down to close the gap.  Private function, no exceptions thrown.
     831                 :            : {
     832                 :            :     // Free the allocated memory for an entry.
     833         [ #  # ]:          0 :     delete [] mpaEntries[xintEntry].mpachrName;
     834                 :          0 :     FreeValueAt(xintEntry);
     835                 :          0 :     mHeader.mintMetaDataCount--;
     836                 :            : 
     837                 :            :     // Move all entries in the meta-data table ahead of the deleted one down
     838                 :            :     // to fill in the gap.
     839         [ #  # ]:          0 :     if(xintEntry < mHeader.mintMetaDataCount) {
     840         [ #  # ]:          0 :         for(UnsignedInt32 lintCopyTo = xintEntry; lintCopyTo <
     841                 :            :             mHeader.mintMetaDataCount; lintCopyTo++) {
     842                 :          0 :             memcpy(&mpaEntries[lintCopyTo], &mpaEntries[lintCopyTo + 1],
     843                 :          0 :                 sizeof(SCubitFileMetaDataEntry));
     844                 :            :         }
     845                 :            :     }
     846                 :          0 : }
     847                 :            : 
     848                 :          0 : void CMetaData::FreeAll()
     849                 :            : // Frees all memory used to store meta-data data and resets the object back
     850                 :            : // to its constructed state.  (Has no effect on the return buffers.)
     851                 :            : // Private function, no exceptions thrown.
     852                 :            : {
     853         [ #  # ]:          0 :     if(mHeader.mintMetaDataCount) {
     854         [ #  # ]:          0 :         for(UnsignedInt32 lintEntry = 0; lintEntry < mintBufferSize; lintEntry++) {
     855         [ #  # ]:          0 :             if(mpaEntries[lintEntry].mpachrName)
     856         [ #  # ]:          0 :                 delete [] mpaEntries[lintEntry].mpachrName;
     857                 :          0 :             FreeValueAt(lintEntry);
     858                 :            :         }
     859         [ #  # ]:          0 :         delete [] mpaEntries;
     860                 :          0 :         mHeader.mintMetaDataCount = 0;
     861                 :          0 :         mintBufferSize = 0;
     862                 :          0 :         mpaEntries = NULL;
     863                 :            :     }
     864                 :          0 :     mHeader.mintMetaDataSchema = 0;
     865                 :          0 :     mHeader.mintMetaDataCompress = 0;
     866                 :          0 : }
     867                 :            : 
     868                 :            : 
     869                 :            : ///////////////////////////////////////////////////////////////////////////////
     870                 :            : // Read / Write File Methods
     871                 :            : ///////////////////////////////////////////////////////////////////////////////
     872                 :            : 
     873                 :          0 : void CMetaData::WriteMetaData(FILE* xpFile,
     874                 :            :                               UnsignedInt32& xintWroteAtOffset,
     875                 :            :                               UnsignedInt32& xintLength,
     876                 :            :                               UnsignedInt32 xintOffsetFrom)
     877                 :            : // Write the meta-data stored in this object to the passed file.  The file
     878                 :            : // position, offset from an optional passed value, and length are returned.
     879                 :            : {
     880         [ #  # ]:          0 :     if(!xpFile)  throw CCubitFile::eFileWriteError;
     881                 :            : 
     882         [ #  # ]:          0 :     CIOWrapper* lpIO = new CIOWrapper(xpFile);
     883                 :          0 :     xintWroteAtOffset = lpIO->BeginWriteBlock(xintOffsetFrom);
     884                 :            : 
     885                 :            :     // Write a description header.
     886                 :          0 :     lpIO->Write(&mHeader.mintMetaDataSchema, 1);
     887                 :          0 :     lpIO->Write(&mHeader.mintMetaDataCompress, 1);
     888                 :          0 :     lpIO->Write(&mHeader.mintMetaDataCount, 1);
     889                 :            : 
     890                 :            :     // Write the actual meta-data entries.
     891                 :          0 :     UnsignedInt32 lintEntry, lintNumEntries = mHeader.mintMetaDataCount;
     892         [ #  # ]:          0 :     if(lintNumEntries) {
     893         [ #  # ]:          0 :         for(lintEntry = 0; lintEntry < lintNumEntries; lintEntry++) {
     894                 :          0 :             lpIO->Write(&mpaEntries[lintEntry].mintMetaDataOwner, 1);
     895                 :          0 :             lpIO->Write(&mpaEntries[lintEntry].mintMetaDataType, 1);
     896                 :          0 :             lpIO->Write(mpaEntries[lintEntry].mpachrName);
     897   [ #  #  #  #  :          0 :             switch(mpaEntries[lintEntry].mintMetaDataType) {
                   #  # ]
     898                 :            :             case eUnsignedInt32:
     899                 :          0 :                 lpIO->Write(&mpaEntries[lintEntry].muValue.mint, 1);
     900                 :          0 :                 break;
     901                 :            :             case eString:
     902                 :          0 :                 lpIO->Write(mpaEntries[lintEntry].muValue.mpachr);
     903                 :          0 :                 break;
     904                 :            :             case eDouble:
     905                 :          0 :                 lpIO->Write(&mpaEntries[lintEntry].muValue.mdbl, 1);
     906                 :          0 :                 break;
     907                 :            :             case eUnsignedInt32Array:
     908                 :          0 :                 lpIO->Write(&mpaEntries[lintEntry].mintNumValues, 1);
     909         [ #  # ]:          0 :                 if(mpaEntries[lintEntry].mintNumValues) {
     910                 :          0 :                     lpIO->Write(mpaEntries[lintEntry].muValue.mpaint,
     911                 :          0 :                         mpaEntries[lintEntry].mintNumValues);
     912                 :            :                 }
     913                 :          0 :                 break;
     914                 :            :             case eDoubleArray:
     915                 :          0 :                 lpIO->Write(&mpaEntries[lintEntry].mintNumValues, 1);
     916         [ #  # ]:          0 :                 if(mpaEntries[lintEntry].mintNumValues) {
     917                 :          0 :                     lpIO->Write(mpaEntries[lintEntry].muValue.mpadbl,
     918                 :          0 :                         mpaEntries[lintEntry].mintNumValues);
     919                 :            :                 }
     920                 :          0 :                 break;
     921                 :            :             }
     922                 :            :         }
     923                 :            :     }
     924                 :          0 :     xintLength = lpIO->EndWriteBlock();
     925         [ #  # ]:          0 :     delete lpIO;
     926                 :          0 : }
     927                 :            : 
     928                 :          0 : void CMetaData::ReadMetaData(FILE* xpFile,
     929                 :            :                              UnsignedInt32 xintAbsoluteOffset,
     930                 :            :                              UnsignedInt32 xintRelativeOffset,
     931                 :            :                              UnsignedInt32 xintSourceEndian)
     932                 :            : // Reset the meta-data object and then fill it with data read from a passed
     933                 :            : // file at the passed location.  The data will be in the passed endian format
     934                 :            : // which is not stored with the meta-data itself as the meta-data is never
     935                 :            : // fully independent.
     936                 :            : {
     937                 :            :     // Delete all stored data
     938                 :          0 :     FreeAll();
     939                 :            : 
     940         [ #  # ]:          0 :     if(!xpFile)  throw CCubitFile::eFileReadError;
     941                 :            : 
     942         [ #  # ]:          0 :     CIOWrapper* lpIO = new CIOWrapper(xpFile, xintSourceEndian);
     943                 :          0 :     lpIO->BeginReadBlock(xintAbsoluteOffset, xintRelativeOffset);
     944                 :            : 
     945                 :            :     // Read the description header.
     946                 :          0 :     lpIO->Read(&mHeader.mintMetaDataSchema, 1);
     947                 :          0 :     lpIO->Read(&mHeader.mintMetaDataCompress, 1);
     948                 :          0 :     lpIO->Read(&mHeader.mintMetaDataCount, 1);
     949                 :            : 
     950                 :          0 :     UnsignedInt32 lintEntry, lintNumEntries = mHeader.mintMetaDataCount;
     951         [ #  # ]:          0 :     if(lintNumEntries) {
     952                 :            :         // Grow the storage capacity of the meta-data object to match that of
     953                 :            :         // the stored data.
     954                 :          0 :         UnsignedInt32 lintGrowSizeBy = mintGrowSizeBy;
     955                 :          0 :         mintGrowSizeBy = lintNumEntries;
     956                 :          0 :         GrowSize();
     957                 :          0 :         mintGrowSizeBy = lintGrowSizeBy;
     958                 :            : 
     959                 :            :         // Read the stored meta-data entries.
     960         [ #  # ]:          0 :         for(lintEntry = 0; lintEntry < lintNumEntries; lintEntry++) {
     961                 :          0 :             lpIO->Read(&mpaEntries[lintEntry].mintMetaDataOwner, 1);
     962                 :          0 :             lpIO->Read(&mpaEntries[lintEntry].mintMetaDataType, 1);
     963                 :          0 :             mpaEntries[lintEntry].mpachrName = lpIO->Read();
     964   [ #  #  #  #  :          0 :             switch(mpaEntries[lintEntry].mintMetaDataType) {
                   #  # ]
     965                 :            :             case eUnsignedInt32:
     966                 :          0 :                 lpIO->Read(&mpaEntries[lintEntry].muValue.mint, 1);
     967                 :          0 :                 break;
     968                 :            :             case eString:
     969                 :          0 :                 mpaEntries[lintEntry].muValue.mpachr = lpIO->Read();
     970                 :          0 :                 break;
     971                 :            :             case eDouble:
     972                 :          0 :                 lpIO->Read(&mpaEntries[lintEntry].muValue.mdbl, 1);
     973                 :          0 :                 break;
     974                 :            :             case eUnsignedInt32Array:
     975                 :          0 :                 lpIO->Read(&mpaEntries[lintEntry].mintNumValues, 1);
     976         [ #  # ]:          0 :                 if(mpaEntries[lintEntry].mintNumValues) {
     977                 :          0 :                     mpaEntries[lintEntry].muValue.mpaint =
     978         [ #  # ]:          0 :                         new UnsignedInt32[mpaEntries[lintEntry].mintNumValues];
     979         [ #  # ]:          0 :                     if(!mpaEntries[lintEntry].muValue.mpaint)
     980                 :          0 :                         throw CCubitFile::eMemoryError;
     981                 :          0 :                     lpIO->Read(mpaEntries[lintEntry].muValue.mpaint,
     982                 :          0 :                         mpaEntries[lintEntry].mintNumValues);
     983                 :            :                 }
     984                 :          0 :                 break;
     985                 :            :             case eDoubleArray:
     986                 :          0 :                 lpIO->Read(&mpaEntries[lintEntry].mintNumValues, 1);
     987         [ #  # ]:          0 :                 if(mpaEntries[lintEntry].mintNumValues) {
     988                 :          0 :                     mpaEntries[lintEntry].muValue.mpadbl =
     989         [ #  # ]:          0 :                         new double[mpaEntries[lintEntry].mintNumValues];
     990         [ #  # ]:          0 :                     if(!mpaEntries[lintEntry].muValue.mpadbl)
     991                 :          0 :                         throw CCubitFile::eMemoryError;
     992                 :          0 :                     lpIO->Read(mpaEntries[lintEntry].muValue.mpadbl,
     993                 :          0 :                         mpaEntries[lintEntry].mintNumValues);
     994                 :            :                 }
     995                 :          0 :                 break;
     996                 :            :             }
     997                 :            :         }
     998                 :            :     }
     999         [ #  # ]:          0 :     delete lpIO;
    1000                 :          0 : }
    1001                 :            : 

Generated by: LCOV version 1.11