- Inherits from:
- Object
- Declared in:
- DSource.h
Object
|
+---DSource
Class Description
The DSource class is used by the class DLexer and the class DTokenizer for
storing the relevant info of the source for the lexer c.q. tokenizer. By storing
the objects in a list, a stack of sources can be implemented.
- Example:
#include <stdio.h>
#include <string.h>
#include "ofc/DSource.h"
#include "ofc/DFile.h"
int main(int argc, char *argv[])
{
DFile *file = [DFile new];
DSource *srce = [DSource new];
char name[] = "example.xml";
if ([file open :name :"r"])
{
if ([srce set :file :name])
{
do // Do for the whole file
{
while (![srce isLineScanned]) // Repeat during scanning of the line
{
int length;
printf("Read line:%s\n", [srce line]); // Print the remaining line
length = strlen([srce line]);
if (length > 10) // Example: scan only 10 chars per time
length = 10;
[srce scanned :length];
}
}
while ([srce nextLine]);
}
else
printf("Could start sourcing \"%s\".\n", name);
[file close];
}
else
printf("Could not open \"%s\":%d.\n", name, [file error]);
[srce free]; // Cleanup
[file free];
return 0;
}
- Last modified:
- 16-Aug-2008 (DSource.h)
Instance Variables
- private id <DTextReadable> _source
- the reference to the source (file)
- private DText *_name
- the name of the source (file)
- private DText *_line
- the read line
- private int _lineNr
- the line number
- private int _columnNr
- the column number
- private int _scanned
- the scanned part of _line
- Constructors
- - (DSource *) init
- Initialise an empty source object
- Returns:
- the object
- - (DSource *) init :(id <DTextReadable>) source :(const char *) name
- Initialise a source object with a source
- Parameters:
- source - the reference to the file
name - the name of the file
- Returns:
- the object
- Copy related methods
- - shallowCopy
- Do a shallow copy of the object (not implemented)
- Returns:
- the object
- Deconstructor
- - free
- Free the object
- Returns:
- the object
- Member methods
- - (int) columnNumber
- Get the current column number
- Returns:
- the column number
- - (const char *) line
- Get the remaining line of text
- Returns:
- the remaining line of text
- - (int) lineNumber
- Get the current line number
- Returns:
- the line number
- - (const char *) name
- Get the name of the source
- Returns:
- a (new) DText with the name
- Main methods
- - (BOOL) appendLine
- Append the next line to the current line
- Returns:
- success
- - (DSource *) error :(const char *) msg
- Generate an error on stderr for the current file and line
- Parameters:
- msg - the error message
- Returns:
- the object
- - (BOOL) isLineScanned
- Check if the current line is fully scanned
- Returns:
- is it ?
- - (BOOL) nextLine
- Move to the next line
- Returns:
- success
- - (BOOL) scanned :(unsigned) length
- Indicate that a part of the line is scanned
- Parameters:
- length - the length of the scanned part
- Returns:
- is the whole line scanned ?
- - (BOOL) set :(id <DTextReadable>) source :(const char *) name
- Set the source definition
- Parameters:
- source - the reference to the file
name - the name of the file
- Returns:
- success
generated 06-Sep-2008 by ObjcDoc 3.0.0