Option.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #ifndef D_OPTION_H
  36. #define D_OPTION_H
  37. #include "common.h"
  38. #include <string>
  39. #include <vector>
  40. #include <memory>
  41. #include "prefs.h"
  42. namespace aria2 {
  43. class Option {
  44. private:
  45. std::vector<std::string> table_;
  46. std::vector<unsigned char> use_;
  47. std::shared_ptr<Option> parent_;
  48. public:
  49. Option();
  50. ~Option();
  51. Option(const Option& option);
  52. Option& operator=(const Option& option);
  53. void put(PrefPtr pref, const std::string& value);
  54. // Returns true if name is defined. Otherwise returns false. Note
  55. // that even if the value is a empty string, this method returns
  56. // true. If option is not defined in this object and parent_ is not
  57. // NULL, lookup parent_ to check |pref| is defined.
  58. bool defined(PrefPtr pref) const;
  59. // Just like defined(), but this function does not lookup parent_.
  60. bool definedLocal(PrefPtr pref) const;
  61. // Returns true if name is not defined or the value is a empty string.
  62. // Otherwise returns false.
  63. bool blank(PrefPtr pref) const;
  64. // Returns option value for |pref|. If the |pref| is not defined in
  65. // this object, parent_ is looked up.
  66. const std::string& get(PrefPtr pref) const;
  67. int32_t getAsInt(PrefPtr pref) const;
  68. int64_t getAsLLInt(PrefPtr pref) const;
  69. bool getAsBool(PrefPtr pref) const;
  70. double getAsDouble(PrefPtr pref) const;
  71. // Removes |pref| from this object. This function does not modify
  72. // parent_.
  73. void removeLocal(PrefPtr pref);
  74. // Removes |pref| from this object from all option hierarchy.
  75. void remove(PrefPtr pref);
  76. // Removes all option values from this object. This function does
  77. // not modify parent_.
  78. void clear();
  79. // Returns the option value table of this object. It does not
  80. // contain option values in parent_ and so forth.
  81. const std::vector<std::string>& getTable() const { return table_; }
  82. // Copy option values defined in option to this option. parent_ is
  83. // left unmodified for this object.
  84. void merge(const Option& option);
  85. // Sets parent Option object for this object.
  86. void setParent(const std::shared_ptr<Option>& parent);
  87. const std::shared_ptr<Option>& getParent() const;
  88. // Returns true if there is no option stored.
  89. bool emptyLocal() const;
  90. };
  91. } // namespace aria2
  92. #endif // D_OPTION_H