libosmscout  1.1.1
FileWriter.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_FILEWRITER_H
2 #define OSMSCOUT_FILEWRITER_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2009 Tim Teulings
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include <cstdio>
24 #include <string>
25 #include <vector>
26 
28 
29 #include <osmscout/CoreFeatures.h>
30 
31 #include <osmscout/GeoCoord.h>
32 #include <osmscout/ObjectRef.h>
33 #include <osmscout/Point.h>
34 #include <osmscout/OSMScoutTypes.h>
35 
36 #include <osmscout/util/Color.h>
38 #include <osmscout/util/GeoBox.h>
39 
40 namespace osmscout {
41 
49  class OSMSCOUT_API FileWriter CLASS_FINAL
50  {
51  private:
52  std::string filename;
53  std::FILE *file;
54  bool hasError;
55  std::vector<int32_t> deltaBuffer;
56  std::vector<uint8_t> byteBuffer;
57 
58  public:
59  static const uint64_t MAX_NODES;
60 
61  public:
62  FileWriter();
63  ~FileWriter();
64 
65  void Open(const std::string& filename);
66  void Close();
67  void CloseFailsafe();
68  bool IsOpen() const
69  {
70  return file!=nullptr;
71  }
72 
73  bool HasError() const
74  {
75  return file==nullptr || hasError;
76  }
77 
78  std::string GetFilename() const;
79 
80  FileOffset GetPos();
81  void SetPos(FileOffset pos);
82  void GotoBegin();
83 
84  void Write(const char* buffer, size_t bytes);
85 
86  void Write(const std::string& value);
87 
88  void Write(bool boolean);
89 
90  void Write(int8_t number);
91  void Write(int16_t number);
92  void Write(int32_t number);
93  void Write(int64_t number);
94 
95  void Write(uint8_t number);
96  void Write(uint16_t number);
97  void Write(uint32_t number);
98  void Write(uint64_t number);
99 
100  void Write(uint16_t number, size_t bytes);
101  void Write(uint32_t number, size_t bytes);
102  void Write(uint64_t number, size_t bytes);
103 
104  void Write(const ObjectFileRef& ref);
105 
106  void Write(const MagnificationLevel& level)
107  {
108  Write(level.Get());
109  }
110 
111  void Write(const Color& color);
112 
113  void WriteFileOffset(FileOffset offset);
114  void WriteFileOffset(FileOffset offset,
115  size_t bytes);
116 
117  void WriteNumber(int16_t number);
118  void WriteNumber(int32_t number);
119  void WriteNumber(int64_t number);
120 
121  void WriteNumber(uint16_t number);
122  void WriteNumber(uint32_t number);
123  void WriteNumber(uint64_t number);
124 
125  void WriteNumber(const MagnificationLevel& level)
126  {
127  WriteNumber(level.Get());
128  }
129 
137  void WriteBox(const GeoBox &bbox);
138 
146  void WriteCoord(const GeoCoord& coord);
147  void WriteInvalidCoord();
148 
149  void Write(const std::vector<Point>& nodes, bool writeIds);
150  void Write(const std::vector<GeoCoord>& nodes);
151 
152  void WriteTypeId(TypeId id, uint8_t maxBytes);
153 
154  void Flush();
155  void FlushCurrentBlockWithZeros(size_t blockSize);
156  };
157 
158  extern OSMSCOUT_API bool IsValidToWrite(const std::vector<Point>& nodes);
159 
166  {
167  private:
168  FileWriter& writer;
169  FileOffset lastFileOffset;
170 
171  public:
172  explicit ObjectFileRefStreamWriter(FileWriter& writer);
173 
174  void Reset();
175 
176  void Write(const ObjectFileRef& ref);
177  };
178 }
179 
180 #endif
void Write(const MagnificationLevel &level)
Definition: FileWriter.h:106
void WriteNumber(const MagnificationLevel &level)
Definition: FileWriter.h:125
uint16_t TypeId
Definition: OSMScoutTypes.h:53
Definition: Area.h:38
OSMSCOUT_API bool IsValidToWrite(const std::vector< Point > &nodes)
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
static const uint64_t MAX_NODES
Definition: FileWriter.h:59
bool IsOpen() const
Definition: FileWriter.h:68
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
Definition: FileWriter.h:165
bool HasError() const
Definition: FileWriter.h:73