- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Mers::Models::CCA::Io::Mof::MOFReader Class Reference

List of all members.

## Public Types
enum | CCAFileType { CCABinary001 = 0x0001, CCABinaryLatest = CCABinary001, CCAText001 = 0x0001 | CCATextFileType, CCAText002 = 0x0002 | CCATextFileType, CCATextLatest = CCAText002 }
## Static Public Member Functions
static int | loadMOF (const char *filename, Mers::Models::CCA::CCAModel &mdl)
static int | loadMOF (const char *filename, Mers::Models::CCA::CCAModel *&mdl)
static int | loadMOFFromString (char const *fileString, Mers::Models::CCA::CCAModel &mdl)
static int | loadMOFFromString (char const *fileString, Mers::Models::CCA::CCAModel *&mdl)
static int | saveCCAModel (const char *filename, CCAFileType saveType, Mers::Models::CCA::CCAModel const &mdl)
static int | saveCCAModel (FILE *file, char const *fileName, CCAFileType saveType, Mers::Models::CCA::CCAModel const &mdl)
static char const * | ccaFileTypeToString (CCAFileType fileType)
static bool | isTextFileFormat (CCAFileType fileType)
## Static Protected Member Functions
static char const * | getCCAFileHeader (CCAFileType fileType)
static int | writeText002 (FILE *file, char const *fileName, char const *headerString, Mers::Models::CCA::CCAModel const &model)
static int | writeTextConstraint (FILE *file, CCASentence const &constraint, char const *clauseSeperator=" ")
static int | writeTextConstraint (FILE *file, CCAClause const &constraint)
static int | writeTextConstraint (FILE *file, CCAAssignment const &constraint)
static int | writeSizedString (FILE *file, char const *str)
static int | writeIndexSizedValue (FILE *file, unsigned char indexSize, unsigned int value)
static int | writeConstraint (FILE *file, unsigned int indexSize, CCASentence const *constraint)
static int | writeConstraint (FILE *file, unsigned int indexSize, CCAClause const *constraint)
static int | writeAssignment (FILE *file, unsigned int indexSize, CCAAssignment const *assign)
static int | writeFloat (FILE *file, float value)
static int | readIndexSizedValue (char const *&fileString, unsigned int fileLen, unsigned char indexSize, unsigned int &value)
static int | readSizedString (char const *&fileString, unsigned int fileLen, char *&str)
static int | readConstraint (char const *&fileString, unsigned int fileLen, unsigned int indexSize, Mers::Models::CCA::CCAModel &mdl, CCASentence *&constraint)
static int | readConstraint (char const *&fileString, unsigned int fileLen, unsigned int indexSize, Mers::Models::CCA::CCAModel &mdl, CCAClause *&constraint)
static int | readAssignment (char const *&fileString, unsigned int fileLen, unsigned int indexSize, Mers::Models::CCA::CCAModel &mdl, CCAAssignment *&assign)
static int | readFloat (char const *&fileString, unsigned int fileLen, float &value)
static int | readInt (char const *&fileString, unsigned int fileLen, unsigned int numBytes, unsigned int &value)

## Detailed Description

Definition at line 30 of file MOFReader.h.

## Member Enumeration Documentation

enum Mers::Models::CCA::Io::Mof::MOFReader::CCAFileType

CCAFileType is setup so the version # is the lower 12 bits and the 13th bit is set to 1 if this is a text format, or 0 if it's a binary format.

Definition at line 38 of file MOFReader.h.

## Member Function Documentation

int MOFReader::loadMOF | ( | const char * | filename,
|  | Mers::Models::CCA::CCAModel & | mdl |
| ) |  |  | `[static]`

Loads the file specified by filename into the model.

Parameters:

  | filename | pointer to the string name of the file being opened.
  | mdl | handle to the model object to be filled by the reader. it is assumed that the model is empty or is being incrementally updated, so the model should already be clear if that is the desired initial state.

Returns:
  0 on success or non zero if an error occured with opening or parsing the file

Definition at line 80 of file MOFReader.cpp.

Referenced by loadMOF().

int MOFReader::loadMOF | ( | const char * | filename,
|  | Mers::Models::CCA::CCAModel *& | mdl |
| ) |  |  | `[static]`

