SMIL  0.9.1
DCommonIO.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _D_COMMON_IO_H
31 #define _D_COMMON_IO_H
32 
33 #include "Core/include/DErrors.h"
34 #include "Core/include/private/DImage.hpp"
35 
36 #include <cstdio>
37 
38 #ifdef _MSC_VER
39 #define SMIL_OPEN(FILEPTR, NAME, MODE) fopen_s(&FILEPTR, NAME, MODE)
40 #else // _MSC_VER
41 #define SMIL_OPEN(FILEPTR, NAME, MODE) FILEPTR = fopen(NAME, MODE)
42 #endif // _MSC_VER
43 
44 namespace smil
45 {
46 
51 
52  string getFileExtension(const char *fileName);
53 
54  class FileCloser
55  {
56  public:
57  FileCloser(FILE *_fp)
58  {
59  fp = _fp;
60  }
61  ~FileCloser()
62  {
63  if (fp)
64  fclose(fp);
65  }
66  protected:
67  FILE *fp;
68  };
69 
71  {
73  : colorType(COLOR_TYPE_UNKNOWN), scalarType(SCALAR_TYPE_UNKNOWN),
74  fileType(FILE_TYPE_BINARY),
75  width(0), height(0), depth(0),
76  dataStartPos(0)
77  {
78  }
79  enum ColorType { COLOR_TYPE_GRAY, COLOR_TYPE_RGB, COLOR_TYPE_GA, COLOR_TYPE_RGBA, COLOR_TYPE_BINARY, COLOR_TYPE_UNKNOWN };
80  enum ScalarType { SCALAR_TYPE_UINT8, SCALAR_TYPE_UINT16, SCALAR_TYPE_INT8, SCALAR_TYPE_INT16, SCALAR_TYPE_FLOAT, SCALAR_TYPE_DOUBLE, SCALAR_TYPE_UNKNOWN };
81  enum FileType { FILE_TYPE_ASCII, FILE_TYPE_BINARY };
82  UINT channels;
83  ColorType colorType;
84  ScalarType scalarType;
85  FileType fileType;
86  size_t width, height, depth;
87  streampos dataStartPos;
88  };
89 
90 
91  #ifdef USE_CURL
92 
93  RES_T getHttpFile(const char *url, const char *outfilename);
94  string getHttpFile(const char *url);
95 
96  #endif // USE_CURL
97 
99 } // namespace smil
100 
101 
102 
103 #endif // _D_COMMON_IO_H
Definition: DColorConvert.h:38
Definition: DCommonIO.h:54
string getHttpFile(const char *url)
Download file data into a string buffer.
Definition: DCommonIO.cpp:100
Definition: DCommonIO.h:70