Concore.hpp
-
class Concore
Class representing the Concore implementation in C++.
Public Functions
-
inline Concore()
Constructor for Concore class. Initializes the iport and oport maps by parsing the respective files. It also creates or attaches to the shared memory segment if required.
-
inline ~Concore()
Destructor for Concore class. Detaches and removes the shared memory segment if shared memory created.
-
inline key_t ExtractNumeric(const std::string &str)
Extracts the numeric part from a string.
- Parameters:
str – The input string.
- Returns:
The numeric part of the string. Returns -1 if the string does not contain a numeric part.
Creates a shared memory segment with the given key.
- Parameters:
key – The key for the shared memory segment.
Retrieves an existing shared memory segment with the given key. Waits until the shared memory segment is created by the writer process.
- Parameters:
key – The key for the shared memory segment.
-
inline map<string, int> mapParser(string filename)
Parses a file containing port and number mappings and returns a map of the values.
- Parameters:
filename – The name of the file to parse.
- Returns:
A map of port names and their corresponding numbers.
-
inline bool unchanged()
function to compare and determine whether file content has been changed.
- Returns:
true if the content has not changed, false otherwise.
-
inline vector<double> parser(string f)
Parses a string and extracts a vector of double values.
- Parameters:
f – The input string to parse.
- Returns:
A vector of double values extracted from the input string.
-
inline vector<double> read(int port, string name, string initstr)
deviate the read to either the SM (Shared Memory) or FM (File Method) communication protocol based on iport and oport.
- Parameters:
port – The port number.
name – The name of the file.
initstr – The initial string
- Returns:
-
inline vector<double> read_FM(int port, string name, string initstr)
Reads data from a specified port and name using the FM (File Method) communication protocol.
- Parameters:
port – The port number.
name – The name of the file.
initstr – The initial string.
- Returns:
a string of file content
-
inline vector<double> read_SM(int port, string name, string initstr)
Reads data from the shared memory segment based on the specified port and name.
- Parameters:
port – The port number.
name – The name of the file.
initstr – The initial string to use if the shared memory is not found.
- Returns:
string of file content
-
inline void write(int port, string name, vector<double> val, int delta = 0)
deviate the write to either the SM (Shared Memory) or FM (File Method) communication protocol based on iport and oport.
- Parameters:
port – The port number.
name – The name of the file.
val – The vector of double values to write.
delta – The delta value (default: 0).
-
inline void write(int port, string name, string val, int delta = 0)
deviate the write to either the SM (Shared Memory) or FM (File Method) communication protocol based on iport and oport.
- Parameters:
port – The port number.
name – The name of the file.
val – The string to write.
delta – The delta value (default: 0).
-
inline void write_FM(int port, string name, vector<double> val, int delta = 0)
write method, accepts a vector double and writes it to the file
- Parameters:
port – The port number.
name – The name of the file.
val – The string to write.
delta – The delta value (default: 0).
-
inline void write_FM(int port, string name, string val, int delta = 0)
write method, accepts a string and writes it to the file
- Parameters:
port – The port number.
name – The name of the file.
val – The string to write.
delta – The delta value (default: 0).
-
inline void write_SM(int port, string name, vector<double> val, int delta = 0)
Writes a vector of double values to the shared memory segment based on the specified port and name.
- Parameters:
port – The port number.
name – The name of the file.
val – The vector of double values to write.
delta – The delta value (default: 0).
-
inline void write_SM(int port, string name, string val, int delta = 0)
Writes a string to the shared memory segment based on the specified port and name.
- Parameters:
port – The port number.
name – The name of the file.
val – The string to write.
delta – The delta value (default: 0).
-
inline vector<double> initval(string f)
Initializes the system with the given input values.
- Parameters:
f – The input string containing the values.
- Returns:
A vector of double values representing the initialized system state.
-
inline Concore()