Loads the file specified by filename into the model, also creates a new model if model is NULL.

Parameters:

  | filename | pointer to the string name of the file being opened.
  | mdl | handle to the model object to be filled by the reader. it is assumed that the model is empty or is being incrementally updated, so the model should already be clear if that is the desired initial state. If the model is not allocated, it should be NULL.

Returns:
  0 on success or non zero if an error occured with opening or parsing the file

Definition at line 108 of file MOFReader.cpp.

References loadMOF().

Here is the call graph for this function:

int MOFReader::loadMOFFromString | ( | char const * | fileString,
|  | Mers::Models::CCA::CCAModel & | mdl |
| ) |  |  | `[static]`

Loads the model from the specified string. Usefull if the whole file is already loaded in memory.

Parameters:

  | fileString | the string that contains the whole file.
  | mdl | handle to the model object to be filled by the reading of the string. it is assumed that the model is empty or is being incrementally updated, so the model should already be clear if that is the desired initial state.

Returns:
  0 on success or non-zero if an error occured while parsing the string.

Definition at line 123 of file MOFReader.cpp.

References Mers::Models::Base::BaseModel::addDomain(), Mers::Models::CCA::CCAStates::begin(), Mers::Models::CCA::CCAAutomata::begin(), ccaFileTypeToString(), Mers::Models::CCA::CCAStates::end(), Mers::Models::CCA::CCAAutomata::end(), Mers::Models::CCA::CCAModel::get_ccAutomata_p(), getCCAFileHeader(), Mers::Models::CCA::CCAModel::getDomains(), Mers::Utils::Containers::DynamicArray::getLength(), Mers::Models::Base::BaseModelVariable::getName(), Mers::Models::CCA::CCAModel::insert_global_constraint(), Mers::Models::CCA::CCAModel::insert_transition(), Mers::Models::Base::BaseModelValueArray::pushBack(), readConstraint(), readFloat(), readIndexSizedValue(), readInt(), readSizedString(), Mers::Models::CCA::CCAState::set_constraint(), Mers::Models::CCA::CCAAutomaton::set_topological_numb(), Mers::Models::CCA::CCAState::set_type(), Mers::Models::CCA::CCAAutomaton::states_p(), and Mers::Models::CCA::CCAAutomaton::variable_p().

Referenced by loadMOFFromString().

Here is the call graph for this function:

int MOFReader::loadMOFFromString | ( | char const * | fileString,
|  | Mers::Models::CCA::CCAModel *& | mdl |
| ) |  |  | `[static]`

Loads the model from the specified string. Usefull if the whole file is already loaded in memory.

Parameters:

  | fileString | the string that contains the whole file.
  | mdl | handle to the model object to be filled by the reading of the string. it is assumed that the model is empty or is being incrementally updated, so the model should already be clear if that is the desired initial state. If the model is not allocated, it should be NULL.

Returns:
  0 on success or non-zero if an error occured while parsing the string.

Definition at line 626 of file MOFReader.cpp.

References loadMOFFromString().

Here is the call graph for this function:

int MOFReader::saveCCAModel | ( | const char * | filename,
|  | CCAFileType | saveType,
|  | Mers::Models::CCA::CCAModel const & | mdl |
| ) |  |  | `[static]`

Saves a model to the specified CCA File Type, if supported.

Currently supported CCA File Types:
CCABinary001

Parameters:

  | filename | the name of the file to use as the save file, without the file extension.
  | saveType | the format/version of the file to save. This must be from the list of supported CCA File Types or the call will fail.
  | mdl | the model that will be exported to the file.

Returns:
  0 on success or non-zero if an error occured

Definition at line 1048 of file MOFReader.cpp.

References Mers::Utils::Lang::String::c_str(), and isTextFileFormat().

Here is the call graph for this function:

int MOFReader::saveCCAModel | ( | FILE * | file,
|  | char const * | fileName,
|  | CCAFileType | saveType,
|  | Mers::Models::CCA::CCAModel const & | mdl |
| ) |  |  | `[static]`

Saves a model to the specified CCA File Type, if supported.

Currently supported CCA File Types:
CCABinary001

