GlfRefSection Class Reference

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

#include <GlfRefSection.h>

Collaboration diagram for GlfRefSection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Detailed Description

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

The GlfRefSection contains:

Definition at line 31 of file GlfRefSection.h.


Constructor & Destructor Documentation

GlfRefSection::GlfRefSection ( const GlfRefSection refSection  ) 

Copy Constructor.

Parameters:
refSection reference section to copy into this one.

Definition at line 36 of file GlfRefSection.cpp.

References copy().

00037     : myRefName()
00038 {
00039     copy(refSection);
00040 }


Member Function Documentation

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.

References resetRefSection().

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

00052 {
00053     // Check to see if the passed in value is the same as this.
00054     if(this == &refSection)
00055     {
00056         return(true);
00057     }
00058 
00059     resetRefSection();
00060 
00061     // Copy the refSection.
00062     myRefName = refSection.myRefName;
00063     myRefLen = refSection.myRefLen;
00064 
00065     return(true);
00066 }

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.

00194 {
00195     name = myRefName.c_str();
00196     return(true);
00197 }

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.

00201 {
00202     return(myRefLen);
00203 }

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.

References copy().

00045 {
00046     copy(refSection);
00047     return(*this);
00048 }

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.

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

Referenced by GlfFile::getNextRefSection().

00080 {
00081     // Read the reference sequence name length
00082     int numRead = 0;
00083     int32_t refNameLen = 0;
00084     int byteLen = sizeof(int32_t);
00085     numRead = ifread(filePtr, &refNameLen, byteLen);
00086     if(numRead != byteLen)
00087     {
00088         // If no bytes were read and it is the end of the file, then return 
00089         // false, but do not throw an exception.  This is not an error, just
00090         // the end of the file.
00091         if((numRead == 0) && ifeof(filePtr))
00092         {
00093             return(false);
00094         }
00095 
00096         String errorMsg = 
00097             "Failed to read the length of the reference sequence name (";
00098         errorMsg += byteLen;
00099         errorMsg += " bytes).  Only read ";
00100         errorMsg += numRead;
00101         errorMsg += " bytes.";
00102         std::string errorString = errorMsg.c_str();
00103         throw(GlfException(GlfStatus::FAIL_IO, errorString));
00104         return(false);
00105     }
00106        
00107     // Read the refSection from the file.
00108     numRead = myRefName.readFromFile(filePtr, refNameLen);
00109     if(numRead != refNameLen)
00110     {
00111         String errorMsg = "Failed to read the reference sequence name (";
00112         errorMsg += refNameLen;
00113         errorMsg += " bytes).  Only read ";
00114         errorMsg += numRead;
00115         errorMsg += " bytes.";
00116         std::string errorString = errorMsg.c_str();
00117         throw(GlfException(GlfStatus::FAIL_IO, errorString));
00118         return(false);
00119     }
00120 
00121     // Read the ref length.
00122     byteLen = sizeof(uint32_t);
00123     numRead = ifread(filePtr, &myRefLen, byteLen);
00124     if(numRead != byteLen)
00125     {
00126         String errorMsg = "Failed to read the reference sequence length (";
00127         errorMsg += byteLen;
00128         errorMsg += " bytes).  Only read ";
00129         errorMsg += numRead;
00130         errorMsg += " bytes.";
00131         std::string errorString = errorMsg.c_str();
00132         throw(GlfException(GlfStatus::FAIL_IO, errorString));
00133         return(false);
00134     }
00135 
00136     // Successfully read, return success.
00137     return(true);
00138 }

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.

00207 {
00208     myRefName = name;
00209     return(true);
00210 }

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.

00214 {
00215     myRefLen = refLen;
00216     return(true);
00217 }

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.

References GlfStatus::FAIL_IO, and ifwrite().

Referenced by GlfFile::writeRefSection().

00143 {
00144     int refNameLen = myRefName.length();
00145     int byteLen = sizeof(int32_t);
00146     int numWrite = ifwrite(filePtr, &refNameLen, byteLen);
00147     if(numWrite != byteLen)
00148     {
00149         String errorMsg = 
00150             "Failed to write the length of the reference sequence name (";
00151         errorMsg += byteLen;
00152         errorMsg += " bytes).  Only wrote ";
00153         errorMsg += numWrite;
00154         errorMsg += " bytes.";
00155         std::string errorString = errorMsg.c_str();
00156         throw(GlfException(GlfStatus::FAIL_IO, errorString));
00157         return(false);
00158     }
00159 
00160     numWrite = ifwrite(filePtr, myRefName.c_str(), refNameLen);
00161     if(numWrite != refNameLen)
00162     {
00163         String errorMsg = "Failed to write the reference sequence name (";
00164         errorMsg += refNameLen;
00165         errorMsg += " bytes).  Only wrote ";
00166         errorMsg += numWrite;
00167         errorMsg += " bytes.";
00168         std::string errorString = errorMsg.c_str();
00169         throw(GlfException(GlfStatus::FAIL_IO, errorString));
00170         return(false);
00171     }
00172 
00173     // Write the length of the reference sequence
00174     byteLen = sizeof(uint32_t);
00175     numWrite = ifwrite(filePtr, &myRefLen, byteLen);
00176     if(numWrite != byteLen)
00177     {
00178         String errorMsg = "Failed to write the reference sequence length (";
00179         errorMsg += byteLen;
00180         errorMsg += " bytes).  Only wrote ";
00181         errorMsg += numWrite;
00182         errorMsg += " bytes.";
00183         std::string errorString = errorMsg.c_str();
00184         throw(GlfException(GlfStatus::FAIL_IO, errorString));
00185         return(false);
00186     }
00187 
00188     // Successfully wrote, return success.
00189     return(true);
00190 }


The documentation for this class was generated from the following files:
Generated on Tue Sep 6 17:52:02 2011 for libStatGen Software by  doxygen 1.6.3