n2p2 - A neural network potential package
nnp::Log Class Reference

Logging class for library output. More...

#include <Log.h>

Collaboration diagram for nnp::Log:

Public Member Functions

 Log ()
 Constructor. More...
 
Logoperator<< (std::string const &entry)
 Overload << operator. More...
 
Logoperator<< (std::vector< std::string > const &entries)
 Overload << operator. More...
 
void addLogEntry (std::string const &entry)
 Add string as new log entry. More...
 
void addMultipleLogEntries (std::vector< std::string > const &entries)
 Add multiple log entries at once. More...
 
void registerCFilePointer (FILE **const &filePointer)
 Register new C-style FILE* pointer for output. More...
 
void registerStreamPointer (std::ofstream *const &streamPointer)
 Register new C++ ofstream pointer. More...
 
std::vector< std::string > getLog () const
 Get complete log memory. More...
 

Public Attributes

bool writeToStdout
 Turn on/off output to stdout. More...
 
bool silent
 Completely silence output. More...
 

Private Attributes

std::vector< std::string > memory
 Memory with all log entries. More...
 
std::vector< FILE ** > cFilePointers
 Storage for C-style FILE* pointers. More...
 
std::vector< std::ofstream * > streamPointers
 Storage for C++ ofstream pointers. More...
 

Detailed Description

Logging class for library output.

Log entries are saved in internal memory and may be redirected to multiple destinations: existing C-style FILE pointer or existing C++ stream.

Definition at line 33 of file Log.h.

Constructor & Destructor Documentation

◆ Log()

Log::Log ( )

Constructor.

Default output to stdout.

Definition at line 23 of file Log.cpp.

23 : writeToStdout(true ),
24 silent (false)
25{
26}
bool silent
Completely silence output.
Definition: Log.h:87
bool writeToStdout
Turn on/off output to stdout.
Definition: Log.h:85

Member Function Documentation

◆ operator<<() [1/2]

Log & Log::operator<< ( std::string const &  entry)

Overload << operator.

Parameters
[in]entryNew log entry.
Returns
Reference to log itself.

Definition at line 28 of file Log.cpp.

29{
30 addLogEntry(entry);
31 return *this;
32}
void addLogEntry(std::string const &entry)
Add string as new log entry.
Definition: Log.cpp:40

References addLogEntry().

Here is the call graph for this function:

◆ operator<<() [2/2]

Log & Log::operator<< ( std::vector< std::string > const &  entries)

Overload << operator.

Parameters
[in]entriesVector with log entries.
Returns
Reference to log itself.

Definition at line 34 of file Log.cpp.

35{
36 addMultipleLogEntries(entries);
37 return *this;
38}
void addMultipleLogEntries(std::vector< std::string > const &entries)
Add multiple log entries at once.
Definition: Log.cpp:74

References addMultipleLogEntries().

Here is the call graph for this function:

◆ addLogEntry()

void Log::addLogEntry ( std::string const &  entry)

Add string as new log entry.

Parameters
[in]entryNew log entry.

Definition at line 40 of file Log.cpp.

41{
42 if (silent) return;
43 memory.push_back(entry);
44
45 if (writeToStdout)
46 {
47 cout << entry;
48 cout.flush();
49 }
50
51 for (vector<FILE**>::const_iterator it = cFilePointers.begin();
52 it != cFilePointers.end(); ++it)
53 {
54 if ((**it) != 0)
55 {
56 fprintf((**it), "%s", entry.c_str());
57 fflush((**it));
58 }
59 }
60
61 for (vector<ofstream*>::const_iterator it = streamPointers.begin();
62 it != streamPointers.end(); ++it)
63 {
64 if ((**it).is_open())
65 {
66 (**it) << entry;
67 (**it).flush();
68 }
69 }
70
71 return;
72}
std::vector< std::string > memory
Memory with all log entries.
Definition: Log.h:91
std::vector< FILE ** > cFilePointers
Storage for C-style FILE* pointers.
Definition: Log.h:93
std::vector< std::ofstream * > streamPointers
Storage for C++ ofstream pointers.
Definition: Log.h:95

References cFilePointers, memory, silent, streamPointers, and writeToStdout.

Referenced by addMultipleLogEntries(), and operator<<().

Here is the caller graph for this function:

◆ addMultipleLogEntries()

void Log::addMultipleLogEntries ( std::vector< std::string > const &  entries)

Add multiple log entries at once.

Parameters
[in]entriesVector with log entries.

Definition at line 74 of file Log.cpp.

75{
76 for (vector<string>::const_iterator it = entries.begin();
77 it != entries.end(); ++it)
78 {
79 addLogEntry(*it);
80 }
81
82 return;
83}

References addLogEntry().

Referenced by operator<<().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerCFilePointer()

void Log::registerCFilePointer ( FILE **const &  filePointer)

Register new C-style FILE* pointer for output.

Parameters
[in]filePointerAddress of C-style file pointer (FILE*).

Definition at line 85 of file Log.cpp.

86{
87 cFilePointers.push_back(filePointer);
88 return;
89}

References cFilePointers.

Referenced by LAMMPS_NS::PairHDNNP::init_style().

Here is the caller graph for this function:

◆ registerStreamPointer()

void Log::registerStreamPointer ( std::ofstream *const &  streamPointer)

Register new C++ ofstream pointer.

Parameters
[in]streamPointerAddress of C++ ofstream pointer.

Definition at line 91 of file Log.cpp.

92{
93 streamPointers.push_back(streamPointer);
94 return;
95}

References streamPointers.

Referenced by main().

Here is the caller graph for this function:

◆ getLog()

vector< string > Log::getLog ( ) const

Get complete log memory.

Returns
Log memory.

Definition at line 97 of file Log.cpp.

98{
99 return memory;
100}

References memory.

Member Data Documentation

◆ writeToStdout

bool nnp::Log::writeToStdout

Turn on/off output to stdout.

Definition at line 85 of file Log.h.

Referenced by addLogEntry(), nnp::InterfaceLammps::initialize(), and main().

◆ silent

bool nnp::Log::silent

Completely silence output.

Definition at line 87 of file Log.h.

Referenced by addLogEntry(), and nnp::Training::dataSetNormalization().

◆ memory

std::vector<std::string> nnp::Log::memory
private

Memory with all log entries.

Definition at line 91 of file Log.h.

Referenced by addLogEntry(), and getLog().

◆ cFilePointers

std::vector<FILE**> nnp::Log::cFilePointers
private

Storage for C-style FILE* pointers.

Definition at line 93 of file Log.h.

Referenced by addLogEntry(), and registerCFilePointer().

◆ streamPointers

std::vector<std::ofstream*> nnp::Log::streamPointers
private

Storage for C++ ofstream pointers.

Definition at line 95 of file Log.h.

Referenced by addLogEntry(), and registerStreamPointer().


The documentation for this class was generated from the following files: