hbinventoryclipboard.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @file hbinventoryclipboard.h
  3. * @brief HBInventoryClipboard class declaration
  4. * This is a full rewrite/expansion of LL's original LLInventoryClipboard class
  5. *
  6. * $LicenseInfo:firstyear=2012&license=viewergpl$
  7. *
  8. * Copyright (c) 2012-2023, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_HBINVENTORYCLIPBOARD_H
  34. #define LL_HBINVENTORYCLIPBOARD_H
  35. #include "hbfastmap.h"
  36. #include "llinventorytype.h"
  37. #include "lluuid.h"
  38. class LLInventoryItem;
  39. // Purely static class
  40. class HBInventoryClipboard
  41. {
  42. public:
  43. HBInventoryClipboard() = delete;
  44. ~HBInventoryClipboard() = delete;
  45. ///////////////////////////////////////////////////////////////////////////
  46. // Inventory objects management
  47. // Empties out the objects clipboard
  48. LL_INLINE static void reset()
  49. {
  50. sObjects.clear();
  51. sCutObjects.clear();
  52. }
  53. // Adds to the current list.
  54. LL_INLINE static void add(const LLUUID& object_id)
  55. {
  56. sObjects.emplace_back(object_id);
  57. }
  58. // Add for Cut operation
  59. LL_INLINE static void addCut(const LLUUID& object_id)
  60. {
  61. sCutObjects.emplace_back(object_id);
  62. }
  63. // Stores a single inventory object
  64. LL_INLINE static void store(const LLUUID& object_id)
  65. {
  66. reset();
  67. add(object_id);
  68. }
  69. // Stores an array of objects
  70. static void store(const uuid_vec_t& inventory_objects);
  71. // Gets the objects in the clipboard by copying them into the vector.
  72. static void retrieve(uuid_vec_t& inventory_objects);
  73. // Gets the objects in the clipboard by copying them into the vector.
  74. static void retrieveCuts(uuid_vec_t& inventory_objects);
  75. // These methods return true when object_id is in the corresponding
  76. // clipboard
  77. static bool isCopied(const LLUUID& object_id);
  78. static bool isCut(const LLUUID& object_id);
  79. // The following three methods return true if the clipboard contains
  80. // something that can be pasted.
  81. LL_INLINE static bool hasCopiedContents() { return !sObjects.empty(); }
  82. LL_INLINE static bool hasCutContents()
  83. {
  84. return !sCutObjects.empty();
  85. }
  86. LL_INLINE static bool hasContents()
  87. {
  88. return !sObjects.empty() || !sCutObjects.empty();
  89. }
  90. ///////////////////////////////////////////////////////////////////////////
  91. // Inventory assets management
  92. // Empties out the assets clipboard
  93. LL_INLINE static void resetAssets() { sAssets.clear(); }
  94. // Adds to the current list of assets. Also copies the asset Id to the text
  95. // clipboard unless false is passed for 'copy_id_to_text_clipboard'.
  96. // Note: if the asset Id is null, it is not stored/copied.
  97. static void addAsset(const LLUUID& asset_id, LLInventoryType::EType type,
  98. bool copy_id_to_text_clipboard = true);
  99. // Stores a single asset Id. Also copies the asset Id to the text clipboard
  100. // unless false is passed for 'copy_id_to_text_clipboard'.
  101. // Note: if the asset Id is null, it is not stored/copied.
  102. static void storeAsset(const LLUUID& asset_id, LLInventoryType::EType type,
  103. bool copy_id_to_text_clipboard = true);
  104. // Stores the asset Id associated with the passed inventory item. Also
  105. // copies the asset Id to the text clipboard unless false is passed for
  106. // 'copy_id_to_text_clipboard'.
  107. // Note: if the asset Id is null, it is not stored/copied.
  108. static void storeAsset(const LLInventoryItem* itemp,
  109. bool copy_id_to_text_clipboard = true);
  110. // Gets the assets of the specified inventory type stored in the clipboard
  111. // by copying their UUID into the vector.
  112. static void retrieveAssets(uuid_vec_t& inventory_assets,
  113. LLInventoryType::EType type);
  114. // Returns true if assets of the specified inventory type are stored.
  115. static bool hasAssets(LLInventoryType::EType type);
  116. private:
  117. static uuid_vec_t sObjects;
  118. static uuid_vec_t sCutObjects;
  119. typedef fast_hmap<LLUUID, LLInventoryType::EType> assets_map_t;
  120. static assets_map_t sAssets;
  121. };
  122. #endif // LL_HBINVENTORYCLIPBOARD_H