rinosh 2 / NextTrainFileLib
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NextTrainFile.h Source File

NextTrainFile.h

00001 ///////////////////////////////////////////////////////////////////////////////
00002 // NextTrainFile: NextTrain file parser   by rinos 2010
00003 ///////////////////////////////////////////////////////////////////////////////
00004 
00005 #ifndef __NEXTTRAIN_FILE_H__
00006 #define __NEXTTRAIN_FILE_H__
00007 
00008 #include "mbed.h"
00009 
00010 class NextTrainFile {
00011     // defines /////////////////////////////////////////////////////////////////
00012 public:
00013     enum LINE_TYPE {
00014         LINE_COMMENT,
00015         LINE_TITLE,
00016         LINE_TIME,
00017         LINE_WEEK,
00018         LINE_OPTION
00019     };
00020     
00021     static const int HOUR_DIV       = 3;    // Last Train AM 03:00
00022     
00023     static const int MAX_TITLE      = 80;
00024     static const int MAX_OPTION     = 80;
00025     
00026     static const int MAX_OPTIONID   = 52;   // A-Za-z
00027     static const int MAX_OPTBUF     = 256;  // m_index (unsigned char) range
00028 
00029     struct NextInfo {
00030         char  m_title [MAX_TITLE];
00031         char  m_option[MAX_OPTION];
00032         unsigned int   m_hour;
00033         unsigned int   m_min;
00034         signed   int   m_diff;
00035         
00036         NextInfo() : m_hour(0), m_min(0), m_diff(0) {
00037             m_title[0]  = 0;
00038             m_option[0] = 0;
00039         }
00040     };
00041 
00042     // error code
00043     typedef enum {
00044         S_SUCCESS,
00045         S_OPEN_ERROR,
00046         S_ALREADY_OPEN,
00047         S_OPTION_OVERFLOW,
00048 
00049         S_NO_TRAIN,
00050         S_INVALID_OPTION_ID,
00051     } Status;
00052 
00053     // internal member/method //////////////////////////////////////////////////
00054 private:
00055     FILE*    m_fp;
00056     NextInfo m_ni;
00057     bool     m_shortopt;
00058     char     m_delim;
00059 
00060     unsigned char m_index [MAX_OPTIONID];
00061     char          m_optbuf[MAX_OPTBUF];
00062     
00063     // Invalid method
00064 protected:
00065     NextTrainFile(const NextTrainFile& v);
00066     const NextTrainFile& operator =(const NextTrainFile& v);
00067 
00068 public:
00069     NextTrainFile(const char* ntFile = 0);
00070     ~NextTrainFile();
00071 
00072     Status open(const char* ntFile);
00073     Status close();
00074     void   use_shortopt(bool f) { m_shortopt = f; }
00075     void   set_delim   (char d) { m_delim    = d; }
00076     Status search(time_t dt = 0, int offset = 0);
00077     const NextInfo* next() const { return &m_ni; }
00078 };
00079 
00080 #endif