HIK2014/humanik/hikdump_std.inl Source File

hikdump_std.inl
Go to the documentation of this file.
1 
7 /**************************************************************************************
8 
9 Copyright (C) 2009 Autodesk, Inc.
10 All Rights Reserved.
11 
12 The coded instructions, statements, computer programs, and/or related material (collectively "Data")
13 in these files contain unpublished information proprietary to Autodesk, Inc., ("Autodesk") which is
14 protected by Canada and United States of America federal copyright law and by international treaties.
15 
16 The Data may not be disclosed or distributed to third parties, in whole or in part, without the prior
17 written consent of Autodesk.
18 
19 THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED.
20 AUTODESK MAKES NO WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING BY CUSTOM
21 OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
22 FITNESS FOR A PARTICULAR PURPOSE OR USE. WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT
23 THE OPERATION OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE.
24 
25 IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS OR SUPPLIERS ("AUTODESK GROUP")
26 BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR
27 MULTIPLE DAMAGES OR OTHER SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
28 OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND), HOWEVER CAUSED, AND REGARDLESS
29 OF THE THEORY OF LIABILITY, WHETHER DERIVED FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO,
30 NEGLIGENCE), OR OTHERWISE, ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
31 WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
32 
33 **************************************************************************************/
34 
35 template<typename HIKFile>
36 inline bool Header::Write(HIKFile pFile) const
37 {
38  bool status;
39  status = fwrite( (void *)&HeaderStr[0], sizeof(char), HEADERLENGTH, pFile) == HEADERLENGTH;
40  status = (status && (fwrite( (void *)&MagicNumber, sizeof(int), 1, pFile) == 1));
41  return status;
42 }
43 
44 template<typename HIKFile>
45 inline bool Header::Read(HIKFile pFile)
46 {
47  char ReadBuf[HEADERLENGTH];
48  if(fread( (void *)&ReadBuf[0], sizeof(char), HEADERLENGTH, pFile) == HEADERLENGTH)
49  {
50  if(strcmp(HeaderStr,ReadBuf) == 0)
51  {
52  int ReadMagicNumber;
53  if(fread( (void *)&ReadMagicNumber, sizeof(int), 1, pFile) == 1)
54  {
55  bSwap = !(ReadMagicNumber == MagicNumber);
56  return true;
57  }
58  }
59  }
60 
61  return false;
62 }
63 
64 template<typename type, int count>
65 template<typename HIKFile>
66 inline bool Field<type, count>::Write(HIKFile pFile) const
67 {
68  return fwrite( (void *)&mField[0], sizeof(FieldType), eCount, pFile) == eCount;
69 }
70 
71 template<typename type, int count>
72 template<typename HIKFile>
73 inline bool Field<type, count>::Read(HIKFile pFile, bool bSwap)
74 {
75  bool Result = fread( (void *)&mField[0], sizeof(FieldType), eCount, pFile) == eCount;
76 
77  if(bSwap)
78  {
79  for(int i = 0; i < eCount; i++)
80  {
81  SwapBytes4((char*)&mField[i]);
82  }
83  }
84 
85  return Result;
86 }
87 
88 template<typename type, int count1, int count2>
89 template<typename HIKFile>
90 inline bool Field2D<type, count1, count2>::Write(HIKFile pFile) const
91 {
92  return fwrite( (void *)&mField[0][0], sizeof(FieldType), eCount, pFile) == eCount;
93 }
94 
95 template<typename type, int count1, int count2>
96 template<typename HIKFile>
97 inline bool Field2D<type, count1, count2>::Read(HIKFile pFile, bool bSwap)
98 {
99  bool Result = fread( (void *)&mField[0][0], sizeof(FieldType), eCount, pFile) == eCount;
100 
101  if(bSwap)
102  {
103  for(int i = 0; i < eCount1; i++)
104  for(int j = 0; j < eCount2; j++)
105  {
106  SwapBytes4((char*)&mField[i][j]);
107  }
108  }
109 
110  return Result;
111 }
112 
113 template<typename type> bool Write(const char* pFileName, const type& pStream)
114 {
115  // Save all the collected data
116  FILE* lFile = fopen(pFileName, "wb+");
117  if(lFile != NULL)
118  {
119  pStream.Write(lFile);
120  fclose(lFile);
121  return true;
122  }
123  return false;
124 }
125 
126 template<typename type> bool WriteBlock(const char* pFileName, const size_t& pElementSize, const size_t& pElementCount, type& pStream)
127 {
128  // Save all the collected data
129  FILE* lFile = fopen(pFileName, "ab+");
130  if(lFile != NULL)
131  {
132  fwrite(pStream, pElementSize, pElementCount, lFile);
133  fclose(lFile);
134  return true;
135  }
136  return false;
137 }
138 
139 template<typename type> bool Read(const char* pFileName, type& pStream)
140 {
141  // Read all the data
142  bool bResult = false;
143  FILE* lFile = fopen(pFileName, "rb");
144  if(lFile != NULL)
145  {
146  bResult = pStream.Read(lFile);
147  fclose(lFile);
148  }
149 
150  return bResult;
151 }
152 
153 template<typename type> bool ReadBlock(const char* pFileName, const size_t pOffset, const size_t& pElementSize, const size_t& pElementCount, type& pStream)
154 {
155  // Read all the data
156  bool bResult = false;
157  FILE* lFile = fopen(pFileName, "rb");
158  if(lFile != NULL)
159  {
160  fseek(lFile, pOffset, 0);
161  bResult = fread(pStream, pElementSize, pElementCount, lFile) > 0 ;
162  fclose(lFile);
163  }
164 
165  return bResult;
166 }
167 
bool WriteBlock(const char *pFileName, const size_t &pElementSize, const size_t &pElementCount, type &pStream)
bool bSwap
Definition: hikdump.h:206
bool Write(HIKFile pFile) const
Definition: hikdump_std.inl:36
Py_ssize_t i
Definition: abstract.h:1086
void SwapBytes4(char *ToSwap)
Definition: hikdump.h:224
#define NULL
Definition: kaydara.h:179
type FieldType
Definition: hikdump.h:239
int type
Definition: node.h:20
bool Read(HIKFile pFile)
Definition: hikdump_std.inl:45
type FieldType
Definition: hikdump.h:257
char char int FILE
Definition: fileobject.h:45
#define HEADERLENGTH
Definition: hikdump.h:192
bool ReadBlock(const char *pFileName, const size_t pOffset, const size_t &pElementSize, const size_t &pElementCount, type &pStream)
bool Write(const char *pFileName, const type &pStream)
const int MagicNumber
Definition: hikdump.h:199
bool Read(HIKFile pFile, bool bSwap)
Definition: hikdump_std.inl:73
bool Read(const char *pFileName, type &pStream)
bool Write(HIKFile pFile) const
Definition: hikdump_std.inl:66
bool Write(HIKFile pFile) const
Definition: hikdump_std.inl:90
bool Read(HIKFile pFile, bool bSwap)
Definition: hikdump_std.inl:97