MoorDyn
Public Member Functions | Protected Member Functions | List of all members
moordyn::io::IO Class Referenceabstract

A base class for all the entities that must save/load data to/from disk. More...

#include <IO.hpp>

Inheritance diagram for moordyn::io::IO:
Inheritance graph
[legend]
Collaboration diagram for moordyn::io::IO:
Collaboration graph
[legend]

Public Member Functions

 IO (moordyn::Log *log)
 Costructor. More...
 
virtual ~IO ()=default
 Destructor.
 
void Save (const std::string filepath)
 Save the entity into a file. More...
 
void Load (const std::string filepath)
 Loads the entity from a file. More...
 
virtual std::vector< uint64_t > Serialize (void)=0
 Produce the packed data to be saved. More...
 
virtual uint64_t * Deserialize (const uint64_t *data)=0
 Unpack the data to restore the Serialized information. More...
 
- Public Member Functions inherited from moordyn::LogUser
 LogUser (Log *log=NULL)
 Constructor. More...
 
 ~LogUser ()
 Destructor.
 
void SetLogger (Log *log)
 Set the log handler. More...
 
LogGetLogger () const
 Get the log handler. More...
 

Protected Member Functions

ofstream MakeFile (const std::string filepath) const
 Create an output file and write the MoorDyn magic header. More...
 
std::tuple< uint64_t, uint64_t * > LoadFile (const std::string filepath) const
 Open an input file and load the data. More...
 
uint64_t Serialize (const uint64_t &i)
 Pack an unsigned integer to make it writable. More...
 
uint64_t Serialize (const int64_t &i)
 Pack an integer to make it writable. More...
 
uint64_t Serialize (const real &f)
 Pack a float to make it writable. More...
 
std::vector< uint64_t > Serialize (const vec &m)
 Pack a 3D vector to make it writable. More...
 
std::vector< uint64_t > Serialize (const vec6 &m)
 Pack a 6D vector to make it writable. More...
 
std::vector< uint64_t > Serialize (const mat &m)
 Pack a 3x3 matrix to make it writable. More...
 
std::vector< uint64_t > Serialize (const mat6 &m)
 Pack a 6x6 matrix to make it writable. More...
 
std::vector< uint64_t > Serialize (const quaternion &m)
 Pack a quaternion to make it writable. More...
 
std::vector< uint64_t > Serialize (const XYZQuat &m)
 Pack an XYZQuat to make it writable. More...
 
std::vector< uint64_t > Serialize (const std::vector< real > &l)
 Pack a list of floating point numbers to make it writable. More...
 
std::vector< uint64_t > Serialize (const std::vector< vec > &l)
 Pack a list of 3D vectors to make it writable. More...
 
std::vector< uint64_t > Serialize (const std::vector< vec6 > &l)
 Pack a list of 6D vectors to make it writable. More...
 
std::vector< uint64_t > Serialize (const std::vector< mat > &l)
 Pack a list of 3x3 matrices to make it writable. More...
 
std::vector< uint64_t > Serialize (const std::vector< mat6 > &l)
 Pack a list of 6x6 matrices to make it writable. More...
 
std::vector< uint64_t > Serialize (const Eigen::Matrix< real, Eigen::Dynamic, Eigen::Dynamic > &l)
 Pack an arbitrarily large matrix. More...
 
template<typename T >
std::vector< uint64_t > Serialize (const std::vector< std::vector< T >> &l)
 Pack a list of lists to make it writable This function might act recursively. More...
 
uint64_t * Deserialize (const uint64_t *in, uint64_t &out)
 Unpack a loaded unsigned integer. More...
 
uint64_t * Deserialize (const uint64_t *in, int64_t &out)
 Unpack a loaded integer. More...
 
uint64_t * Deserialize (const uint64_t *in, real &out)
 Unpack a loaded floating point number. More...
 
uint64_t * Deserialize (const uint64_t *in, vec &out)
 Unpack a loaded 3D vector. More...
 
uint64_t * Deserialize (const uint64_t *in, vec6 &out)
 Unpack a loaded 6D vector. More...
 
uint64_t * Deserialize (const uint64_t *in, mat &out)
 Unpack a loaded 3x3 matrix. More...
 
uint64_t * Deserialize (const uint64_t *in, mat6 &out)
 Unpack a loaded 6x6 matrix. More...
 
uint64_t * Deserialize (const uint64_t *in, quaternion &out)
 Unpack a loaded quaternion. More...
 
uint64_t * Deserialize (const uint64_t *in, XYZQuat &out)
 Unpack a loaded XYZQuat. More...
 
uint64_t * Deserialize (const uint64_t *in, std::vector< real > &out)
 Unpack a loaded list of floating point numbers. More...
 
uint64_t * Deserialize (const uint64_t *in, std::vector< vec > &out)
 Unpack a loaded list of 3D vectors. More...
 
uint64_t * Deserialize (const uint64_t *in, std::vector< vec6 > &out)
 Unpack a loaded list of 6D vectors. More...
 
