Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
old_macaon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Franck Dary
old_macaon
Commits
23f5481f
Commit
23f5481f
authored
Aug 3, 2018
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
Finished documentation for File
parent
9340683e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
maca_common/include/File.hpp
+62
-0
62 additions, 0 deletions
maca_common/include/File.hpp
with
62 additions
and
0 deletions
maca_common/include/File.hpp
+
62
−
0
View file @
23f5481f
/// @file File.hpp
/// @author Franck Dary
/// @version 1.0
/// @date 2018-08-03
#ifndef FILE__H
#ifndef FILE__H
#define FILE__H
#define FILE__H
...
@@ -7,39 +12,96 @@
...
@@ -7,39 +12,96 @@
#include
<functional>
#include
<functional>
#include
"util.hpp"
#include
"util.hpp"
/// @brief A class for opening and reading a file.
///
/// It can simply be seen as a wrapper for FILE *\n
/// It provides usefull functions and also permit to unget a large number of char
/// in a row, something that we can't do with FILE * alone.
class
File
class
File
{
{
public
:
public
:
/// @brief Instance of File wrapped around stdout.
static
File
stdOut
;
static
File
stdOut
;
private
:
private
:
/// @brief Construct a File from a FILE *
///
/// @param file Already opened file.
File
(
FILE
*
file
);
File
(
FILE
*
file
);
private
:
private
:
/// @brief Pointer to the file description.
FILE
*
file
;
FILE
*
file
;
/// @brief A buffer used to store char from ungetChar.
std
::
stack
<
char
>
buffer
;
std
::
stack
<
char
>
buffer
;
/// @brief Whether or not the whole file has been read.
bool
endHasBeenReached
;
bool
endHasBeenReached
;
/// @brief The filename, usefull for the rewind function.
std
::
string
filename
;
std
::
string
filename
;
public
:
public
:
/// @brief Construct and open a new file.
///
/// @param filename The filename of the file.
/// @param mode C's style opening mode. "r"ead or "w"rite.
File
(
const
std
::
string
&
filename
,
const
std
::
string
&
mode
);
File
(
const
std
::
string
&
filename
,
const
std
::
string
&
mode
);
/// @brief File is not moveable.
///
/// @param model
File
(
File
&&
model
)
=
delete
;
File
(
File
&&
model
)
=
delete
;
/// @brief File is not copyable.
///
/// @param model
///
/// @return
File
&
operator
=
(
const
File
&
model
)
=
delete
;
File
&
operator
=
(
const
File
&
model
)
=
delete
;
/// @brief The destructor, in which we close the file.
~
File
();
~
File
();
/// @brief Peek the next char in the file but without consuming it.
///
/// @return The next char in the file.
char
peek
();
char
peek
();
/// @brief Whether or not the whole file has been read.
///
/// @return Whether or not the whole file has been read.
bool
isFinished
();
bool
isFinished
();
/// @brief Get the next char in the file and consume it.
///
/// @return The next char in the file.
char
getChar
();
char
getChar
();
/// @brief Put back a char in the File.
/// It is not mandatory to use a char that was read from the file.\n
/// The next call the getChar will return c.\n
/// You can call ungetChar successively without problem.
/// @param c The char that will be pulled back.
void
ungetChar
(
char
c
);
void
ungetChar
(
char
c
);
/// @brief Return the underlying file descriptor.
/// This is usefull if you need to use fscanf or fprintf.
/// @return The file descriptor.
FILE
*
getDescriptor
();
FILE
*
getDescriptor
();
/// @brief Get the filename of the File.
///
/// @return The filename.
const
std
::
string
&
getName
();
const
std
::
string
&
getName
();
/// @brief Read the file until the character c is met.
/// The next call to getChar will return c.
/// @param c The character to read until.
void
readUntil
(
char
c
);
void
readUntil
(
char
c
);
/// @brief Read the file until the current character meets a condition.
/// The next call to condition(getChar()) will return true.
/// @param condition The condition the read char will have to meet.
void
readUntil
(
const
std
::
function
<
bool
(
char
)
>
&
condition
);
void
readUntil
(
const
std
::
function
<
bool
(
char
)
>
&
condition
);
/// @brief Read the file until the current character meets a condition.
/// The next call to condition(getChar()) will return true.
/// @param dest Where to store all the read characters.
/// @param condition The condition the read char will have to meet.
void
readUntil
(
std
::
string
&
dest
,
const
std
::
function
<
bool
(
char
)
>
&
condition
);
void
readUntil
(
std
::
string
&
dest
,
const
std
::
function
<
bool
(
char
)
>
&
condition
);
/// @brief Read the file again from the start, in "r"ead mode.
void
rewind
();
void
rewind
();
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment