HIK2016/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 = NULL;
117 #if !defined(_MSC_VER) || (_MSC_VER == 1500)
118  lFile = fopen(pFileName, "wb+");
119 #else
120  fopen_s(&lFile, pFileName, "wb+");
121 #endif
122  if(lFile != NULL)
123  {
124  pStream.Write(lFile);
125  fclose(lFile);
126  return true;
127  }
128  return false;
129 }
130 
131 template<typename type> bool WriteBlock(const char* pFileName, const size_t& pElementSize, const size_t& pElementCount, type& pStream)
132 {
133  // Save all the collected data
134  FILE* lFile = NULL;
135 #if !defined(_MSC_VER) || (_MSC_VER == 1500)
136  lFile = fopen(pFileName, "ab+");
137 #else
138  fopen_s(&lFile, pFileName, "ab+");
139 #endif
140  if(lFile != NULL)
141  {
142  fwrite(pStream, pElementSize, pElementCount, lFile);
143  fclose(lFile);
144  return true;
145  }
146  return false;
147 }
148 
149 template<typename type> bool Read(const char* pFileName, type& pStream)
150 {
151  // Read all the data
152  bool bResult = false;
153  FILE* lFile = NULL;
154 #if !defined(_MSC_VER) || (_MSC_VER == 1500)
155  lFile = fopen(pFileName, "rb");
156 #else
157  fopen_s(&lFile, pFileName, "rb");
158 #endif
159  if(lFile != NULL)
160  {
161  bResult = pStream.Read(lFile);
162  fclose(lFile);
163  }
164 
165  return bResult;
166 }
167 
168 template<typename type> bool ReadBlock(const char* pFileName, const size_t pOffset, const size_t& pElementSize, const size_t& pElementCount, type& pStream)
169 {
170  // Read all the data
171  bool bResult = false;
172  FILE* lFile = NULL;
173 #if !defined(_MSC_VER) || (_MSC_VER == 1500)
174  lFile = fopen(pFileName, "rb");
175 #else
176  fopen_s(&lFile, pFileName, "rb");
177 #endif
178  if(lFile != NULL)
179  {
180  fseek(lFile, pOffset, 0);
181  bResult = fread(pStream, pElementSize, pElementCount, lFile) > 0 ;
182  fclose(lFile);
183  }
184 
185  return bResult;
186 }
187 
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
int type
Definition: node.h:20
bool Read(HIKFile pFile)
Definition: hikdump_std.inl:45
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