rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
stdin_get_contents()

Load a file from stdin (or similar stream-like file) into a buffer. More...

Functions

template<class ContiguousContainer>
void c4::yml::stdin_get_contents (ContiguousContainer *cont, FILE *f=stdin)
 load a file from stdin (or similar stream-like file) and return a newly created ContiguousContainer with the file contents
template<class ContiguousContainer>
ContiguousContainer c4::yml::stdin_get_contents (FILE *f=stdin)
 load a file from stdin and return a newly created ContiguousContainer with the file contents

Detailed Description

Load a file from stdin (or similar stream-like file) into a buffer.

Function Documentation

◆ stdin_get_contents() [1/2]

template<class ContiguousContainer>
void c4::yml::stdin_get_contents ( ContiguousContainer * cont,
FILE * f = stdin )

load a file from stdin (or similar stream-like file) and return a newly created ContiguousContainer with the file contents

Definition at line 178 of file file.hpp.

179{
180 using I = typename ContiguousContainer::size_type;
181 using T = typename ContiguousContainer::value_type;
182 int c;
183 I pos = 0;
184 I num_bytes = 128;
185 I elmsz = static_cast<I>(sizeof(T));
186 I sz = (num_bytes + elmsz - 1) / elmsz; // round up to next multiple of elmsz
187 num_bytes = sz * elmsz;
188 cont->resize(sz);
189 unsigned char *buf = reinterpret_cast<unsigned char*>(&(*cont)[0]); // NOLINT
190 while((c = fgetc(f)) != EOF)
191 {
192 if(pos == num_bytes)
193 {
194 num_bytes = 2 * num_bytes;
195 if(num_bytes % sizeof(T)) goto errsize; // NOLINT // LCOV_EXCL_LINE
196 cont->resize(num_bytes / sizeof(T));
197 buf = reinterpret_cast<unsigned char*>(&(*cont)[0]); // NOLINT
198 }
199 buf[pos++] = static_cast<unsigned char>(c);
200 }
201 if(pos % sizeof(T))
202 goto errsize; // NOLINT
203 cont->resize(pos / sizeof(T));
204 return;
205errsize:
206 _RYML_ERR_BASIC("file size is not multiple of element size");
207}

◆ stdin_get_contents() [2/2]

template<class ContiguousContainer>
ContiguousContainer c4::yml::stdin_get_contents ( FILE * f = stdin)

load a file from stdin and return a newly created ContiguousContainer with the file contents

Definition at line 212 of file file.hpp.

213{
214 ContiguousContainer cc;
215 stdin_get_contents(&cc, f);
216 return cc;
217}
void stdin_get_contents(ContiguousContainer *cont, FILE *f=stdin)
load a file from stdin (or similar stream-like file) and return a newly created ContiguousContainer w...
Definition file.hpp:178