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;
40 /**----------------------------------------------------------------------------
41 \brief Contains methods for easily reading objects in an ascii stream
42 using set deliminators and line logic.
43 ----------------------------------------------------------------------------*/
45 {
46 public:
47 explicit Scanner(const File& file, char delimiter = '|', File::OpenMode mode = File::e_ascii_read);
48 explicit Scanner(const String& string, char delimiter = '|');
49 virtual ~Scanner();
50 void setDelimiter(char delimiter);
54 virtual bool nextLine();
55 virtual bool nextLine(String& string, bool clear_string = true);
56 const String& currentLine() const { return m_current_line; }
57 String& currentLine() { return m_current_line; }
58 const char* getCurrent() const;
59 void moveForward(uint04 distance = 1);
60 bool isComment(char comment) const;
63 bool skipTo(char location, bool ignore_case = false);
64 bool skipTo(const Buffer<char>& locations, bool ignore_case = false);
65 bool skipTo(const char* location, bool ignore_case = false);
68 void setHasDelimiter(const bool has_delimiter) { m_has_delimiter = has_delimiter; }
69 uint04& linePosition() { return m_cur_line_pos; }
70 void setQuoteCharacter(char quote_character) { m_quote_character = quote_character; }
71 char quoteCharacter() const { return m_quote_character; }
72 File file() const { return m_file; }
73 template<class t_type>
74 t_type getNext();
75
76 void getNext(String& next);
77
78 template<class t_type>
79 t_type getNextHex();
80
81 template<class t_type>
82 t_type getNext(uint04 count)
83 {
84 char* start = &m_current_line[m_cur_line_pos];
85 if (count == 0)
86 return String();
87 m_cur_line_pos += count;
88 return String(start, count).getAs<t_type>();
89 }
90 bool hasNext() const;
91
92 template<class t_type>
93 t_type getColumn(uint04 column)
94 {
95 if (m_cur_column > column)
96 {
97 m_cur_column = 0;
98 m_cur_line_pos = 0;
99 }
100
101 for (uint04 i = m_cur_column; i < column; i++)
102 skip();
103 return getNext<t_type>();
104 }
105
107
108 void setIgnoreEmptyLines(bool ignore_new_lines) { m_ignore_empty_lines = ignore_new_lines; }
109 void setIgnoreWhiteSpace(bool ignore_white_space) { m_ignore_white_space = ignore_white_space; }
110 virtual void setFilePosition(uint08 file_position, bool read_line = true);
111
113 {
114 return (uint01*)&m_current_line[m_cur_line_pos];
115 }
117 protected:
130 bool m_ignore_white_space = false;
132 };
133}
#define NDEVR_BASE_API
Definition DLLInfo.h:57
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
Logic for reading or writing to a file as well as navigating filesystems.
Definition File.h:48
OpenMode
Definition File.h:51
Contains methods for easily reading objects in an ascii stream.
Definition Scanner.h:45
const char * getCurrent() const
void getNext(String &next)
uint04 getLineLength() const
virtual uint01 * getByteArray()
Definition Scanner.h:112
fltp04 getFilePercent()
virtual void setFilePosition(uint08 file_position, bool read_line=true)
void setHasDelimiter(const bool has_delimiter)
Definition Scanner.h:68
Scanner(const File &file, char delimiter='|', File::OpenMode mode=File::e_ascii_read)
t_type getNextHex()
bool skipTo(const char *location, bool ignore_case=false)
uint08 m_current_file_position
Definition Scanner.h:122
String m_time_format
Definition Scanner.h:120
TranslatedString getDebugPosition() const
uint08 m_current_line_number
Definition Scanner.h:121
void moveForward(uint04 distance=1)
bool m_ignore_empty_lines
Definition Scanner.h:129
uint04 m_current_line_size
Definition Scanner.h:126
void setQuoteCharacter(char quote_character)
Definition Scanner.h:70
bool skipTo(char location, bool ignore_case=false)
uint08 dataSize() const
t_type getNext()
virtual ~Scanner()
bool isComment(char comment) const
uint08 m_data_size
Definition Scanner.h:123
void resetLinePosition()
uint04 & linePosition()
Definition Scanner.h:69
Scanner(const String &string, char delimiter='|')
void setDelimiter(char delimiter)
char m_delimiter
Definition Scanner.h:127
String m_current_line
Definition Scanner.h:118
void setIgnoreEmptyLines(bool ignore_new_lines)
Definition Scanner.h:108
bool skipTo(const Buffer< char > &locations, bool ignore_case=false)
char quoteCharacter() const
Definition Scanner.h:71
File file() const
Definition Scanner.h:72
File m_file
Definition Scanner.h:119
const String & currentLine() const
Definition Scanner.h:56
uint04 m_cur_line_pos
Definition Scanner.h:124
uint04 m_cur_column
Definition Scanner.h:125
void setIgnoreWhiteSpace(bool ignore_white_space)
Definition Scanner.h:109
virtual bool nextLine()
t_type getNext(uint04 count)
Definition Scanner.h:82
uint08 getCurrentLineNumber() const
uint08 getCurrentFilePosition()
virtual bool nextLine(String &string, bool clear_string=true)
t_type getColumn(uint04 column)
Definition Scanner.h:93
bool hasNext() const
char m_quote_character
Definition Scanner.h:128
String & currentLine()
Definition Scanner.h:57
uint04 skipWhiteSpace()
bool m_has_delimiter
Definition Scanner.h:131
The core String class for the NDEVR API.
Definition String.h:69
t_type getAs() const
Converts a string into an object. To use this function an object must have overwritten StringStream<t...
Definition String.h:143
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
Definition TranslatedString.h:13
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
Definition BaseValues.hpp:127
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96