uint64_t * Deserialize (const uint64_t *in, std::vector< mat > &out)
 Unpack a loaded list of 3x3 matrices. More...
 
uint64_t * Deserialize (const uint64_t *in, std::vector< mat6 > &out)
 Unpack a loaded list of 6x6 matrices. More...
 
uint64_t * Deserialize (const uint64_t *in, Eigen::Matrix< real, Eigen::Dynamic, Eigen::Dynamic > &out)
 Unpack an arbitrarily large matrix. More...
 
template<typename T >
uint64_t * Deserialize (const uint64_t *in, std::vector< std::vector< T >> &out)
 Unpack a loaded list of lists. More...
 

Additional Inherited Members

- Protected Attributes inherited from moordyn::LogUser
Log_log
 The log handler.
 

Detailed Description

A base class for all the entities that must save/load data to/from disk.

Note
Since this class already publicly inherits moordyn::LogUser, all the classes inheriting this class do not require inheriting also LogUser

Constructor & Destructor Documentation

◆ IO()

moordyn::io::IO::IO ( moordyn::Log log)

Costructor.

Parameters
logLogging handler

Member Function Documentation

◆ Deserialize() [1/17]

virtual uint64_t* moordyn::io::IO::Deserialize ( const uint64_t *  data)
pure virtual

Unpack the data to restore the Serialized information.

This is the function that each inherited class must implement, and should be the inverse of Serialize(void)

Parameters
dataThe packed data
Returns
A pointer to the end of the file, for debugging purposes

Implemented in moordyn::time::ABScheme< order, local >, moordyn::time::SchemeBase< NSTATE, NDERIV >, moordyn::time::SchemeBase< 2, 2 >, moordyn::time::SchemeBase< 1, 2 >, moordyn::time::SchemeBase< 2, 1 >, moordyn::time::SchemeBase< 1, 1 >, moordyn::time::SchemeBase< 5, 4 >, moordyn::state::State, moordyn::Rod, moordyn::Point, moordyn::MoorDyn, moordyn::Line, and moordyn::Body.

Here is the caller graph for this function:

◆ Deserialize() [2/17]

uint64_t* moordyn::io::IO::Deserialize ( const uint64_t *  in,
Eigen::Matrix< real, Eigen::Dynamic, Eigen::Dynamic > &  out 
)
inlineprotected

Unpack an arbitrarily large matrix.

Parameters
inThe pointer to the next unread value
outThe unpacked vector
Returns
The new pointer to the remaining data to be read

◆ Deserialize() [3/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
int64_t &  out 
)
protected

Unpack a loaded integer.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [4/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
mat out 
)
protected

Unpack a loaded 3x3 matrix.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [5/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
mat6 out 
)
protected

Unpack a loaded 6x6 matrix.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [6/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
quaternion out 
)
protected

Unpack a loaded quaternion.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [7/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
real out 
)
protected

Unpack a loaded floating point number.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [8/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
std::vector< mat > &  out 
)
protected

Unpack a loaded list of 3x3 matrices.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [9/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
std::vector< mat6 > &  out 
)
protected

Unpack a loaded list of 6x6 matrices.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [10/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
std::vector< real > &  out 
)
protected

Unpack a loaded list of floating point numbers.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [11/17]

template<typename T >
uint64_t* moordyn::io::IO::Deserialize ( const uint64_t *  in,
std::vector< std::vector< T >> &  out 
)
inlineprotected

Unpack a loaded list of lists.

This function might works recursively

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read

◆ Deserialize() [12/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
std::vector< vec > &  out 
)
protected

Unpack a loaded list of 3D vectors.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [13/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
std::vector< vec6 > &  out 
)
protected

Unpack a loaded list of 6D vectors.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [14/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
uint64_t &  out 
)
protected

Unpack a loaded unsigned integer.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read

◆ Deserialize() [15/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
vec out 
)
protected

Unpack a loaded 3D vector.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [16/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
vec6 out 
)
protected

Unpack a loaded 6D vector.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Deserialize() [17/17]

uint64_t * moordyn::io::IO::Deserialize ( const uint64_t *  in,
XYZQuat out 
)
protected

Unpack a loaded XYZQuat.

Parameters
inThe pointer to the next unread value
outThe unpacked value
Returns
The new pointer to the remaining data to be read
Here is the call graph for this function:

◆ Load()

void moordyn::io::IO::Load ( const std::string  filepath)

Loads the entity from a file.

It is the inverse of Save(filepath)

Parameters
filepathThe output file path
Here is the call graph for this function:

◆ LoadFile()

std::tuple< uint64_t, uint64_t * > moordyn::io::IO::LoadFile ( const std::string  filepath) const
protected

Open an input file and load the data.

Parameters
filepathThe input file path
Returns
the size of the data into the file and the allocated memory with the data inside. Remember to call free() on the returned pointer
Here is the caller graph for this function:

◆ MakeFile()

