GlfRefSection Class Reference

This class allows a user to easily get/set the fields in a GLF section/chromosome header. More...

`#include <GlfRefSection.h>`

## Public Member Functions

| GlfRefSection (const GlfRefSection &refSection)
| Copy Constructor. More...
GlfRefSection & | operator= (const GlfRefSection &refSection)
| Overload operator= to copy the passed in refSection into this one. More...
bool | copy (const GlfRefSection &refSection)
| Copy the passed in refSection into this refSection. More...
void | resetRefSection ()
| Clear this reference section back to the default setting. More...
bool | read (IFILE filePtr)
| Read the refSection from the specified file (file MUST be in the correct position for reading a refSection). More...
bool | write (IFILE filePtr) const
| Write the refSection to the specified file. More...
bool | getName (std::string &name) const
| Get the reference name. More...
uint32_t | getRefLen () const
| Get the length of the reference sequence. More...
bool | setName (const std::string &name)
| Set the reference name. More...
bool | setRefLen (uint32_t refLen)
| Set the length of the reference sequence. More...
void | print () const
| Print the reference section in a readable format. More...

## Detailed Description

This class allows a user to easily get/set the fields in a GLF section/chromosome header.

The GlfRefSection contains:

- Reference Sequence Name
- Reference Sequence Length

Definition at line 31 of file GlfRefSection.h.

## Constructor & Destructor Documentation

## GlfRefSection() [1/2]

GlfRefSection::GlfRefSection | ( |  | ) |

Definition at line 22 of file GlfRefSection.cpp.

: myRefName()
{
resetRefSection();
}
GlfRefSection::resetRefSection
void resetRefSection()
Clear this reference section back to the default setting.
Definition: GlfRefSection.cpp:70

## ~GlfRefSection()

GlfRefSection::~GlfRefSection | ( |  | ) |

Definition at line 29 of file GlfRefSection.cpp.

{
resetRefSection();
}

## GlfRefSection() [2/2]

GlfRefSection::GlfRefSection | ( | const GlfRefSection & | refSection | ) |

Copy Constructor.

Parameters

  refSection | reference section to copy into this one.

Definition at line 36 of file GlfRefSection.cpp.

: myRefName()
{
copy(refSection);
}
GlfRefSection::copy
bool copy(const GlfRefSection &refSection)
Copy the passed in refSection into this refSection.
Definition: GlfRefSection.cpp:51

References copy().

## Member Function Documentation

## copy()

bool GlfRefSection::copy | ( | const GlfRefSection & | refSection | ) |

Copy the passed in refSection into this refSection.

Parameters

  refSection | reference section to copy into this one.

Definition at line 51 of file GlfRefSection.cpp.

{
// Check to see if the passed in value is the same as this.
if(this == &refSection)
{
return(true);
}
resetRefSection();
// Copy the refSection.
myRefName = refSection.myRefName;
myRefLen = refSection.myRefLen;
return(true);
}

References resetRefSection().

Referenced by GlfRefSection(), and operator=().

## getName()

bool GlfRefSection::getName | ( | std::string & | name | ) | const

Get the reference name.

Parameters

  name | string to populate with the reference name.

Returns
  true if the name was successfully returned, false if not.

Definition at line 193 of file GlfRefSection.cpp.

{
name = myRefName.c_str();
return(true);
}

## getRefLen()

uint32_t GlfRefSection::getRefLen | ( |  | ) | const

Get the length of the reference sequence.

Returns
  reference sequence length for this reference section.

Definition at line 200 of file GlfRefSection.cpp.

{
return(myRefLen);
}

## operator=()

GlfRefSection & GlfRefSection::operator= | ( | const GlfRefSection & | refSection | ) |

Overload operator= to copy the passed in refSection into this one.

Parameters

  refSection | reference section to copy into this one.

Definition at line 44 of file GlfRefSection.cpp.

{
copy(refSection);
return(*this);
}

References copy().

## print()

void GlfRefSection::print | ( |  | ) | const

Print the reference section in a readable format.

Definition at line 220 of file GlfRefSection.cpp.

{
std::cout << "l_name: " << myRefName.length()
<< "; name: " << myRefName.c_str()
<< "; ref_len: " << myRefLen
<< "\n";
}

## read()

bool GlfRefSection::read | ( | IFILE | filePtr | ) |

Read the refSection from the specified file (file MUST be in the correct position for reading a refSection).

Parameters

  filePtr | file to read from that is in the correct position.

Returns
  true if the reference section was successfully read from the file, false if not.

Definition at line 79 of file GlfRefSection.cpp.

