Browse Source

Rename gidToString as gidToHex, add hexToGid and isNull

Tatsuhiro Tsujikawa 12 năm trước cách đây
mục cha
commit
8f659f49ec
2 tập tin đã thay đổi với 21 bổ sung2 xóa
  1. 16 1
      src/aria2api.cc
  2. 5 1
      src/includes/aria2/aria2.h

+ 16 - 1
src/aria2api.cc

@@ -109,11 +109,26 @@ int run(Session* session, RUN_MODE mode)
   return e->run(mode == RUN_ONCE);
 }
 
-std::string gidToString(const A2Gid& gid)
+std::string gidToHex(const A2Gid& gid)
 {
   return GroupId::toHex(gid);
 }
 
+A2Gid hexToGid(const std::string& hex)
+{
+  A2Gid gid;
+  if(GroupId::toNumericId(gid, hex.c_str()) == 0) {
+    return gid;
+  } else {
+    return 0;
+  }
+}
+
+bool isNull(const A2Gid& gid)
+{
+  return gid == 0;
+}
+
 namespace {
 template<typename InputIterator, typename Pred>
 void apiGatherOption

+ 5 - 1
src/includes/aria2/aria2.h

@@ -107,7 +107,11 @@ enum RUN_MODE {
 int run(Session* session, RUN_MODE mode);
 
 // Returns textual representation of the |gid|.
-std::string gidToString(const A2Gid& gid);
+std::string gidToHex(const A2Gid& gid);
+// Returns GID converted from the textual representation |hex|.
+A2Gid hexToGid(const std::string& hex);
+// Returns true if the |gid| is invalid.
+bool isNull(const A2Gid& gid);
 
 // This method adds new HTTP(S)/FTP/BitTorrent Magnet URI.  On
 // successful return, the |gid| includes the GID of newly added