API Documentation
Loading...
Searching...
No Matches
Scanner.h
Go to the documentation of this file.
1/**--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Scanner
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/File.h>
35#include <NDEVR/String.h>
36
37namespace NDEVR
38{
39 class TranslatedString;
41 {
42 public:
43 explicit Scanner(const File& file, char delimiter = '|', File::OpenMode mode = File::e_ascii_read);
44 explicit Scanner(const String& string, char delimiter = '|');
45 virtual ~Scanner();
46 void setDelimiter(char delimiter);
47 uint08 getCurrentLineNumber() const;
48 uint08 getCurrentFilePosition();
49 fltp04 getFilePercent();
50 virtual bool nextLine();
51 virtual bool nextLine(String& string, bool clear_string = true);
52 const String& currentLine() const { return m_current_line; }
53 String& currentLine() { return m_current_line; }
54 const char* getCurrent() const;
55 void moveForward(uint04 distance = 1);
56 bool isComment(char comment) const;
57 uint04 getLineLength() const;
58 uint04 skip();
59 bool skipTo(char location, bool ignore_case = false);
60 bool skipTo(const Buffer<char>& locations, bool ignore_case = false);
61 bool skipTo(const char* location, bool ignore_case = false);
62 uint04 skipWhiteSpace();
63 void resetLinePosition();
64 void setHasDelimiter(const bool has_delimiter) { m_has_delimiter = has_delimiter; }
65 uint04& linePosition() { return m_cur_line_pos; }
66 void setQuoteCharacter(char quote_character) { m_quote_character = quote_character; }
67 char quoteCharacter() const { return m_quote_character; }
68 File file() const { return m_file; }
69 template<class t_type>
70 t_type getNext();
71
72 void getNext(String& next);
73
74 template<class t_type>
75 t_type getNextHex();
76
77 template<class t_type>
78 t_type getNext(uint04 count)
79 {
80 char* start = &m_current_line[m_cur_line_pos];
81 if (count == 0)
82 return String();
83 m_cur_line_pos += count;
84 return String(start, count).getAs<t_type>();
85 }
86 bool hasNext() const;
87
88 template<class t_type>
89 t_type getColumn(uint04 column)
90 {
91 if (m_cur_column > column)
92 {
93 m_cur_column = 0;
94 m_cur_line_pos = 0;
95 }
96
97 for (uint04 i = m_cur_column; i < column; i++)
98 skip();
99 return getNext<t_type>();
100 }
101
102 TranslatedString getDebugPosition() const;
103
104 void setIgnoreEmptyLines(bool ignore_new_lines) { m_ignore_empty_lines = ignore_new_lines; }
105 void setIgnoreWhiteSpace(bool ignore_white_space) { m_ignore_white_space = ignore_white_space; }
106 virtual void setFilePosition(uint08 file_position, bool read_line = true);
107
109 {
110 return (uint01*)&m_current_line[m_cur_line_pos];
111 }
112 uint08 dataSize() const;
113 protected:
126 bool m_ignore_white_space = false;
128 };
129}
#define NDEVR_BASE_API
Definition DLLInfo.h:78
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition File.h:47
OpenMode
Definition File.h:50
Definition Scanner.h:41
virtual uint01 * getByteArray()
Definition Scanner.h:108
void setHasDelimiter(const bool has_delimiter)
Definition Scanner.h:64
t_type getNextHex()
uint08 m_current_file_position
Definition Scanner.h:118
String m_time_format
Definition Scanner.h:116
uint08 m_current_line_number
Definition Scanner.h:117
bool m_ignore_empty_lines
Definition Scanner.h:125
uint04 m_current_line_size
Definition Scanner.h:122
void setQuoteCharacter(char quote_character)
Definition Scanner.h:66
t_type getNext()
uint08 m_data_size
Definition Scanner.h:119
uint04 & linePosition()
Definition Scanner.h:65
char m_delimiter
Definition Scanner.h:123
String m_current_line
Definition Scanner.h:114
void setIgnoreEmptyLines(bool ignore_new_lines)
Definition Scanner.h:104
char quoteCharacter() const
Definition Scanner.h:67
File file() const
Definition Scanner.h:68
File m_file
Definition Scanner.h:115
const String & currentLine() const
Definition Scanner.h:52
uint04 m_cur_line_pos
Definition Scanner.h:120
uint04 m_cur_column
Definition Scanner.h:121
void setIgnoreWhiteSpace(bool ignore_white_space)
Definition Scanner.h:105
t_type getNext(uint04 count)
Definition Scanner.h:78
t_type getColumn(uint04 column)
Definition Scanner.h:89
char m_quote_character
Definition Scanner.h:124
String & currentLine()
Definition Scanner.h:53
bool m_has_delimiter
Definition Scanner.h:127
Definition String.h:40
t_type getAs() const
Definition String.h:334
Definition TranslatedString.h:9
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer -Can represent exact integer values 0 thro...
Definition BaseValues.hpp:132
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120