1 /* This file is part of qjson 2 * 3 * Copyright (C) 2010 Flavio Castelli <flavio@castelli.name> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License version 2.1, as published by the Free Software Foundation. 8 * 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef CMDLINEPARSER_H 22 #define CMDLINEPARSER_H 23 24 #include <QtCore/QCoreApplication> 25 #include <QtCore/QStringList> 26 27 #include <QJson/Serializer> 28 29 namespace QJson { 30 class CmdLineParser 31 { 32 public: 33 enum Result {Ok, Help, Error}; 34 35 CmdLineParser(const QStringList &arguments); 36 Result parse(); 37 38 void setIndentationMode(const IndentMode &mode); 39 IndentMode indentationMode() const; 40 QString helpFile() const; 41 QString file() const; 42 bool serialize(); 43 bool quiet(); 44 45 void showMessage(const QString &msg, bool error); 46 47 private: 48 bool hasMoreArgs() const; 49 const QString &nextArg(); 50 void handleSetIndentationMode(); 51 52 QStringList m_arguments; 53 int m_pos; 54 IndentMode m_indentationMode; 55 QString m_file; 56 bool m_serialize; 57 bool m_quiet; 58 static const QString m_helpMessage; 59 QString m_error; 60 }; 61 } 62 63 #endif 64 65