Parameters:

  | file | the file to use as the save file.
  | saveType | the format/version of the file to save. This must be from the list of supported CCA File Types or the call will fail.
  | mdl | the model that will be exported to the file.

Returns:
  0 on success or non-zero if an error occured.

Definition at line 641 of file MOFReader.cpp.

References Mers::Models::CCA::CCAAutomata::begin(), Mers::Models::Base::BaseModelVariableArray::begin(), Mers::Models::Base::BaseModelDomainArray::begin(), Mers::Models::CCA::CCAModel::ccAutomata_p(), Mers::Models::CCA::CCAAutomata::end(), Mers::Models::Base::BaseModelVariableArray::end(), Mers::Models::Base::BaseModelDomainArray::end(), Mers::Models::CCA::CCAModel::get_variables_p(), getCCAFileHeader(), Mers::Models::CCA::CCAModel::getDomains(), Mers::Utils::Containers::DynamicArray::getLength(), Mers::Models::CCA::CCAModel::getVariables(), Mers::Models::CCA::CCAModel::global_constraint_p(), writeConstraint(), writeFloat(), writeIndexSizedValue(), writeSizedString(), and writeText002().

Here is the call graph for this function:

char const * MOFReader::ccaFileTypeToString | ( | CCAFileType | fileType | ) | `[static]`

Returns the string name of a CCAFileType enumerated type.

Parameters:

  | fileType | the enumerated type for which the string is being fetched.

Returns:
  a handle to a static string if the enumerated type was found or NULL if the type was invalid.

Definition at line 1098 of file MOFReader.cpp.

Referenced by loadMOFFromString().

bool MOFReader::isTextFileFormat | ( | CCAFileType | fileType | ) | `[static]`

Returns true iff this is a CCA text file type.

Parameters:

  | fileType | the file type in question.

Returns:
  true if the CCAFileType is text file type.

Definition at line 1116 of file MOFReader.cpp.

Referenced by saveCCAModel().

char const * MOFReader::getCCAFileHeader | ( | CCAFileType | fileType | ) | `[static, protected]`

Returns the header string for the specified fileType.

Parameters:

  | fileType | the file for which the file header is retrieved.

Returns:
  a valid static character string if the header was found or NULL if the header was not found.

Definition at line 1123 of file MOFReader.cpp.

Referenced by loadMOFFromString(), and saveCCAModel().

int MOFReader::writeText002 | ( | FILE * | file,
|  | char const * | fileName,
|  | char const * | headerString,
|  | Mers::Models::CCA::CCAModel const & | model |
| ) |  |  | `[static, protected]`

Saves a model to a CCAText002 file type.

Parameters:

  | file | the file to use as the save file.
  | headerString | the text string of this file's header.
  | model | the model that will be exported to the file.

Returns:
  0 on success or non-zero if an error occured.

Definition at line 1145 of file MOFReader.cpp.

References Mers::Utils::Lang::String::c_str(), Mers::Models::CCA::CCAModel::get_ccAutomata_p(), Mers::Utils::Containers::DynamicArray::getLength(), Mers::Models::Base::BaseModelValue::getName(), Mers::Models::CCA::CCAModel::global_constraint_p(), Mers::Utils::Lang::String::resize(), Mers::Utils::Lang::String::rfind(), Mers::Utils::Lang::String::substr(), and writeTextConstraint().

Referenced by saveCCAModel().

Here is the call graph for this function:

int MOFReader::writeTextConstraint | ( | FILE * | file,
|  | CCASentence const & | constraint,
|  | char const * | clauseSeperator = `" "` |
| ) |  |  | `[static, protected]`

Saves a Sentence constraint to a text file.

Parameters:

  | file | the file to use as the save file.
  | constraint | the sentence that should be written.
  | clauseSeperator | string to insert between each clause.

Returns:
  0 on success or non-zero if an error occured.

Definition at line 1244 of file MOFReader.cpp.

References Mers::Utils::Containers::DynamicArray::getLength(), and Mers::Models::Base::BaseModelSentence::getSentenceType().

Referenced by writeText002(), and writeTextConstraint().

Here is the call graph for this function:

int MOFReader::writeTextConstraint | ( | FILE * | file,
|  | CCAClause const & | constraint |
| ) |  |  | `[static, protected]`