{
// Read the reference sequence name length
int numRead = 0;
int32_t refNameLen = 0;
int byteLen = sizeof(int32_t);
numRead = ifread(filePtr, &refNameLen, byteLen);
if(numRead != byteLen)
{
// If no bytes were read and it is the end of the file, then return
// false, but do not throw an exception. This is not an error, just
// the end of the file.
if((numRead == 0) && ifeof(filePtr))
{
return(false);
}
String errorMsg =
"Failed to read the length of the reference sequence name (";
errorMsg += byteLen;
errorMsg += " bytes). Only read ";
errorMsg += numRead;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Read the refSection from the file.
numRead = myRefName.readFromFile(filePtr, refNameLen);
if(numRead != refNameLen)
{
String errorMsg = "Failed to read the reference sequence name (";
errorMsg += refNameLen;
errorMsg += " bytes). Only read ";
errorMsg += numRead;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Read the ref length.
byteLen = sizeof(uint32_t);
numRead = ifread(filePtr, &myRefLen, byteLen);
if(numRead != byteLen)
{
String errorMsg = "Failed to read the reference sequence length (";
errorMsg += byteLen;
errorMsg += " bytes). Only read ";
errorMsg += numRead;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Successfully read, return success.
return(true);
}
ifeof
int ifeof(IFILE file)
Check to see if we have reached the EOF (returns 0 if not EOF).
Definition: InputFile.h:654
ifread
unsigned int ifread(IFILE file, void *buffer, unsigned int size)
Read up to size bytes from the file into the buffer.
Definition: InputFile.h:600
GlfException
GlfException objects should be thrown by functions that operate on Glf files for exceptions.
Definition: GlfException.h:28
GlfStatus::FAIL_IO
@ FAIL_IO
method failed due to an I/O issue.
Definition: GlfStatus.h:34
String
Definition: StringBasics.h:39

References GlfStatus::FAIL_IO, ifeof(), and ifread().

Referenced by GlfFile::getNextRefSection().

## resetRefSection()

void GlfRefSection::resetRefSection | ( |  | ) |

Clear this reference section back to the default setting.

Definition at line 70 of file GlfRefSection.cpp.

{
myRefName.reset();
myRefLen = 0;
}

Referenced by copy().

## setName()

bool GlfRefSection::setName | ( | const std::string & | name | ) |

Set the reference name.

Parameters

  name | reference name to set this section to.

Returns
  true if the name was successfully set, false if not.

Definition at line 206 of file GlfRefSection.cpp.

{
myRefName = name;
return(true);
}

## setRefLen()

bool GlfRefSection::setRefLen | ( | uint32_t | refLen | ) |

Set the length of the reference sequence.

Parameters

  refLen | reference sequence length to set this section to.

Returns
  true if the length was successfully set, false if not.

Definition at line 213 of file GlfRefSection.cpp.

{
myRefLen = refLen;
return(true);
}

## write()

bool GlfRefSection::write | ( | IFILE | filePtr | ) | const

Write the refSection to the specified file.

Parameters

  filePtr | file to write to that is in the correct position.

Returns
  true if the reference section was successfully written to the file, false if not.

Definition at line 142 of file GlfRefSection.cpp.

{
int refNameLen = myRefName.length();
int byteLen = sizeof(int32_t);
int numWrite = ifwrite(filePtr, &refNameLen, byteLen);
if(numWrite != byteLen)
{
String errorMsg =
"Failed to write the length of the reference sequence name (";
errorMsg += byteLen;
errorMsg += " bytes). Only wrote ";
errorMsg += numWrite;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
numWrite = ifwrite(filePtr, myRefName.c_str(), refNameLen);
if(numWrite != refNameLen)
{
String errorMsg = "Failed to write the reference sequence name (";
errorMsg += refNameLen;
errorMsg += " bytes). Only wrote ";
errorMsg += numWrite;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Write the length of the reference sequence
byteLen = sizeof(uint32_t);
numWrite = ifwrite(filePtr, &myRefLen, byteLen);
if(numWrite != byteLen)
{
String errorMsg = "Failed to write the reference sequence length (";
errorMsg += byteLen;
errorMsg += " bytes). Only wrote ";
errorMsg += numWrite;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Successfully wrote, return success.
return(true);
}
ifwrite
unsigned int ifwrite(IFILE file, const void *buffer, unsigned int size)
Write the specified number of bytes from the specified buffer into the file.
Definition: InputFile.h:669

References GlfStatus::FAIL_IO, and ifwrite().

Referenced by GlfFile::writeRefSection().

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

- glf/GlfRefSection.h
- glf/GlfRefSection.cpp