MNE-CPP  beta 1.0
command.h
Go to the documentation of this file.
1 //=============================================================================================================
36 #ifndef COMMAND_H
37 #define COMMAND_H
38 
39 //*************************************************************************************************************
40 //=============================================================================================================
41 // INCLUDES
42 //=============================================================================================================
43 
44 #include "rtcommand_global.h"
45 
47 
48 
49 //*************************************************************************************************************
50 //=============================================================================================================
51 // Qt INCLUDES
52 //=============================================================================================================
53 
54 #include <QObject>
55 #include <QList>
56 #include <QString>
57 #include <QVariant>
58 #include <QJsonObject>
59 #include <QSharedPointer>
60 #include <QDebug>
61 #include <QPair>
62 #include <QStringList>
63 
64 
65 //*************************************************************************************************************
66 //=============================================================================================================
67 // DEFINE NAMESPACE RTCOMMANDLIB
68 //=============================================================================================================
69 
70 namespace RTCOMMANDLIB
71 {
72 
73 static QVariant defaultVariant;
74 
75 
76 //=============================================================================================================
82 class RTCOMMANDSHARED_EXPORT Command: public QObject, public ICommand
83 {
84 Q_OBJECT
85 public:
86  typedef QSharedPointer<Command> SPtr;
87  typedef QSharedPointer<const Command> ConstSPtr;
88 
89  //=========================================================================================================
96  explicit Command(bool p_bIsJson = true, QObject *parent = 0);
97 
98  //=========================================================================================================
107  explicit Command(const QString &p_sCommand, const QJsonObject &p_qCommandContent, bool p_bIsJson = true, QObject *parent = 0);
108 
109  //=========================================================================================================
118  explicit Command(const QString &p_sCommand, const QString &p_sDescription, bool p_bIsJson = true, QObject *parent = 0);
119 
120  //=========================================================================================================
131  explicit Command(const QString &p_sCommand, const QString &p_sDescription,
132  const QStringList &p_qListParamNames, const QList<QVariant> &p_qListParamValues, bool p_bIsJson = true, QObject *parent = 0);
133 
134  //=========================================================================================================
144  explicit Command(const QString &p_sCommand, const QString &p_sDescription,
145  const QStringList &p_qListParamNames, const QList<QVariant> &p_qListParamValues, const QStringList &p_vecParameterDescriptions, bool p_bIsJson = true, QObject *parent = 0);
146 
147  //=========================================================================================================
153  Command(const Command &p_Command);
154 
155  //=========================================================================================================
159  virtual ~Command();
160 
161  //=========================================================================================================
167  inline QString command() const;
168 
169  //=========================================================================================================
175  inline quint32 count() const;
176 
177  //=========================================================================================================
183  inline QString description() const;
184 
185  //=========================================================================================================
191  virtual void execute();
192 
193  //=========================================================================================================
199  inline bool& isJson();
200 
201  //=========================================================================================================
207  inline QList<QString> pDescriptions() const;
208 
209  //=========================================================================================================
215  inline QList<QString> pNames() const;
216 
217  //=========================================================================================================
223  inline QList<QVariant>& pValues();
224 
225  //=========================================================================================================
231  void reply(const QString &p_sReply);
232 
233  //=========================================================================================================
237  void send();
238 
239  //=========================================================================================================
245  QJsonObject toJsonObject() const;
246 
247  //=========================================================================================================
253  QStringList toStringList() const;
254 
255  //=========================================================================================================
261  QString toStringReadySend() const;
262 
263  //=========================================================================================================
269  Command& operator= (const Command &rhs);
270 
271  //=========================================================================================================
279  QVariant& operator[] (const QString &key);
280 
281  //=========================================================================================================
289  QVariant& operator[] (qint32 idx);
290 
291  //=========================================================================================================
299  const QVariant operator[] (const QString &key) const;
300 
301 signals:
302  //=========================================================================================================
308  void executed(Command p_command);
309 
310 public:
311  QString m_sCommand;
312  QString m_sDescription;
313  QStringList m_qListParamNames;
314  QList<QVariant> m_qListParamValues;
315  QStringList m_qListParamDescriptions;
316  bool m_bIsJson;
317 };
318 
319 //*************************************************************************************************************
320 //=============================================================================================================
321 // INLINE DEFINITIONS
322 //=============================================================================================================
323 
324 inline QString Command::command() const
325 {
326  return m_sCommand;
327 }
328 
329 
330 //*************************************************************************************************************
331 
332 inline quint32 Command::count() const
333 {
334  return m_qListParamValues.size();
335 }
336 
337 
338 //*************************************************************************************************************
339 
340 inline QString Command::description() const
341 {
342  return m_sDescription;
343 }
344 
345 
346 //*************************************************************************************************************
347 
348 inline bool& Command::isJson()
349 {
350  return m_bIsJson;
351 }
352 
353 
354 //*************************************************************************************************************
355 
356 inline QList<QString> Command::pDescriptions() const
357 {
358  return m_qListParamDescriptions;
359 }
360 
361 //*************************************************************************************************************
362 
363 inline QList<QString> Command::pNames() const
364 {
365  return m_qListParamNames;
366 }
367 
368 //*************************************************************************************************************
369 
370 inline QList<QVariant>& Command::pValues()
371 {
372  return m_qListParamValues;
373 }
374 
375 
376 } // NAMESPACE
377 
378 #endif // COMMAND_H
QSharedPointer< const ICommand > ConstSPtr
QList< QString > pNames() const
Definition: command.h:363
QList< QString > pDescriptions() const
Definition: command.h:356
#define RTCOMMANDSHARED_EXPORT
Contains declarations of the command design pattern: ICommand interface.
quint32 count() const
Definition: command.h:332
QSharedPointer< ICommand > SPtr
QList< QVariant > & pValues()
Definition: command.h:370
QString description() const
Definition: command.h:340
QString command() const
Definition: command.h:324
RtCommand library export/import macros.
The ICommand interface provides the base class of every command of the command design pattern...