[3e4acc]: libkwave / Parser.h Maximize Restore History

Download this file

Parser.h    146 lines (115 with data), 4.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/***************************************************************************
Parser.h - parser for Kwave's internal commands
-------------------
begin : Sat Feb 3 2001
copyright : (C) 2001 by Thomas Eschenbacher
email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef _PARSER_H_
#define _PARSER_H_
#include "config.h"
#include <QString>
#include <QStringList>
#include <kdemacros.h>
//*****************************************************************************
class KDE_EXPORT Parser
{
public:
/**
* Constructor. Parses the given string into an optional
* command part and a list of parameters.
*/
Parser(const QString &init);
/** Destructor. */
virtual ~Parser();
/** Returns the command part of the line */
inline QString command() {
return m_command;
}
/** Returns the complete list of parameters */
inline const QStringList &params() {
return m_param;
}
/** Returns true if the parameter list is not empty. */
inline bool hasParams() {
return (m_param.count() != 0);
}
/** Returns true if a list of commands was parsed */
inline bool hasMultipleCommands() {
return (m_commands.count() > 1);
}
/** Returns the list of commands */
inline QStringList commandList() { return m_commands; };
/** Returns true if the end of the parameter list has been reached. */
inline bool isDone () {
return (static_cast<int>(m_current) >= m_param.count());
}
/** Returns the number of parameters. */
inline unsigned int count() {
return m_param.count();
}
/**
* Returns the first parameter and sets the current
* position to the next.
*/
const QString &firstParam();
/**
* Returns the next parameter and increases the current
* position if not already at the end of the parameter
* list. If the end of the parameter list has been
* reached, the return value will be a zero-length string.
*/
const QString &nextParam();
/**
* Skips a parameter and advances the current position
* by one if the end has not already been reached.
*/
void skipParam();
/**
* Gets the next parameter through calling nextParam() and
* interpretes it as a "bool" value. It will recognize the
* strings "true" and "false" (not case-sensitive) and
* numeric values (true means not zero). On errors the
* return value will be false.
*/
bool toBool();
/**
* Gets the next parameter through calling nextParam() and
* interpretes it as an "int" value. On errors the
* return value will be zero.
*/
int toInt();
/**
* Gets the next parameter through calling nextParam() and
* interpretes it as an "unsigned int" value. On errors the
* return value will be zero.
*/
unsigned int toUInt();
/**
* Gets the next parameter through calling nextParam() and
* interpretes it as a "double" value. On errors the
* return value will be zero.
*/
double toDouble();
protected:
/** Splits a line into a list of commands */
QStringList splitCommands(QString &line);
private:
/** the command part of the line */
QString m_command;
/** list of parsed parameters */
QStringList m_param;
/** number of the "current" parameter */
unsigned int m_current;
/** if it has multiple commands, the list of command strings */
QStringList m_commands;
};
#endif /* _PARSER_H_ */