Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NP_TMcode
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Giacomo Mulas
NP_TMcode
Commits
d8b92e8a
Commit
d8b92e8a
authored
10 months ago
by
Giovanni La Mura
Browse files
Options
Downloads
Patches
Plain Diff
Define VirtualAsciiFile class
parent
60678631
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/file_io.h
+46
-0
46 additions, 0 deletions
src/include/file_io.h
src/libnptm/file_io.cpp
+46
-0
46 additions, 0 deletions
src/libnptm/file_io.cpp
with
92 additions
and
0 deletions
src/include/file_io.h
+
46
−
0
View file @
d8b92e8a
...
...
@@ -5,6 +5,8 @@
#ifndef INCLUDE_FILE_IO_H_
#define INCLUDE_FILE_IO_H_
#include
<vector>
/*! \class FileSchema
*
* \brief File content descriptor.
...
...
@@ -156,4 +158,48 @@ class HDFFile {
hid_t
dapl_id
=
H5P_DEFAULT
,
hid_t
dxpl_id
=
H5P_DEFAULT
);
};
/*! \class VirtualAsciiFile
*
* \brief Virtual representation of an ASCII file.
*/
class
VirtualAsciiFile
{
protected:
//! \brief A vector of strings representing the file lines.
std
::
vector
<
std
::
string
>
*
file_lines
;
//! \brief The name of the file.
std
::
string
_file_name
;
public:
const
std
::
string
&
file_name
=
_file_name
;
/*! \brief VirtualAsciiFile instance constructor.
*
* \param name: `const string&` Reference to a string for the file name.
*/
VirtualAsciiFile
(
const
std
::
string
&
name
);
/*! \brief VirtualAsciiFile copy constructor.
*
* \param rhs: `const VirtualAsciiFile&` Reference to a VirtualAsciiFile instance.
* \param name: `const string&` Name of the copy (optional, default is the same as original).
*/
VirtualAsciiFile
(
const
VirtualAsciiFile
&
rhs
,
const
std
::
string
&
name
=
""
);
/*! \brief VirtualAsciiFile instance destroyer.
*/
~
VirtualAsciiFile
();
/*! \brief Append a line at the end of the file.
*
* \param line: `const string&` Reference to a string representing the line.
*/
void
append
(
const
std
::
string
&
line
);
/*! \brief Write virtual file contents to a real file on disk.
*
* \return result: `int` A result code (0 if successful).
*/
int
write_to_disk
();
};
#endif
This diff is collapsed.
Click to expand it.
src/libnptm/file_io.cpp
+
46
−
0
View file @
d8b92e8a
...
...
@@ -3,6 +3,7 @@
* \brief Implementation of file I/O operations.
*/
#include
<exception>
#include
<fstream>
#include
<regex>
#include
<string>
#include
<hdf5.h>
...
...
@@ -21,6 +22,7 @@
using
namespace
std
;
/* >>> FileSchema class implementation <<< */
FileSchema
::
FileSchema
(
int
num_rec
,
const
std
::
string
*
rec_types
,
const
std
::
string
*
rec_names
)
{
num_records
=
num_rec
;
record_types
=
new
string
[
num_rec
];
...
...
@@ -48,7 +50,9 @@ string* FileSchema::get_record_types() {
for
(
int
i
=
0
;
i
<
num_records
;
i
++
)
rec_types
[
i
]
=
record_types
[
i
];
return
rec_types
;
}
/* >>> End of FileSchema class implementation <<< */
/* >>> HDFFile class implementation <<< */
HDFFile
::
HDFFile
(
const
std
::
string
&
name
,
unsigned
int
flags
,
hid_t
fcpl_id
,
hid_t
fapl_id
)
{
file_name
=
name
;
if
(
flags
==
H5F_ACC_EXCL
||
flags
==
H5F_ACC_TRUNC
)
...
...
@@ -222,3 +226,45 @@ herr_t HDFFile::write(
}
return
status
;
}
/* >>> End of HDFFile class implementation <<< */
/* >>> VirtualAsciiFile class implementation <<< */
VirtualAsciiFile
::
VirtualAsciiFile
(
const
std
::
string
&
name
)
{
_file_name
=
name
;
_file_lines
=
new
vector
<
string
>
();
}
VirtualAsciiFile
::
VirtualAsciiFile
(
const
VirtualAsciiFile
&
rhs
,
const
std
::
string
&
name
)
{
if
(
name
.
compare
(
""
)
==
0
)
{
_file_name
=
rhs
.
_file_name
;
}
else
{
_file_name
=
name
;
}
_file_lines
=
new
vector
<
string
>
();
for
(
vector
<
string
>::
iterator
it
=
rhs
.
_file_lines
->
begin
();
it
!=
rhs
.
_file_lines
->
end
();
++
it
)
{
_file_lines
->
push_back
(
*
it
);
}
}
VirtualAsciiFile
::~
VirtualAsciiFile
()
{
if
(
_file_lines
!=
NULL
)
delete
_file_lines
;
}
void
VirtualAsciiFile
::
append
(
const
string
&
line
)
{
_file_lines
.
push_back
(
line
);
}
int
VirtualAsciiFile
::
write_to_disk
()
{
int
result
=
0
;
fstream
output_file
;
output_file
.
open
(
file_name
,
ios
::
out
);
if
(
output_file
.
is_open
())
{
for
(
vector
<
string
>::
iterator
it
=
_file_lines
->
begin
();
it
!=
_file_lines
->
end
();
++
it
)
{
output_file
<<
*
it
;
}
}
else
{
result
=
1
;
}
return
result
;
}
/* >>> End of VirtualAsciiFile class implementation <<< */
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