ofstream moordyn::io::IO::MakeFile ( const std::string  filepath) const
protected

Create an output file and write the MoorDyn magic header.

Parameters
filepathThe output file path
Here is the caller graph for this function:

◆ Save()

void moordyn::io::IO::Save ( const std::string  filepath)

Save the entity into a file.

It is of course possible to save each entity in a separate file. However, since this function is just redirecting the work to save(void), which might produce the data to save recursively, actually the whole system can be saved in the same file

Parameters
filepathThe output file path
Here is the call graph for this function:

◆ Serialize() [1/17]

std::vector<uint64_t> moordyn::io::IO::Serialize ( const Eigen::Matrix< real, Eigen::Dynamic, Eigen::Dynamic > &  l)
inlineprotected

Pack an arbitrarily large matrix.

Parameters
lThe matrix
Returns
The packed list

◆ Serialize() [2/17]

uint64_t moordyn::io::IO::Serialize ( const int64_t &  i)
protected

Pack an integer to make it writable.

Parameters
iThe integer number
Returns
The packed number
Here is the call graph for this function:

◆ Serialize() [3/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const mat m)
protected

Pack a 3x3 matrix to make it writable.

Parameters
mThe matrix
Returns
The packed matrix
Here is the call graph for this function:

◆ Serialize() [4/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const mat6 m)
protected

Pack a 6x6 matrix to make it writable.

Parameters
mThe matrix
Returns
The packed matrix
Here is the call graph for this function:

◆ Serialize() [5/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const quaternion m)
protected

Pack a quaternion to make it writable.

Parameters
mThe quaternion
Returns
The packed quaternion
Here is the call graph for this function:

◆ Serialize() [6/17]

uint64_t moordyn::io::IO::Serialize ( const real f)
protected

Pack a float to make it writable.

Parameters
fThe float number
Returns
The packed number
Here is the call graph for this function:

◆ Serialize() [7/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const std::vector< mat > &  l)
protected

Pack a list of 3x3 matrices to make it writable.

Parameters
lThe list
Returns
The packed list
Here is the call graph for this function:

◆ Serialize() [8/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const std::vector< mat6 > &  l)
protected

Pack a list of 6x6 matrices to make it writable.

Parameters
lThe list
Returns
The packed list
Here is the call graph for this function:

◆ Serialize() [9/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const std::vector< real > &  l)
protected

Pack a list of floating point numbers to make it writable.

Parameters
lThe list
Returns
The packed list
Here is the call graph for this function:

◆ Serialize() [10/17]

template<typename T >
std::vector<uint64_t> moordyn::io::IO::Serialize ( const std::vector< std::vector< T >> &  l)
inlineprotected

Pack a list of lists to make it writable This function might act recursively.

Parameters
lThe list
Returns
The packed list

◆ Serialize() [11/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const std::vector< vec > &  l)
protected

Pack a list of 3D vectors to make it writable.

Parameters
lThe list
Returns
The packed list
Here is the call graph for this function:

◆ Serialize() [12/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const std::vector< vec6 > &  l)
protected

Pack a list of 6D vectors to make it writable.

Parameters
lThe list
Returns
The packed list
Here is the call graph for this function:

◆ Serialize() [13/17]

uint64_t moordyn::io::IO::Serialize ( const uint64_t &  i)
protected

Pack an unsigned integer to make it writable.

Parameters
iThe unsigned integer number
Returns
The packed number

◆ Serialize() [14/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const vec m)
protected

Pack a 3D vector to make it writable.

Parameters
mThe matrix
Returns
The packed matrix
Here is the call graph for this function:

◆ Serialize() [15/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const vec6 m)
protected

Pack a 6D vector to make it writable.

Parameters
mThe matrix
Returns
The packed matrix
Here is the call graph for this function:

◆ Serialize() [16/17]

std::vector< uint64_t > moordyn::io::IO::Serialize ( const XYZQuat m)
protected

Pack an XYZQuat to make it writable.

Parameters
mThe XYZQuat
Returns
The packed XYZQuat
Here is the call graph for this function:

◆ Serialize() [17/17]

virtual std::vector<uint64_t> moordyn::io::IO::Serialize ( void  )
pure virtual

Produce the packed data to be saved.

The produced data can be used afterwards to restore the saved information afterwards calling Deserialize(void).

This is the function that each inherited class must implement

Returns
The packed data

Implemented in moordyn::time::ABScheme< order, local >, moordyn::time::SchemeBase< NSTATE, NDERIV >, moordyn::time::SchemeBase< 2, 2 >, moordyn::time::SchemeBase< 1, 2 >, moordyn::time::SchemeBase< 2, 1 >, moordyn::time::SchemeBase< 1, 1 >, moordyn::time::SchemeBase< 5, 4 >, moordyn::state::State, moordyn::Rod, moordyn::Point, moordyn::MoorDyn, moordyn::Line, and moordyn::Body.

Here is the caller graph for this function:

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