Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

LineInformation.h

Go to the documentation of this file.
00001 
00002 #include <string.h>
00003 #include <ctype.h>
00004 
00005 class LineInformation{
00006         
00007 public:
00008         
00009         enum LINE_TYPE { EMPTY_LINE, DIRTY_LINE, HEADER_LINE, DATA_LINE, };
00010         
00011 private:
00012         
00013         int _length;
00014         int _tabCount;
00015         // Note that this is not "const" so we can add null terminators
00016         // in places when we need to (using getMalleableLine() )
00017         char *_beginning;
00018         LINE_TYPE _type;
00019         
00020         void _determineLength( void ){ _length=strlen(_beginning); }
00021         void _determineTabCount( void ){ for(const char *b=_beginning;*b;b++) if(*b=='\t') _tabCount++; }
00022         void _determineIfDirty( void ) { for(const char *b=_beginning;*b;b++) if(!isspace(*b)) _type=DIRTY_LINE; }
00023         
00024 public:
00025         
00026         // getters:
00027         int getLength( void ){ return _length; }
00028         int getTabCount( void ){ return _tabCount; }
00029         // This is the read-only version:
00030         const char *getLine( void ){ return (const char *) _beginning; }
00031         // Use this when mucking around with (changing) the line:
00032         char *getMalleableLine( void ){ return _beginning; }
00033         // This is actually one past the end, on the null terminator:
00034         const char *getLineEnd( void ){ return _beginning + _length; }
00035         LINE_TYPE getType( void ){ return _type; }
00036         // setters:
00037         void setBeginning( char *beginning ){ 
00038                 _beginning=beginning; 
00039                 _determineLength(); 
00040                 _determineTabCount(); 
00041                 _determineIfDirty();
00042         }
00043         void setType( LINE_TYPE type ){ _type=type; }
00044         
00045         // Constructor:
00046         LineInformation(){
00047                 
00048                 _length=0;
00049                 _tabCount=0;
00050                 _beginning=NULL;
00051                 _type=EMPTY_LINE;
00052                 
00053         }
00054         
00055 };
00056 

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4