Saves a Clause constraint to a text file.

Parameters:

  | file | the file to use as the save file.
  | constraint | the clause that should be written.

Returns:
  0 on success or non-zero if an error occured.

Definition at line 1316 of file MOFReader.cpp.

References Mers::Models::Base::BaseModelClause::getClauseType(), Mers::Utils::Containers::DynamicArray::getLength(), and writeTextConstraint().

Here is the call graph for this function:

int MOFReader::writeTextConstraint | ( | FILE * | file,
|  | CCAAssignment const & | constraint |
| ) |  |  | `[static, protected]`

Saves a Clause constraint to a text file.

Parameters:

  | file | the file to use as the save file.
  | constraint | the clause that should be written.

Returns:
  0 on success or non-zero if an error occured.

Definition at line 1372 of file MOFReader.cpp.

References Mers::Models::Base::BaseModelAssignment::getOperator(), Mers::Models::Base::BaseModelAssignment::getValue(), Mers::Models::Base::BaseModelAssignment::getVariable(), and Mers::Models::Base::BaseModelAssignment::operatorToSymbolString().

Here is the call graph for this function:

int MOFReader::writeSizedString | ( | FILE * | file,
|  | char const * | str |
| ) |  |  | `[static, protected]`

Writes a string to the file in the format <XX><String> where XX is an unsigned short representing the strings length and then String is a non-null terminated string. This procedure will truncate the string and write the truncated string to the file if its length exceeds 2^16 characters. A zero length string or null string causes this routine to write a length of 0 (2 bytes) and no characters.

Parameters:

  | file | the file being written to.
  | str | the string being written to the file. Note that it must be null terminated as this routine runs strlen on the string before writting it.

Returns:
  0 on success, a positive number if a write error occured or a negative number if the string was longer than 2^16.

Definition at line 1427 of file MOFReader.cpp.

Referenced by saveCCAModel().

int MOFReader::writeIndexSizedValue | ( | FILE * | file,
|  | unsigned char | indexSize,
|  | unsigned int | value |
| ) |  |  | `[static, protected]`

Writes the value as a 2^indexSize byte integer. It will return an error if there was a problem writting or if the number is trucated in the write operation. If the value is to big, it will be written at the requested byte size and truncated as oppose to pegged (so value &= 0xFF instead of value = 0xFF for indexSize == 0).

Parameters:

  | file | the file being written to.
  | indexSize | specifies the target value size, in bytes. A value of 0 is 1 Byte, a value of 1 is 2 Bytes, 2 is 4 Bytes, etc. Bytes = 2^indexSize; Note that this routine only supports 0, 1, or 2 at the moment.
  | value | the value being written. It will be truncated as necessary to make it fit in the requested footprint.

Returns:
  0 on success, a positive number if a write error occured, a negative number if value was truncated.

Definition at line 1458 of file MOFReader.cpp.

Referenced by saveCCAModel(), and writeAssignment().

int MOFReader::writeConstraint | ( | FILE * | file,
|  | unsigned int | indexSize,
|  | CCASentence const * | constraint |
| ) |  |  | `[static, protected]`

Writes a constraint (sentence) to the file. Sentences are of the form <0xFF><sentence::sentenceType><numClauses>[<Clause>...]. A NULL constraint will write <0xFF><sentence::CNF><0>.

Parameters:

  | file | the constraint information is written to this file.
  | constraint | the sentence being written to the file.

Returns:
  0 on success, a positive number of an error occured while writting.

Definition at line 1487 of file MOFReader.cpp.

References Mers::Models::CCA::CCASentence::begin(), Mers::Models::CCA::CCASentence::end(), Mers::Utils::Containers::DynamicArray::getLength(), and Mers::Models::Base::BaseModelSentence::getSentenceType().

Referenced by saveCCAModel().

Here is the call graph for this function:

int MOFReader::writeConstraint | ( | FILE * | file,
|  | unsigned int | indexSize,
|  | CCAClause const * | constraint |
| ) |  |  | `[static, protected]`

Writes a constraint (clause) to the file. Clauses are of the form <0x00><clause::clauseType><numAssignments>[<Assignment>...]. A NULL constraint will write <0x00><clause::DISJUNCTIVE><0>.

