[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1735: Add a couple methods to retrieve the unparsed contents of a (in trunk: . src/control)



Author: edmanm
Date: 2007-05-13 03:23:57 -0400 (Sun, 13 May 2007)
New Revision: 1735

Modified:
   trunk/
   trunk/src/control/controlreply.cpp
   trunk/src/control/controlreply.h
   trunk/src/control/replyline.cpp
   trunk/src/control/replyline.h
Log:
 r1837@adrastea:  edmanm | 2007-05-13 03:04:24 -0400
 Add a couple methods to retrieve the unparsed contents of a control reply,
 make some methods const that can be const, and clean up some comments from the
 days before we played the Doxygen game.



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /vidalia/local/trunk [r1837] on 54b3572a-7227-0410-958f-53ecd705b71a

Modified: trunk/src/control/controlreply.cpp
===================================================================
--- trunk/src/control/controlreply.cpp	2007-05-11 18:31:05 UTC (rev 1734)
+++ trunk/src/control/controlreply.cpp	2007-05-13 07:23:57 UTC (rev 1735)
@@ -41,36 +41,48 @@
 
 /** Returns the requested line from this reply */
 ReplyLine
-ControlReply::getLine(int idx)
+ControlReply::getLine(int idx) const
 {
   return _lines.at(idx);
 }
 
 /** Returns all lines for this reply */
 QList<ReplyLine>
-ControlReply::getLines()
+ControlReply::getLines() const
 {
   return _lines;
 }
 
 /** Returns the status of the first line in the reply */
 QString
-ControlReply::getStatus()
+ControlReply::getStatus() const
 {
   return getLine().getStatus();
 }
 
 /** Returns the message of the first line in the reply */
 QString
-ControlReply::getMessage()
+ControlReply::getMessage() const
 {
   return getLine().getMessage();
 }
 
 /** Returns the data for the first line in the reply. */
 QStringList
-ControlReply::getData()
+ControlReply::getData() const
 {
   return getLine().getData();
 }
 
+/** Returns the entire contents of the control reply. */
+QString
+ControlReply::toString() const
+{
+  QString str;
+  foreach (ReplyLine line, _lines) {
+    str.append(line.toString());
+    str.append("\n");
+  }
+  return str.trimmed();
+}
+

Modified: trunk/src/control/controlreply.h
===================================================================
--- trunk/src/control/controlreply.h	2007-05-11 18:31:05 UTC (rev 1734)
+++ trunk/src/control/controlreply.h	2007-05-13 07:23:57 UTC (rev 1735)
@@ -42,16 +42,18 @@
   void appendLine(ReplyLine line);
 
   /** Returns a single line from this reply */
-  ReplyLine getLine(int idx = 0);
+  ReplyLine getLine(int idx = 0) const;
   /** Returns all lines for this reply */
-  QList<ReplyLine> getLines();
+  QList<ReplyLine> getLines() const;
   
   /** Returns the status of the first line in the reply */
-  QString getStatus();
+  QString getStatus() const;
   /** Returns the messasge of the first line in the reply */
-  QString getMessage();
+  QString getMessage() const;
   /** Returns the data for the first line in the reply. */
-  QStringList getData();
+  QStringList getData() const;
+  /** Returns the entire contents of the control reply. */
+  QString toString() const;
 
 private:
   QList<ReplyLine> _lines;

Modified: trunk/src/control/replyline.cpp
===================================================================
--- trunk/src/control/replyline.cpp	2007-05-11 18:31:05 UTC (rev 1734)
+++ trunk/src/control/replyline.cpp	2007-05-13 07:23:57 UTC (rev 1735)
@@ -55,28 +55,28 @@
   _status = status;
 }
 
-/** Get the status code for this reply line. */
+/** Returns the status code for this reply line. */
 QString
-ReplyLine::getStatus()
+ReplyLine::getStatus() const
 {
   return _status;
 }
 
-/** Set the message for this reply line */
+/** Sets the ReplyText message this reply line to <b>msg</b>. */
 void
 ReplyLine::setMessage(QString msg)
 {
   _message = unescape(msg);
 }
 
-/** Get the message for this reply line */
+/** Returns the ReplyText portion of this reply line. */
 QString
-ReplyLine::getMessage()
+ReplyLine::getMessage() const
 {
   return _message;
 }
 
-/** Add some data to this line */
+/** Appends <b>data</b> to this reply line. */
 void
 ReplyLine::appendData(QString data)
 {
@@ -85,12 +85,13 @@
 
 /** Returns a QStringList of all data lines for this reply line */
 QStringList
-ReplyLine::getData()
+ReplyLine::getData() const
 {
   return _data;
 }
 
-/** Unescapes characters in the given string */
+/** Unescapes special characters in <b>str</b> and returns the unescaped
+ * result. */
 QString
 ReplyLine::unescape(QString str)
 {
@@ -103,3 +104,14 @@
   return str.trimmed();
 }
 
+QString
+ReplyLine::toString() const
+{
+  QString str = _status + " " + _message;
+  if (!_data.isEmpty()) {
+    str.append("\n");
+    str.append(_data.join("\n"));
+  }
+  return str;
+}
+

Modified: trunk/src/control/replyline.h
===================================================================
--- trunk/src/control/replyline.h	2007-05-11 18:31:05 UTC (rev 1734)
+++ trunk/src/control/replyline.h	2007-05-13 07:23:57 UTC (rev 1735)
@@ -38,25 +38,33 @@
   ReplyLine(QString status, QString message);
   ReplyLine(QString status, QString message, QString data);
 
-  /* Get/set the status for this reply line */
+  /** Set the status code to <b>status</b>. */
   void setStatus(QString status);
-  QString getStatus();
+  /** Returns the status code for this reply line. */
+  QString getStatus() const;
 
-  /** Get/set the message for this reply line */
+  /** Sets the ReplyText message this reply line to <b>msg</b>. */
   void setMessage(QString msg);
-  QString getMessage();
+  /** Returns the ReplyText portion of this reply line. */
+  QString getMessage() const;
 
-  /* append/retrieve the data for this reply line (could be empty) */
+  /** Appends <b>data</b> to this reply line. */
   void appendData(QString data);
-  QStringList getData();
+  /** Returns a QStringList of all data lines for this reply line. */
+  QStringList getData() const;
+  
+  /** Returns the entire contents of this reply line, including the status,
+   * message, and any extra data. */
+  QString toString() const;
 
 private:
-  /* Unescape characters in the supplied string */
-  QString unescape(QString str);
+  /** Unescapes special characters in <b>str</b> and returns the unescaped
+   * result. */
+  static QString unescape(QString str);
   
-  QString _status;
-  QString _message;
-  QStringList _data;
+  QString _status;    /**< Response status code. */
+  QString _message;   /**< ReplyText portion of this reply line. */
+  QStringList _data;  /**< Contents of any DataReplyLines in this line. */
 };
 
 #endif