|
Teamcenter C++ API Reference
2312
|
Manipulates a file. More...
#include <OSFile.hxx>
Public Member Functions | |
| virtual char * | asString () const |
| int | changeFilePath (const char *iFilePath) |
| int | chmod (int iMode) |
| int | close () |
| int | copy (const char *iCopyPath) |
| int | create (int iMode=0644) |
| int | deleteFile () |
| int | exists (bool &oFileExists) const |
| int | fprintf (const char *iFormattedLine,...) |
| int | fscanf (const char *oFormattedLine,...) |
| char * | getDirectoryPath () const |
| char * | getFileExtension () const |
| char * | getFileName () const |
| char * | getFilePath () const |
| int | getFileSize () |
| int | getFileStatus (SS_file_status *oFileStatus) |
| int | getFileType (int *oFileType) |
| char * | getToken (char *oFoundSeparator, const char *iSeparators=" \n\t\r\f") |
| int | initializeParsing () |
| int | open (int iRWMode=01) |
| OSFile & | operator<< (unsigned char) |
| OSFile & | operator<< (short) |
| OSFile & | operator<< (unsigned short) |
| OSFile & | operator<< (int) |
| OSFile & | operator<< (unsigned int) |
| OSFile & | operator<< (long) |
| OSFile & | operator<< (unsigned long) |
| OSFile & | operator<< (float) |
| OSFile & | operator<< (double) |
| OSFile & | operator= (const OSFile &) |
| OSFile & | operator>> (unsigned char &) |
| OSFile & | operator>> (short &) |
| OSFile & | operator>> (unsigned short &) |
| OSFile & | operator>> (int &) |
| OSFile & | operator>> (unsigned int &) |
| OSFile & | operator>> (long &) |
| OSFile & | operator>> (unsigned long &) |
| OSFile & | operator>> (float &) |
| OSFile & | operator>> (double &) |
| OSFile (const char *iFilePath, int iFileType=010000) | |
| OSFile (int iFileType=010000) | |
| OSFile (const OSFile &iOSFile) | |
| int | print (const char *iPrinter=0) const |
| int | read (void *ioBuffer, int iNumberOfBytes, int iType=0) |
| int | readByte (unsigned char *ioBuffer, int iNumberOfBytes) |
| int | readChar (unsigned char *ioBuffer, int iNumberOfBytes) |
| int | readDouble (double *ioBuffer, int iNumberOfBytes) |
| int | readFloat (float *ioBuffer, int iNumberOfBytes) |
| int | readInt (unsigned int *ioBuffer, int iNumberOfBytes) |
| int | readInt (int *ioBuffer, int iNumberOfBytes) |
| int | readLine (char *oReadLine) |
| int | readLineWithAllocation (char **oReadLine) |
| int | readLong (unsigned long *ioBuffer, int iNumberOfBytes) |
| int | readLong (long *ioBuffer, int iNumberOfBytes) |
| int | readShort (unsigned short *ioBuffer, int iNumberOfBytes) |
| int | readShort (short *ioBuffer, int iNumberOfBytes) |
| int | readVoid (void *ioBuffer, int iNumberOfBytes) |
| int | rename (const char *iFileName) |
| int | seek (int *iOffset) |
| int | write (const void *ioBuffer, int iNumberOfBytes, int iType=0) |
| int | writeByte (const unsigned char *ioBuffer, int iNumberOfBytes) |
| int | writeChar (const unsigned char *ioBuffer, int iNumberOfBytes) |
| int | writeDouble (const double *ioBuffer, int iNumberOfBytes) |
| int | writeFloat (const float *ioBuffer, int iNumberOfBytes) |
| int | writeInt (const unsigned int *ioBuffer, int iNumberOfBytes) |
| int | writeInt (const int *ioBuffer, int iNumberOfBytes) |
| int | writeLine (const char *iLine) |
| int | writeLong (const unsigned long *ioBuffer, int iNumberOfBytes) |
| int | writeLong (const long *ioBuffer, int iNumberOfBytes) |
| int | writeShort (const unsigned short *ioBuffer, int iNumberOfBytes) |
| int | writeShort (const short *ioBuffer, int iNumberOfBytes) |
| int | writeVoid (const void *ioBuffer, int iNumberOfBytes) |
| virtual | ~OSFile () |
Static Public Member Functions | |
| static char * | getCleanedName (const char *iFileNameToClean) |
| static char * | getValidatedFileName (const char *iFileNameToValidate, bool iKeepCase) |
Protected Member Functions | |
| bool | isSeparator (char iCharacter, const char *iSeparators) const |
Private Member Functions | |
| void | getFileInformation () |
Private Attributes | |
| int | m_creationDate |
| SS_fd | m_fileDescriptor |
| int | m_fileFormat |
| char * | m_filePath |
| int | m_fileProtection |
| int | m_fileSize |
| struct { | |
| int error_status | |
| const char * operation | |
| } | m_fileStatus |
| int | m_flagTextBinary |
| int | m_owner |
| char * | m_parsedLine |
| int | m_parsedLineLength |
| int | m_parsedLinePosition |
| bool | m_parsingError |
| bool | m_statDataRetrieved |
Static Private Attributes | |
| static const char * | OPERATION_CHANGEFP |
| static const char * | OPERATION_CHMOD |
| static const char * | OPERATION_CLOSE |
| static const char * | OPERATION_CONSTRUCTOR |
| static const char * | OPERATION_COPY |
| static const char * | OPERATION_COPYCONST |
| static const char * | OPERATION_CREATE |
| static const char * | OPERATION_DELETE |
| static const char * | OPERATION_EXISTS |
| static const char * | OPERATION_FPRINTF |
| static const char * | OPERATION_FSCANF |
| static const char * | OPERATION_GETFILEINFO |
| static const char * | OPERATION_OPEN |
| static const char * | OPERATION_OPERATOREQUALS |
| static const char * | OPERATION_READ |
| static const char * | OPERATION_READLINE |
| static const char * | OPERATION_READLINEWA |
| static const char * | OPERATION_RENAME |
| static const char * | OPERATION_SEEK |
| static const char * | OPERATION_STAT |
| static const char * | OPERATION_WRITE |
| static const char * | OPERATION_WRITELINE |
Manipulates a file.
It provides a wide range of methods to create, delete, rename, parse, etc. a file.
Definition at line 37 of file OSFile.hxx.
| Teamcenter::OSFile::OSFile | ( | const char * | iFilePath, |
| int | iFileType = 010000 |
||
| ) |
Constructs the object based on the provided file path and type.
| [in] | iFilePath | Path to the file |
| [in] | iFileType | Type of file. Valid values are SS_TEXT or SS_BINARY |
| Teamcenter::OSFile::OSFile | ( | int | iFileType = 010000 | ) |
Constructs the object based solely on the provided type.
| [in] | iFileType | Type of file. Valid values are SS_TEXT or SS_BINARY |
| Teamcenter::OSFile::OSFile | ( | const OSFile & | iOSFile | ) |
Copy constructor.
|
virtual |
Destructor
|
virtual |
Dumps the content of a OSFile object, printing all of its attributes.
All references to other objects will only be dumped as hexadecimal addresses.
| int Teamcenter::OSFile::changeFilePath | ( | const char * | iFilePath | ) |
Changes the full path to the OSFile instance.
The file needs to:
| [in] | iFilePath | The new file path. |
| int Teamcenter::OSFile::chmod | ( | int | iMode | ) |
| int Teamcenter::OSFile::close | ( | ) |
Closes the file.
If the file does not exist and the mode is not read-only, then the file will be created.
| int Teamcenter::OSFile::copy | ( | const char * | iCopyPath | ) |
Copies the content of the OSFile instance to another file.
The file must be closed.
| [in] | iCopyPath | Path to the location where the file will be copied. |
| int Teamcenter::OSFile::create | ( | int | iMode = 0644 | ) |
Creates the file with the permission as specified in the iMode arguments
The value for the mode is a numeric mode is from one to four octal digits (0-7), derived by adding up the bits with values 4, 2 and 1. Any omitted digits are assumed to be leading zeros:
The following modes can be used as defined in the ITK documentation group SS_CONST: SS_ALL_PERMISSIONS_DMODE, SS_DEF_FMODE, SS_DEF_DMODE, SS_NO_WORLD_ACCESS_FMODE, SS_NO_WORLD_ACCESS_DMODE
| [in] | iMode | The needed mode as explained above. By default, the files are created with the mode SS_DEF_DMODE (user can read/write, all others can only read). |
| int Teamcenter::OSFile::deleteFile | ( | ) |
Deletes the file.
The file must be closed.
| int Teamcenter::OSFile::exists | ( | bool & | oFileExists | ) | const |
Checks the existence of a file.
| [in,out] | oFileExists | Flag determining if the file exists |
| int Teamcenter::OSFile::fprintf | ( | const char * | iFormattedLine, |
| ... | |||
| ) |
Writes a formatted line to the file.
The file needs to be opened.
| [in] | iFormattedLine | The formatted line to print to the file. |
| [in] | ... | The formatted arguments to be fed into the formatted line. |
| int Teamcenter::OSFile::fscanf | ( | const char * | oFormattedLine, |
| ... | |||
| ) |
Reads a line from the file, and stores the output in the oFormattedLine parameter.
The file needs to be opened.
The method detects the presence of up to 10 arguments in the formatted line. Arguments are signalled by the '' character, which can also be escaped ("\%").
| [out] | oFormattedLine | The line being read. |
| [out] | ... | The variable argument list. Each non-zero pointer corresponds to an existing parameter in the formatted line. |
|
static |
Generates a suitable file name from an input string, by replacing all single-byte non alphanumeric characters (excluding the '+', '-' and '|' characters) with the '_' character.
The file extension is also considered in the validation. Only the last '.' character will not be replaced, because it is considered as the extension marker.
The output file name will be in lower case.
| [in] | iFileNameToClean | The file name to clean |
| char* Teamcenter::OSFile::getDirectoryPath | ( | ) | const |
Returns the directory part of the path name
The name will contain either the / or the \ folder separator, depending on the Operating System.
| char* Teamcenter::OSFile::getFileExtension | ( | ) | const |
Retrieves the file extension.
|
private |
Retrieves the file stats information
| char* Teamcenter::OSFile::getFileName | ( | ) | const |
Returns the name of the file (with its potential extension).
| char* Teamcenter::OSFile::getFilePath | ( | ) | const |
Retrieves the full path as it was passed in the constructor.
| int Teamcenter::OSFile::getFileSize | ( | ) |
Returns the size of the file in bytes.
| int Teamcenter::OSFile::getFileStatus | ( | SS_file_status * | oFileStatus | ) |
Retrieves the file status, as captured in the structure SS_file_status.
| [out] | oFileStatus | The file status. |
| int Teamcenter::OSFile::getFileType | ( | int * | oFileType | ) |
Retrieves the file type.
| [out] | oFileType | The file type. Values are SS_TEXT (text file) and SS_BINARY (binary file). |
| char* Teamcenter::OSFile::getToken | ( | char * | oFoundSeparator, |
| const char * | iSeparators = " \n\t\r\f" |
||
| ) |
Parses the file content and returns the string found between the current cursor position and the next separator (any of the characters in the parameter iSeparators).
The method initializeParsing() must have been called at least once.
Each time parsing from the beginning is needed, the method initializeParsing() needs to be called.
Once parsing is done, remember to close the file.
Note the following behavior:
oFoundSeparator will contain the character '\0'. Here is an example of output with successive calls, using ";\n" as separators
| String | Result call#1 | Result call#2 | Result call#3 | Result call#4 |
|---|---|---|---|---|
| token1; "token;2" ;token3 | oFoundSeparator=';' return=token1 | oFoundSeparator=' ' return="token;2" | oFoundSeparator='' return=token3 | oFoundSeparator='' return= |
| [out] | oFoundSeparator | The separator found for the returned token |
| [in] | iSeparators | String containing separators (one per character) to be considered for parsing. |
|
static |
Generates a suitable file name from an input string, by replacing all single-byte non alphanumeric characters with the '_' character.
The file extension is also considered in the validation. Only the last '.' character will not be replaced, because it is considered as the extension marker.
| [in] | iFileNameToValidate | The file name to validate |
| [in] | iKeepCase | Flag to indicate if the case of the file name shall not be altered (true) or set to lower case (false). |
| int Teamcenter::OSFile::initializeParsing | ( | ) |
Initializes the instance prior to parsing (through getToken()).
The file needs to be closed prior to the call. The method will open the file.
Each time parsing from the beginning is needed, the method needs to be called.
Once parsing is done, remember to close the file.
|
protected |
Checks if the provided character is one of the characters in the iSeparators parameter.
| int Teamcenter::OSFile::open | ( | int | iRWMode = 01 | ) |
Opens the file with the requested permission.
If the file does not exist and the mode is not read-only, then the file will be created.
| [in] | iRWMode | The needed mode to open the file. The default mode is read only. Valid values are SS_RDONLY (read only), SS_WRONLY (write only), SS_RDWRITE (read/write), SS_APPEND (appending) |
| OSFile& Teamcenter::OSFile::operator<< | ( | unsigned | short | ) |
| OSFile& Teamcenter::OSFile::operator<< | ( | unsigned | int | ) |
| OSFile& Teamcenter::OSFile::operator<< | ( | unsigned | long | ) |
| int Teamcenter::OSFile::print | ( | const char * | iPrinter = 0 | ) | const |
Prints the file content to the specified printer.
| [in] | iPrinter | The printer to use for the job. If a 0 pointer is specified, the printer stored in the preference "TC_PRINTER" will be used. |
| int Teamcenter::OSFile::read | ( | void * | ioBuffer, |
| int | iNumberOfBytes, | ||
| int | iType = 0 |
||
| ) |
Read iNumberOfBytes bytes from the file and puts it in the ioBuffer pointer.
| [in,out] | ioBuffer | The pointer containing the output. The memory needs to be allocated prior to the call. |
| [in] | iNumberOfBytes | The number of bytes to read |
| [in] | iType | The type of the data. Valid values are SS_VOID, SS_CHAR, SS_WCHAR, SS_BYTE, SS_SHORT, SS_LONG, SS_FLOAT, SS_DOUBLE. |
| int Teamcenter::OSFile::readLine | ( | char * | oReadLine | ) |
Reads a line from the file, and stores the output in already-allocated memory.
The file needs to be opened.
| [out] | oReadLine | The line being read. The pointer will need to be allocated prior to calling this method. It should be dimensioned to SS_MAXLLEN. |
| int Teamcenter::OSFile::readLineWithAllocation | ( | char ** | oReadLine | ) |
Reads a line from the file, and allocates the memory in the returned pointer.
The file needs to be opened.
| [out] | oReadLine | The line being read. The pointer will need to be freed through a call to MEM_free or Teamcenter::scoped_smptr. |
| int Teamcenter::OSFile::rename | ( | const char * | iFileName | ) |
Changes the file name of the OSFile instance.
The file needs to:
| [in] | iFileName | The new file name. |
| int Teamcenter::OSFile::seek | ( | int * | iOffset | ) |
Retrieves or sets the cursor position in the file.
The file needs to be opened prior to this call.
If the parameter value is -1, the method will retrieve the current cursor position. Otherwise, the method will set the cursor position to the desired location.
| [in,out] | iOffset | Either the position to retrieve or the position to set |
iOffset will be set to -1. | int Teamcenter::OSFile::write | ( | const void * | ioBuffer, |
| int | iNumberOfBytes, | ||
| int | iType = 0 |
||
| ) |
Writes iNumberOfBytes bytes from the ioBuffer pointer into the file.
| [in] | ioBuffer | The pointer containing the information to print to the file. |
| [in] | iNumberOfBytes | The number of bytes to write. |
| [in] | iType | The type of the data. Valid values are SS_VOID, SS_CHAR, SS_WCHAR, SS_BYTE, SS_SHORT, SS_LONG, SS_FLOAT, SS_DOUBLE. |
| int Teamcenter::OSFile::writeLine | ( | const char * | iLine | ) |
Writes a line to the file.
The file needs to be opened.
| [in] | iLine | The line to be written. |
| int Teamcenter::OSFile::error_status |
Any error that has occurred on a file operation
Definition at line 691 of file OSFile.hxx.
|
private |
File creation date
Definition at line 653 of file OSFile.hxx.
|
private |
File descriptor
Definition at line 659 of file OSFile.hxx.
|
private |
The file format
Definition at line 668 of file OSFile.hxx.
|
private |
File path
Definition at line 686 of file OSFile.hxx.
|
private |
File protection mode
Definition at line 656 of file OSFile.hxx.
|
private |
The file size
Definition at line 665 of file OSFile.hxx.
| struct { ... } Teamcenter::OSFile::m_fileStatus |
|
private |
Mode flag to determine if the file is text or binary
Definition at line 662 of file OSFile.hxx.
|
private |
ID of the file owner
Definition at line 650 of file OSFile.hxx.
|
private |
File parsing: line content
Definition at line 674 of file OSFile.hxx.
|
private |
File parsing: line length
Definition at line 680 of file OSFile.hxx.
|
private |
File parsing: cursor position
Definition at line 677 of file OSFile.hxx.
|
private |
File parsing: reports if a parsing error has occurred
Definition at line 683 of file OSFile.hxx.
|
private |
Flag to determine if the file stats shall be retrieved
Definition at line 671 of file OSFile.hxx.
| const char* Teamcenter::OSFile::operation |
The name of the operation where the error has occurred
Definition at line 692 of file OSFile.hxx.
|
staticprivate |
Definition at line 700 of file OSFile.hxx.
|
staticprivate |
Definition at line 706 of file OSFile.hxx.
|
staticprivate |
Definition at line 703 of file OSFile.hxx.
|
staticprivate |
Constants defining the different types of operations done on the OSFile instance
Definition at line 696 of file OSFile.hxx.
|
staticprivate |
Definition at line 708 of file OSFile.hxx.
|
staticprivate |
Definition at line 697 of file OSFile.hxx.
|
staticprivate |
Definition at line 701 of file OSFile.hxx.
|
staticprivate |
Definition at line 704 of file OSFile.hxx.
|
staticprivate |
Definition at line 705 of file OSFile.hxx.
|
staticprivate |
Definition at line 711 of file OSFile.hxx.
|
staticprivate |
Definition at line 712 of file OSFile.hxx.
|
staticprivate |
Definition at line 717 of file OSFile.hxx.
|
staticprivate |
Definition at line 702 of file OSFile.hxx.
|
staticprivate |
Definition at line 698 of file OSFile.hxx.
|
staticprivate |
Definition at line 709 of file OSFile.hxx.
|
staticprivate |
Definition at line 714 of file OSFile.hxx.
|
staticprivate |
Definition at line 713 of file OSFile.hxx.
|
staticprivate |
Definition at line 699 of file OSFile.hxx.
|
staticprivate |
Definition at line 716 of file OSFile.hxx.
|
staticprivate |
Definition at line 707 of file OSFile.hxx.
|
staticprivate |
Definition at line 710 of file OSFile.hxx.
|
staticprivate |
Definition at line 715 of file OSFile.hxx.