dlgConfiguration: remove polar panel
[xcsoar.git] / src / IO / Source.hpp
blob17fdc966495420f33a8f22a957463036be77537f
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program 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
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_IO_SOURCE_HPP
25 #define XCSOAR_IO_SOURCE_HPP
27 #include "Compiler.h"
29 #include <utility>
31 /**
32 * A data source. This object provides a buffer, which may be
33 * modified in-place by the caller, to do zero-copy parsing.
35 template<class T>
36 class Source {
37 public:
38 /**
39 * A portion of this object's buffer. The first item is the start
40 * of the buffer, and the second item is the number of available
41 * words.
43 struct Range {
44 T *data;
46 unsigned length;
48 Range() = default;
50 constexpr
51 Range(T *_data, unsigned _length):data(_data), length(_length) {}
53 constexpr
54 bool IsEmpty() const {
55 return length == 0;
59 public:
60 virtual ~Source() {}
62 /**
63 * Returns words from this source. After you have used them, call
64 * the method consume(). This method Invalidates any range returned
65 * by a previous call.
67 * This object will always return as many words as possible; calling
68 * read() subsequently (without consume()) will not get you more
69 * data. An empty range marks the end of the stream.
71 virtual Range Read() = 0;
73 /**
74 * Marks words as "consumed". The buffer returned by read() is not
75 * yet Invalidated, and may be used until the next read() call is
76 * issued.
78 virtual void Consume(unsigned n) = 0;
80 /**
81 * Determins the size of the file. Returns -1 if the size is
82 * unknown.
84 gcc_pure
85 virtual long GetSize() const {
86 return -1;
89 /**
90 * Determins the current position within the file. Returns -1 if
91 * this is unknown.
93 gcc_pure
94 virtual long Tell() const {
95 return -1;
99 #endif