statechanges.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. APT::VersionVector& Hold();
  15. void Hold(pkgCache::VerIterator const &Ver);
  16. APT::VersionVector& Unhold();
  17. void Unhold(pkgCache::VerIterator const &Ver);
  18. APT::VersionVector& Error();
  19. // forgets all unsaved changes
  20. void Discard();
  21. /** commit the staged changes to the database(s).
  22. *
  23. * Makes the needed calls to store the requested states.
  24. * After this call the state containers will hold only versions
  25. * for which the storing operation succeeded. Versions where the
  26. * storing operation failed are collected in #Error(). Note that
  27. * error is an upper bound as states are changed in batches so it
  28. * isn't always clear which version triggered the failure exactly.
  29. *
  30. * @param DiscardOutput controls if stdout/stderr should be used
  31. * by subprocesses for (detailed) error reporting if needed.
  32. * @return \b false if storing failed, true otherwise.
  33. * Note that some states might be applied even if the whole operation failed.
  34. */
  35. bool Save(bool const DiscardOutput = false);
  36. StateChanges();
  37. StateChanges(StateChanges&&);
  38. StateChanges& operator=(StateChanges&&);
  39. ~StateChanges();
  40. private:
  41. class APT_HIDDEN Private;
  42. std::unique_ptr<Private> d;
  43. };
  44. }