Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Parseit.h

Go to the documentation of this file.
00001 /********************************************************************
00002        Copyright (c) 2001, Lee Patterson & Ant Works Software
00003        http://ssobjects.sourceforge.net
00004 
00005        Original source from http://www.codeproject.com/datetime/dateclass.asp
00006        Copyright (c), Richard Stringer
00007 
00008        filename : Parseit.h
00009 
00010        changes  : 24-AUG-2000 Lee Patterson (lee@antws.com)
00011                   - Removed MFC code so it will compile under other 
00012                     platforms.
00013                   - Made more functions use const.
00014 
00015        notes    : Most of the date alogrithms used in this class 
00016                   can be found at:
00017                   http://www.capecod.net/~pbaum/date/date0.htm
00018 
00019 *********************************************************************/
00020 
00021 #ifndef __PARSEIT_H_
00022 #define __PARSEIT_H_
00023 
00024 #ifdef WIN32
00025 # define snprintf _snprintf             //make it linux like (NOTE: snprintf in Linux behaives a little different when you exceed the size
00026 #else
00027  typedef const char* LPCSTR;
00028  typedef char* LPSTR;
00029 #endif
00030 
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include "linkedlist.h"
00034 
00035 namespace ssobjects
00036 {
00037 
00039 //      class definition for the ParseField class
00041 //      this class is just a CString with some assignment and cast operators
00042 //      it is used to store a parsed field value and allow the data to be accessed
00043 //      thru casting the result to the wanted datatype
00044 //      ************************** ALLOWED OPERATIONS *********************************
00045 //      CParseField p;
00046 //      p="1234.12"             // assignment to LPCSTR
00047 //      CStrinf e=(LPCSTR)p;//  operator (LPCSTR)
00048 //      double d=(double)p;     //      d=1234.12       operator double 
00049 //      int n=(int)p;           //      n=1234  operator int
00051 class CParseField
00052 {
00053     public:
00054         CParseField() {};
00055         ~CParseField() {};
00056 
00057         operator int()          { return atoi(TheData);};
00058         operator long()         { return atol(TheData);};
00059         operator double()       { return atof(TheData);};
00060         operator LPCSTR()       { return (LPCSTR) TheData;}; const
00061         CParseField& operator =(LPCSTR s) {strcpy(TheData,s);return *this;};
00062         CParseField&  operator =(CParseField& s) {strcpy(TheData,s.TheData);return *this;};
00063         
00064 // Implementation
00065     protected:
00066         char TheData[80];
00067 };
00069 //      END OF CparseField DEFINITION AND CODE ( ALL FUNCTIONS HERE)
00071 
00072 
00074 //      class definition for the Parsing class
00076 class CParseIt
00077 {
00078   private:    //unused overloads
00079     CParseIt(const CParseIt&);
00080     CParseIt& operator=(const CParseIt&);
00081 
00082   public:
00083     CParseIt(bool Strip=false);
00084     CParseIt(LPCSTR Data,LPCSTR Sep=",",bool Strip=false);
00085     ~CParseIt();
00086 
00087     //  use default constructoe then call this function to open and use a file contaimning
00088     //  the data    
00089 #ifdef WIN32
00090     bool        ParseFile(LPCSTR lpzFileName,LPCSTR Sep=",");
00091 #endif
00092 // Attributes
00093   public:
00094 // Operations             
00095   protected:           
00096     bool                IsSeperator(char s);
00097 #ifdef WIN32
00098     bool                LoadFile(LPCSTR lpzFileName);
00099 #endif
00100         
00101   public:         
00102     //  returns the one based number of fields if 0 there are no fields
00103     int                 GetNumFields() {return NumFields;};
00104     //  returns the list of seperators
00105     LPCSTR              GetSeperator() {return Seperator;};
00106     //  sets the seperator list IE "|,*"
00107     void                SetSeperator(LPCSTR Sep) {strncpy(Seperator,Sep,9);};
00108     //  parse a object constructed bt the second constructor (data,sep);
00109     bool                Parse();
00110     //  parse a object created by the default constructor will call Parse();
00111     bool                Parse(LPCSTR Data,LPCSTR Sep=",",bool Strip=false);
00112     //  returns the 1 based field in a string
00113     bool                GetField(int nFNum,LPSTR Buff);
00114     //  will return the cparsefield object. This can be cast to the desired type
00115     //  by (int) (long) (double) (lpcstr)
00116     CParseField GetField(int n);
00117         
00118 // Implementation
00119   public:
00120     void ReSet();
00121 
00122   protected:
00123     bool                        StripQuotes;
00124     char                        Seperator[10];
00125     int                         NumFields;
00126     LinkedList<CParseField>     TheFields;      
00127     LPSTR                       TheData;
00128 };
00129 
00130 };
00131 
00132 #endif

Generated on Thu Nov 8 12:39:25 2001 for SimpleServerObjects by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001