Parameters:

  | file | the constraint information is written to this file.
  | constraint | the clause being written to the file.

Returns:
  0 on success, a positive number of an error occured while writting.

Definition at line 1533 of file MOFReader.cpp.

References Mers::Models::Base::BaseModelAssignmentArray::begin(), Mers::Models::Base::BaseModelAssignmentArray::end(), Mers::Models::Base::BaseModelClause::getClauseType(), Mers::Utils::Containers::DynamicArray::getLength(), and writeAssignment().

Here is the call graph for this function:

int MOFReader::writeAssignment | ( | FILE * | file,
|  | unsigned int | indexSize,
|  | CCAAssignment const * | assign |
| ) |  |  | `[static, protected]`

Writes an assignment to the file. The assignment, in this case, includes the boolean flag from the literal indicating inversion or not. It has the form <bool invert>=""><UID variable>=""><UID value>="">. A NULL assign pointer is invalid.

Parameters:

  | file | the assignment information is written to this file.
  | assign | the assignment that is written to the file.

Returns:
  0 on success, a positive number of an error occured while writting.

Definition at line 1579 of file MOFReader.cpp.

References Mers::Models::Base::BaseModelAssignment::getOperator(), Mers::Models::Base::BaseModelAssignment::getValue(), Mers::Models::Base::BaseModelAssignment::getVariable(), and writeIndexSizedValue().

Referenced by writeConstraint().

Here is the call graph for this function:

int MOFReader::writeFloat | ( | FILE * | file,
|  | float | value |
| ) |  |  | `[static, protected]`

writes the x86 floating point type in the form <24 bit signed mantissa><8 bit signed exponent> using a base 2 radix.

Parameters:

  | file | the file to write the floating point value to.
  | value | the floating point value being written. Note that this floating point type is converted to the above format before writting.

Returns:
  0 on success, a positive number of an error occured while writting.

Definition at line 1620 of file MOFReader.cpp.

Referenced by saveCCAModel().

int MOFReader::readIndexSizedValue | ( | char const *& | fileString,
|  | unsigned int | fileLen,
|  | unsigned char | indexSize,
|  | unsigned int & | value |
| ) |  |  | `[static, protected]`

Reads the value as a 2^indexSize byte integer. It will return an error if there was a problem with the indexSize.

Parameters:

  | fileString | the file being read from.
  | fileLen | the number of bytes left in the file.
  | indexSize | specifies the target value size, in bytes. A value of 0 is 1 Byte, a value of 1 is 2 Bytes, 2 is 4 Bytes, etc. Bytes = 2^indexSize; Note that this routine only supports 0, 1, or 2 at the moment.
  | value | the value being read.

Returns:
  0 on success, a positive number if a read error occured (EOF).

Definition at line 1700 of file MOFReader.cpp.

References readInt().

Referenced by loadMOFFromString(), and readAssignment().

Here is the call graph for this function:

int MOFReader::readSizedString | ( | char const *& | fileString,
|  | unsigned int | fileLen,
|  | char *& | str |
| ) |  |  | `[static, protected]`

Reads a string from the file in the format <XX><String> where XX is an unsigned short representing the strings length and then String is a non-null terminated string. A zero length string will be returned if the string size is zero.

Parameters:

  | fileString | the file being read from.
  | fileLen | the number of bytes left in the file.
  | str | the string being read. This string will be allocated during this routine so it should be NULL prior to calling. It will be null terminated.

Returns:
  0 on success, a positive number if there was insufficient memory to allocate the buffer or if the end of file was reached before reading the string was complete.

Definition at line 1671 of file MOFReader.cpp.

References readInt().

Referenced by loadMOFFromString().

Here is the call graph for this function:

int MOFReader::readConstraint | ( | char const *& | fileString,
|  | unsigned int | fileLen,
|  | unsigned int | indexSize,
|  | Mers::Models::CCA::CCAModel & | mdl,
|  | CCASentence *& | constraint |
| ) |  |  | `[static, protected]`

Reads a constraint (sentence) from the file. Sentences are of the form <0xFF><sentence::sentenceType><numClauses>[<Clause>...]. The returned constraint will always be allocated, even if the constraint length is zero.

