Vector Optimized Library of Kernels  2.5.0
Architecture-tuned implementations of math kernels
stack_line_reader.h
Go to the documentation of this file.
1 // Copyright 2017 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Reads a file line by line and stores the data on the stack. This allows
16 // parsing files in one go without allocating.
17 #ifndef CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_
18 #define CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_
19 
20 #include <stdbool.h>
21 
22 #include "cpu_features_macros.h"
23 #include "internal/string_view.h"
24 
26 
27 typedef struct {
28  char buffer[STACK_LINE_READER_BUFFER_SIZE];
30  int fd;
31  bool skip_mode;
33 
34 // Initializes a StackLineReader.
35 void StackLineReader_Initialize(StackLineReader* reader, int fd);
36 
37 typedef struct {
38  StringView line; // A view of the line.
39  bool eof; // Nothing more to read, we reached EOF.
40  bool full_line; // If false the line was truncated to
41  // STACK_LINE_READER_BUFFER_SIZE.
42 } LineResult;
43 
44 // Reads the file pointed to by fd and tries to read a full line.
46 
48 
49 #endif // CPU_FEATURES_INCLUDE_INTERNAL_STACK_LINE_READER_H_
#define CPU_FEATURES_START_CPP_NAMESPACE
Definition: cpu_features_macros.h:114
#define CPU_FEATURES_END_CPP_NAMESPACE
Definition: cpu_features_macros.h:115
LineResult StackLineReader_NextLine(StackLineReader *reader)
Definition: stack_line_reader.c:104
void StackLineReader_Initialize(StackLineReader *reader, int fd)
Definition: stack_line_reader.c:23
Definition: stack_line_reader.h:37
bool eof
Definition: stack_line_reader.h:39
StringView line
Definition: stack_line_reader.h:38
bool full_line
Definition: stack_line_reader.h:40
Definition: stack_line_reader.h:27
StringView view
Definition: stack_line_reader.h:29
int fd
Definition: stack_line_reader.h:30
bool skip_mode
Definition: stack_line_reader.h:31
Definition: string_view.h:27