libosmscout 1.1.1
Loading...
Searching...
No Matches
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#include <osmscout/lib/CoreFeatures.h>
29
30#include <osmscout/GeoCoord.h>
31#include <osmscout/ObjectRef.h>
32#include <osmscout/Point.h>
34
35#include <osmscout/util/Color.h>
38
39namespace osmscout {
40
48 class OSMSCOUT_API FileWriter CLASS_FINAL
49 {
50 private:
51 std::string filename;
52 std::FILE *file=nullptr;
53 bool hasError=true;
54 std::vector<int32_t> deltaBuffer;
55 std::vector<uint8_t> byteBuffer;
56
57 public:
58 static const uint64_t MAX_NODES;
59
60 public:
61 FileWriter() = default;
63
64 void Open(const std::string& filename);
65 void Close();
67 bool IsOpen() const
68 {
69 return file!=nullptr;
70 }
71
72 bool HasError() const
73 {
74 return file==nullptr || hasError;
75 }
76
77 std::string GetFilename() const;
78
80 void SetPos(FileOffset pos);
81 void GotoBegin();
82
83 void Write(const char* buffer, size_t bytes);
84
85 void Write(const std::string& value);
86
87 void Write(bool boolean);
88
89 void Write(std::byte byteValue);
90
91 void Write(int8_t number);
92 void Write(int16_t number);
93 void Write(int32_t number);
94 void Write(int64_t number);
95
96 void Write(uint8_t number);
97 void Write(uint16_t number);
98 void Write(uint32_t number);
99 void Write(uint64_t number);
100
101 void Write(uint16_t number, size_t bytes);
102 void Write(uint32_t number, size_t bytes);
103 void Write(uint64_t number, size_t bytes);
104
105 void Write(const ObjectFileRef& ref);
106
107 void Write(const MagnificationLevel& level)
108 {
109 Write(level.Get());
110 }
111
112 void Write(const Color& color);
113
116 size_t bytes);
117
118 void WriteNumber(int16_t number);
119 void WriteNumber(int32_t number);
120 void WriteNumber(int64_t number);
121
122 void WriteNumber(uint16_t number);
123 void WriteNumber(uint32_t number);
124 void WriteNumber(uint64_t number);
125
127 {
128 WriteNumber(level.Get());
129 }
130
138 void WriteBox(const GeoBox &bbox);
139
149
150 void Write(const std::vector<Point>& nodes, bool writeIds);
151 void Write(const std::vector<GeoCoord>& nodes);
152
153 void WriteTypeId(TypeId id, uint8_t maxBytes);
154
155 void Flush();
156 void FlushCurrentBlockWithZeros(size_t blockSize);
157 };
158
159 extern OSMSCOUT_API bool IsValidToWrite(const std::vector<Point>& nodes);
160
167 {
168 private:
169 FileWriter& writer;
170 FileOffset lastFileOffset=0;
171
172 public:
173 explicit ObjectFileRefStreamWriter(FileWriter& writer);
174
175 void Reset();
176
177 void Write(const ObjectFileRef& ref);
178 };
179}
180
181#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
void FlushCurrentBlockWithZeros(size_t blockSize)
void WriteNumber(int32_t number)
const GeoCoord coord
Definition RouteStateAgent.h:49
void Write(int8_t number)
void Write(uint32_t number)
void Write(const std::vector< GeoCoord > &nodes)
void Open(const std::string &filename)
std::string GetFilename() const
bool HasError() const
Definition FileWriter.h:72
void Write(const Color &color)
void Write(uint16_t number, size_t bytes)
void WriteBox(const GeoBox &bbox)
std::vector< Point > nodes
List of nodes.
Definition Way.h:57
void WriteCoord(const GeoCoord &coord)
void Write(const char *buffer, size_t bytes)
void Write(const MagnificationLevel &level)
Definition FileWriter.h:107
void Write(const ObjectFileRef &ref)
void Write(uint16_t number)
void WriteNumber(uint64_t number)
void Write(const TypeConfig &typeConfig, FileWriter &writer) const
void Write(uint64_t number, size_t bytes)
bool IsOpen() const
Definition FileWriter.h:67
void WriteNumber(uint16_t number)
void Write(int32_t number)
void Write(int64_t number)
void Write(uint64_t number)
void WriteFileOffset(FileOffset offset)
void Write(const std::vector< Point > &nodes, bool writeIds)
void Write(uint8_t number)
void WriteNumber(uint32_t number)
void WriteNumber(int16_t number)
void Write(std::byte byteValue)
void WriteNumber(int64_t number)
void Write(int16_t number)
MagnificationLevel()=default
static const uint64_t MAX_NODES
Definition FileWriter.h:58
void WriteTypeId(TypeId id, uint8_t maxBytes)
void Write(uint32_t number, size_t bytes)
void WriteNumber(const MagnificationLevel &level)
Definition FileWriter.h:126
void WriteFileOffset(FileOffset offset, size_t bytes)
Vertex2D * buffer
Definition Transformation.h:343
void SetPos(FileOffset pos)
GeoBox bbox
Precomputed (cache) bounding box.
Definition DataAgent.h:53
void Write(bool boolean)
void Write(const std::string &value)
ObjectFileRefStreamWriter(FileWriter &writer)
void Write(const ObjectFileRef &ref)
uint16_t TypeId
Definition OSMScoutTypes.h:52
uint64_t FileOffset
Definition OSMScoutTypes.h:46
Definition Area.h:39
OSMSCOUT_API bool IsValidToWrite(const std::vector< Point > &nodes)