aptconfiguration.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. /** \class APT::Configuration
  4. * \brief Provide access methods to various configuration settings
  5. *
  6. * This class and their methods providing a layer around the usual access
  7. * methods with _config to ensure that settings are correct and to be able
  8. * to set defaults without the need to recheck it in every method again.
  9. */
  10. /*}}}*/
  11. #ifndef APT_CONFIGURATION_H
  12. #define APT_CONFIGURATION_H
  13. // Include Files /*{{{*/
  14. #include <string>
  15. #include <vector>
  16. #include <limits>
  17. /*}}}*/
  18. namespace APT {
  19. class Configuration { /*{{{*/
  20. public: /*{{{*/
  21. /** \brief Returns a vector of usable Compression Types
  22. *
  23. * Files can be compressed in various ways to decrease the size of the
  24. * download. Therefore the Acquiremethods support a few compression types
  25. * and some archives provide also a few different types. This option
  26. * group exists to give the user the choice to prefer one type over the
  27. * other (some compression types are very resource intensive - great if you
  28. * have a limited download, bad if you have a really lowpowered hardware.)
  29. *
  30. * This method ensures that the defaults are set and checks at runtime
  31. * if the type can be used. E.g. the current default is to prefer bzip2
  32. * over lzma and gz - if the bzip2 binary is not available it has not much
  33. * sense in downloading the bz2 file, therefore we will not return bz2 as
  34. * a usable compression type. The availability is checked with the settings
  35. * in the Dir::Bin group.
  36. *
  37. * \param Cached saves the result so we need to calculated it only once
  38. * this parameter should ony be used for testing purposes.
  39. *
  40. * \return a vector of the compression types in the preferred usage order
  41. */
  42. std::vector<std::string> static const getCompressionTypes(bool const &Cached = true);
  43. /** \brief Returns a vector of Language Codes
  44. *
  45. * Languages can be defined with their two or five chars long code.
  46. * This methods handles the various ways to set the preferred codes,
  47. * honors the environment and ensures that the codes are not listed twice.
  48. *
  49. * The special word "environment" will be replaced with the long and the short
  50. * code of the local settings and it will be insured that this will not add
  51. * duplicates. So in an german local the setting "environment, de_DE, en, de"
  52. * will result in "de_DE, de, en".
  53. *
  54. * Another special word is "none" which separates the preferred from all codes
  55. * in this setting. So setting and method can be used to get codes the user want
  56. * to see or to get all language codes APT (should) have Translations available.
  57. *
  58. * \param All return all codes or only codes for languages we want to use
  59. * \param Cached saves the result so we need to calculated it only once
  60. * this parameter should ony be used for testing purposes.
  61. * \param Locale don't get the locale from the system but use this one instead
  62. * this parameter should ony be used for testing purposes.
  63. *
  64. * \return a vector of (all) Language Codes in the preferred usage order
  65. */
  66. std::vector<std::string> static const getLanguages(bool const &All = false,
  67. bool const &Cached = true, char const ** const Locale = 0);
  68. /** \brief Are we interested in the given Language?
  69. *
  70. * \param Lang is the language we want to check
  71. * \param All defines if we check against all codes or only against used codes
  72. * \return true if we are interested, false otherwise
  73. */
  74. bool static const checkLanguage(std::string Lang, bool const All = false);
  75. /** \brief Returns a vector of Architectures we support
  76. *
  77. * \param Cached saves the result so we need to calculated it only once
  78. * this parameter should ony be used for testing purposes.
  79. *
  80. * \return a vector of Architectures in preferred order
  81. */
  82. std::vector<std::string> static const getArchitectures(bool const &Cached = true);
  83. /** \brief Are we interested in the given Architecture?
  84. *
  85. * \param Arch we want to check
  86. * \return true if we are interested, false otherwise
  87. */
  88. bool static const checkArchitecture(std::string const &Arch);
  89. /** \brief Representation of supported compressors */
  90. struct Compressor {
  91. std::string Name;
  92. std::string Extension;
  93. std::string Binary;
  94. std::vector<std::string> CompressArgs;
  95. std::vector<std::string> UncompressArgs;
  96. unsigned short Cost;
  97. Compressor(char const *name, char const *extension, char const *binary,
  98. char const *compressArg, char const *uncompressArg,
  99. unsigned short const cost);
  100. Compressor() : Cost(std::numeric_limits<unsigned short>::max()) {};
  101. };
  102. /** \brief Return a vector of Compressors supported for data.tar's
  103. *
  104. * \param Cached saves the result so we need to calculated it only once
  105. * this parameter should ony be used for testing purposes.
  106. *
  107. * \return a vector of Compressors
  108. */
  109. std::vector<Compressor> static const getCompressors(bool const Cached = true);
  110. /** \brief Return a vector of extensions supported for data.tar's */
  111. std::vector<std::string> static const getCompressorExtensions();
  112. /*}}}*/
  113. private: /*{{{*/
  114. void static setDefaultConfigurationForCompressors();
  115. /*}}}*/
  116. };
  117. /*}}}*/
  118. }
  119. #endif