statechanges.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <apt-pkg/pkgcache.h>
  2. #include <apt-pkg/cacheset.h>
  3. #include <apt-pkg/macros.h>
  4. #include <memory>
  5. namespace APT
  6. {
  7. /** Simple wrapper class to abstract away the differences in storing different
  8. * states in different places potentially in different versions.
  9. */
  10. class APT_PUBLIC StateChanges
  11. {
  12. public:
  13. // getter/setter for the different states
  14. #define APT_GETTERSETTER(Name) \
  15. APT::VersionVector& Name(); \
  16. void Name(pkgCache::VerIterator const &Ver)
  17. APT_GETTERSETTER(Hold);
  18. APT_GETTERSETTER(Unhold);
  19. APT_GETTERSETTER(Install);
  20. APT_GETTERSETTER(Remove);
  21. APT_GETTERSETTER(Purge);
  22. APT::VersionVector& Error();
  23. #undef APT_GETTERSETTER
  24. // operate on all containers at once
  25. void clear();
  26. bool empty() const;
  27. /** commit the staged changes to the database(s).
  28. *
  29. * Makes the needed calls to store the requested states.
  30. * After this call the state containers will hold only versions
  31. * for which the storing operation succeeded. Versions where the
  32. * storing operation failed are collected in #Error(). Note that
  33. * error is an upper bound as states are changed in batches so it
  34. * isn't always clear which version triggered the failure exactly.
  35. *
  36. * @param DiscardOutput controls if stdout/stderr should be used
  37. * by subprocesses for (detailed) error reporting if needed.
  38. * @return \b false if storing failed, true otherwise.
  39. * Note that some states might be applied even if the whole operation failed.
  40. */
  41. bool Save(bool const DiscardOutput = false);
  42. StateChanges();
  43. StateChanges(StateChanges&&);
  44. StateChanges& operator=(StateChanges&&);
  45. ~StateChanges();
  46. private:
  47. class APT_HIDDEN Private;
  48. std::unique_ptr<Private> d;
  49. };
  50. }