~ubuntu-branches/ubuntu/intrepid/gsmlib/intrepid

« back to all changes in this revision

Viewing changes to gsmlib/gsm_parser.h

  • Committer: Bazaar Package Importer
  • Author(s): Mikael Hedin
  • Date: 2002-01-24 12:59:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020124125907-b7qkpokx5283jdpu
Tags: upstream-1.8
ImportĀ upstreamĀ versionĀ 1.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// *************************************************************************
 
2
// * GSM TA/ME library
 
3
// *
 
4
// * File:    gsm_parser.h
 
5
// *
 
6
// * Purpose: Parser to parse MA/TA result strings
 
7
// *
 
8
// * Author:  Peter Hofmann (software@pxh.de)
 
9
// *
 
10
// * Created: 13.5.1999
 
11
// *************************************************************************
 
12
 
 
13
#ifndef GSM_PARSER_H
 
14
#define GSM_PARSER_H
 
15
 
 
16
#include <gsmlib/gsm_util.h>
 
17
#include <gsmlib/gsm_error.h>
 
18
#include <string>
 
19
#include <vector>
 
20
 
 
21
using namespace std;
 
22
 
 
23
namespace gsmlib
 
24
{
 
25
  class Parser : public RefBase
 
26
  {
 
27
  private:
 
28
    unsigned int _i;            // index into _s, next character
 
29
    string _s;                  // string to parse
 
30
    bool _eos;                  // true if end-of-string reached in nextChar()
 
31
 
 
32
    // return next character or -1 if end of string
 
33
    int nextChar(bool skipWhiteSpace = true);
 
34
    
 
35
    // "puts back" a character
 
36
    void putBackChar() {if (! _eos) --_i;}
 
37
 
 
38
    // check for empty parameter (ie. "," or end of string)
 
39
    // skips white space
 
40
    // returns true if no parameter
 
41
    // or throw an GsmException if allowNoParameter == false
 
42
    bool checkEmptyParameter(bool allowNoParameter) throw(GsmException);
 
43
    
 
44
    // parse a string (like "string")
 
45
    // throw an exception if not well-formed
 
46
    string parseString2(bool stringWithQuotationMarks) throw(GsmException);
 
47
 
 
48
    // parse a int (like 1234)
 
49
    // throw an exception if not well-formed
 
50
    int parseInt2() throw(GsmException);
 
51
 
 
52
    // throw a parser exception
 
53
    void throwParseException(string message = "") throw(GsmException);
 
54
 
 
55
  public:
 
56
    Parser(string s);
 
57
    
 
58
    // the following functions skip white space
 
59
    // parse a character, if absent throw a GsmException
 
60
    // return false if allowNoChar == true and character not encountered
 
61
    bool parseChar(char c, bool allowNoChar = false) throw(GsmException);
 
62
 
 
63
    // parse a list of the form "("ABC", DEF")"
 
64
    // the list can be empty (ie. == "" ) if allowNoList == true
 
65
    vector<string> parseStringList(bool allowNoList = false)
 
66
      throw(GsmException);
 
67
 
 
68
    // parse a list of the form "(12, 14)" or "(1-4, 10)"
 
69
    // the result is returned as a bit vector where for each integer
 
70
    // in the list and/or range(s) a bit is set
 
71
    // the list can be empty (ie. == "") if allowNoList == true
 
72
    vector<bool> parseIntList(bool allowNoList = false)
 
73
      throw(GsmException);
 
74
 
 
75
    // parse an integer range of the form "(1-125)"
 
76
    // the range may be absent if allowNoRange == true
 
77
    // then IntRange::_high and _low are set to NOT_SET
 
78
    IntRange parseRange(bool allowNoRange = false)
 
79
      throw(GsmException);
 
80
    
 
81
    // parse an integer of the form "1234"
 
82
    // allow absent int if allowNoInt == true
 
83
    // then it returns NOT_SET
 
84
    int parseInt(bool allowNoInt = false) throw(GsmException);
 
85
 
 
86
    // parse a string of the form ""string""
 
87
    // allow absent string if allowNoString == true
 
88
    // then it returns ""
 
89
    // if stringWithQuotationMarks == true the string may contain """
 
90
    // the string is then parsed till the end of the line
 
91
    string parseString(bool allowNoString = false,
 
92
                       bool stringWithQuotationMarks = false)
 
93
      throw(GsmException);
 
94
 
 
95
    // parse a single ","
 
96
    // the comma may be absent if allowNoComma == true
 
97
    // returns true if there was a comma
 
98
    bool parseComma(bool allowNoComma = false) throw(GsmException);
 
99
    
 
100
    // parse till end of line, return result without whitespace
 
101
    string parseEol() throw(GsmException);
 
102
 
 
103
    // check that end of line is reached
 
104
    void checkEol() throw(GsmException);
 
105
 
 
106
    // return string till end of line without whitespace
 
107
    // (does not change internal state)
 
108
    string getEol();
 
109
  };
 
110
};
 
111
 
 
112
#endif // GSM_PARSER_H