Parameters:

  | fileString | the file being read from.
  | fileLen | the number of bytes left in the file.
  | constraint | the sentence being read from the file.

Returns:
  0 on success, a positive number if EOF was reached before reading was complete, or a negative number of the file contained a clause instead of a sentence. In the last case, the clause is placed in a sentence with the opposite type (Conjuctive/Disjunctive) of the clause.

Definition at line 1710 of file MOFReader.cpp.

References Mers::Models::Base::BaseModelClause::getClauseType(), Mers::Models::CCA::CCASentence::insert_clause(), and readInt().

Referenced by loadMOFFromString().

Here is the call graph for this function:

int MOFReader::readConstraint | ( | char const *& | fileString,
|  | unsigned int | fileLen,
|  | unsigned int | indexSize,
|  | Mers::Models::CCA::CCAModel & | mdl,
|  | CCAClause *& | constraint |
| ) |  |  | `[static, protected]`

Reads a constraint (clause) from the file. Clauses are of the form <0x00><clause::clauseType><numAssignments>[<Assignment>...]. The returned constraint will always be allocated, even if the constraint length is zero.

Parameters:

  | fileString | the file being read from.
  | fileLen | the number of bytes left in the file.
  | constraint | the clause being read from the file.

Returns:
  0 on success, a positive number if EOF was reached before reading was complete or if a negative number of the file contained a sentence instead of a clause.

Definition at line 1807 of file MOFReader.cpp.

References Mers::Models::CCA::CCAClause::insert_assignment(), readAssignment(), and readInt().

Here is the call graph for this function:

int MOFReader::readAssignment | ( | char const *& | fileString,
|  | unsigned int | fileLen,
|  | unsigned int | indexSize,
|  | Mers::Models::CCA::CCAModel & | mdl,
|  | CCAAssignment *& | assign |
| ) |  |  | `[static, protected]`

Reads an assignment from the file. The assignment, in this case, includes the boolean flag from the literal indicating inversion or not. It has the form <bool invert>=""><UID variable>=""><UID value>="">.

Parameters:

  | fileString | the file being read from.
  | fileLen | the number of bytes left in the file.
  | assign | the assignment that is read from the file.

Returns:
  0 on success, a positive number if EOF was reached before reading was complete or insufficient memory to allcate the assignemnt.

Definition at line 1871 of file MOFReader.cpp.

References Mers::Models::CCA::CCAModel::get_assignment(), readIndexSizedValue(), and readInt().

Referenced by readConstraint().

Here is the call graph for this function:

int MOFReader::readFloat | ( | char const *& | fileString,
|  | unsigned int | fileLen,
|  | float & | value |
| ) |  |  | `[static, protected]`

Reads the x86 floating point type in the form <24 bit signed mantissa><8 bit signed exponent> using a base 2 radix.

Parameters:

  | fileString | the file being read from.
  | fileLen | the number of bytes left in the file.
  | value | the floating point value being read. Note that this floating point type is converted from the above format to the local processor format.

Returns:
  0 on success, a positive number if EOF was reached before reading was complete.

Definition at line 1917 of file MOFReader.cpp.

References readInt().

Referenced by loadMOFFromString().

Here is the call graph for this function:

int MOFReader::readInt | ( | char const *& | fileString,
|  | unsigned int | fileLen,
|  | unsigned int | numBytes,
|  | unsigned int & | value |
| ) |  |  | `[static, protected]`

Reads in a binary number in LSB first binary form.

Parameters:

  | fileString | the file being read from.
  | fileLen | the number of bytes left in the file.
  | numBytes | the number of bytes to read in for this number, typically 1, 2, or 4.
  | value | the value read in is stored here. It is cleared before reading so the upper unread bytes will be zero.

Returns:
  0 on success, a positive number if there weren't that many bytes left, and a negative number if the data type being used was too small to read in the requested number of bytes

Definition at line 1964 of file MOFReader.cpp.

Referenced by loadMOFFromString(), readAssignment(), readConstraint(), readFloat(), readIndexSizedValue(), and readSizedString().

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

- /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/Io/Mof/MOFReader.h
- /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/Io/Mof/MOFReader.cpp