PageRenderTime 22ms CodeModel.GetById 6ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llinventory/llinventory.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 298 lines | 154 code | 30 blank | 114 comment | 0 complexity | 53e09e2ef656bd2eb5e13866d8a05c9d MD5 | raw file
  1/** 
  2 * @file llinventory.h
  3 * @brief LLInventoryItem and LLInventoryCategory class declaration.
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLINVENTORY_H
 28#define LL_LLINVENTORY_H
 29
 30#include "lldarray.h"
 31#include "llfoldertype.h"
 32#include "llinventorytype.h"
 33#include "llmemtype.h"
 34#include "llpermissions.h"
 35#include "llrefcount.h"
 36#include "llsaleinfo.h"
 37#include "llsd.h"
 38#include "lluuid.h"
 39
 40class LLMessageSystem;
 41
 42//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 43// Class LLInventoryObject
 44//
 45//   Base class for anything in the user's inventory.   Handles the common code 
 46//   between items and categories. 
 47//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 48class LLInventoryObject : public LLRefCount
 49{
 50public:
 51	typedef std::list<LLPointer<LLInventoryObject> > object_list_t;
 52
 53	//--------------------------------------------------------------------
 54	// Initialization
 55	//--------------------------------------------------------------------
 56public:
 57	MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
 58	LLInventoryObject();
 59	LLInventoryObject(const LLUUID& uuid, 
 60					  const LLUUID& parent_uuid,
 61					  LLAssetType::EType type, 
 62					  const std::string& name);
 63	void copyObject(const LLInventoryObject* other); // LLRefCount requires custom copy
 64protected:
 65	virtual ~LLInventoryObject();
 66
 67	//--------------------------------------------------------------------
 68	// Accessors
 69	//--------------------------------------------------------------------
 70public:
 71	virtual const LLUUID& getUUID() const; // inventoryID that this item points to
 72	virtual const LLUUID& getLinkedUUID() const; // inventoryID that this item points to, else this item's inventoryID
 73	const LLUUID& getParentUUID() const;
 74	virtual const std::string& getName() const;
 75	virtual LLAssetType::EType getType() const;
 76	LLAssetType::EType getActualType() const; // bypasses indirection for linked items
 77	BOOL getIsLinkType() const;
 78	
 79	//--------------------------------------------------------------------
 80	// Mutators
 81	//   Will not call updateServer
 82	//--------------------------------------------------------------------
 83public:
 84	void setUUID(const LLUUID& new_uuid);
 85	virtual void rename(const std::string& new_name);
 86	void setParent(const LLUUID& new_parent);
 87	void setType(LLAssetType::EType type);
 88
 89private:
 90	// in place correction for inventory name string
 91	void correctInventoryName(std::string& name);
 92
 93	//--------------------------------------------------------------------
 94	// File Support
 95	//   Implemented here so that a minimal information set can be transmitted
 96	//   between simulator and viewer.
 97	//--------------------------------------------------------------------
 98public:
 99	// virtual BOOL importFile(LLFILE* fp);
100	virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
101	virtual BOOL importLegacyStream(std::istream& input_stream);
102	virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
103
104	virtual void removeFromServer();
105	virtual void updateParentOnServer(BOOL) const;
106	virtual void updateServer(BOOL) const;
107
108	//--------------------------------------------------------------------
109	// Member Variables
110	//--------------------------------------------------------------------
111protected:
112	LLUUID mUUID;
113	LLUUID mParentUUID; // Parent category.  Root categories have LLUUID::NULL.
114	LLAssetType::EType mType;
115	std::string mName;
116};
117
118//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
119// Class LLInventoryItem
120//
121//   An item in the current user's inventory.
122//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123class LLInventoryItem : public LLInventoryObject
124{
125public:
126	typedef LLDynamicArray<LLPointer<LLInventoryItem> > item_array_t;
127
128	//--------------------------------------------------------------------
129	// Initialization
130	//--------------------------------------------------------------------
131public:
132	MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
133	LLInventoryItem(const LLUUID& uuid,
134					const LLUUID& parent_uuid,
135					const LLPermissions& permissions,
136					const LLUUID& asset_uuid,
137					LLAssetType::EType type,
138					LLInventoryType::EType inv_type,
139					const std::string& name, 
140					const std::string& desc,
141					const LLSaleInfo& sale_info,
142					U32 flags,
143					S32 creation_date_utc);
144	LLInventoryItem();
145	// Create a copy of an inventory item from a pointer to another item
146	// Note: Because InventoryItems are ref counted, reference copy (a = b)
147	// is prohibited
148	LLInventoryItem(const LLInventoryItem* other);
149	virtual void copyItem(const LLInventoryItem* other); // LLRefCount requires custom copy
150	void generateUUID() { mUUID.generate(); }
151protected:
152	~LLInventoryItem(); // ref counted
153	
154	//--------------------------------------------------------------------
155	// Accessors
156	//--------------------------------------------------------------------
157public:
158	virtual const LLUUID& getLinkedUUID() const;
159	virtual const LLPermissions& getPermissions() const;
160	virtual const LLUUID& getCreatorUUID() const;
161	virtual const LLUUID& getAssetUUID() const;
162	virtual const std::string& getDescription() const;
163	virtual const LLSaleInfo& getSaleInfo() const;
164	virtual LLInventoryType::EType getInventoryType() const;
165	virtual U32 getFlags() const;
166	virtual time_t getCreationDate() const;
167	virtual U32 getCRC32() const; // really more of a checksum.
168	
169	//--------------------------------------------------------------------
170	// Mutators
171	//   Will not call updateServer and will never fail
172	//   (though it may correct to sane values)
173	//--------------------------------------------------------------------
174public:
175	void setAssetUUID(const LLUUID& asset_id);
176	void setDescription(const std::string& new_desc);
177	void setSaleInfo(const LLSaleInfo& sale_info);
178	void setPermissions(const LLPermissions& perm);
179	void setInventoryType(LLInventoryType::EType inv_type);
180	void setFlags(U32 flags);
181	void setCreationDate(time_t creation_date_utc);
182	void setCreator(const LLUUID& creator); // only used for calling cards
183
184	// Check for changes in permissions masks and sale info
185	// and set the corresponding bits in mFlags.
186	void accumulatePermissionSlamBits(const LLInventoryItem& old_item);
187
188	// Put this inventory item onto the current outgoing mesage.
189	// Assumes you have already called nextBlock().
190	virtual void packMessage(LLMessageSystem* msg) const;
191
192	// Returns TRUE if the inventory item came through the network correctly.
193	// Uses a simple crc check which is defeatable, but we want to detect 
194	// network mangling somehow.
195	virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
196
197	//--------------------------------------------------------------------
198	// File Support
199	//--------------------------------------------------------------------
200public:
201	virtual BOOL importFile(LLFILE* fp);
202	virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
203	virtual BOOL importLegacyStream(std::istream& input_stream);
204	virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
205
206	//--------------------------------------------------------------------
207	// Helper Functions
208	//--------------------------------------------------------------------
209public:
210	// Pack all information needed to reconstruct this item into the given binary bucket.
211	S32 packBinaryBucket(U8* bin_bucket, LLPermissions* perm_override = NULL) const;
212	void unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size);
213	LLSD asLLSD() const;
214	void asLLSD( LLSD& sd ) const;
215	bool fromLLSD(const LLSD& sd);
216
217	//--------------------------------------------------------------------
218	// Member Variables
219	//--------------------------------------------------------------------
220protected:
221	LLPermissions mPermissions;
222	LLUUID mAssetUUID;
223	std::string mDescription;
224	LLSaleInfo mSaleInfo;
225	LLInventoryType::EType mInventoryType;
226	U32 mFlags;
227	time_t mCreationDate; // seconds from 1/1/1970, UTC
228};
229
230//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
231// Class LLInventoryCategory
232//
233//   A category/folder of inventory items. Users come with a set of default 
234//   categories, and can create new ones as needed.
235//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
236class LLInventoryCategory : public LLInventoryObject
237{
238public:
239	typedef LLDynamicArray<LLPointer<LLInventoryCategory> > cat_array_t;
240
241	//--------------------------------------------------------------------
242	// Initialization
243	//--------------------------------------------------------------------
244public:
245	MEM_TYPE_NEW(LLMemType::MTYPE_INVENTORY);
246	LLInventoryCategory(const LLUUID& uuid, const LLUUID& parent_uuid,
247						LLFolderType::EType preferred_type,
248						const std::string& name);
249	LLInventoryCategory();
250	LLInventoryCategory(const LLInventoryCategory* other);
251	void copyCategory(const LLInventoryCategory* other); // LLRefCount requires custom copy
252protected:
253	~LLInventoryCategory();
254
255	//--------------------------------------------------------------------
256	// Accessors And Mutators
257	//--------------------------------------------------------------------
258public:
259	LLFolderType::EType getPreferredType() const;
260	void setPreferredType(LLFolderType::EType type);
261	LLSD asLLSD() const;
262	bool fromLLSD(const LLSD& sd);
263
264	//--------------------------------------------------------------------
265	// Messaging
266	//--------------------------------------------------------------------
267public:
268	virtual void packMessage(LLMessageSystem* msg) const;
269	virtual void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
270
271	//--------------------------------------------------------------------
272	// File Support
273	//--------------------------------------------------------------------
274public:
275	virtual BOOL importFile(LLFILE* fp);
276	virtual BOOL exportFile(LLFILE* fp, BOOL include_asset_key = TRUE) const;
277	virtual BOOL importLegacyStream(std::istream& input_stream);
278	virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const;
279
280	//--------------------------------------------------------------------
281	// Member Variables
282	//--------------------------------------------------------------------
283protected:
284	LLFolderType::EType	mPreferredType; // Type that this category was "meant" to hold (although it may hold any type).	
285};
286
287
288//-----------------------------------------------------------------------------
289// Convertors
290//
291//   These functions convert between structured data and an inventory
292//   item, appropriate for serialization.
293//-----------------------------------------------------------------------------
294LLSD ll_create_sd_from_inventory_item(LLPointer<LLInventoryItem> item);
295LLSD ll_create_sd_from_inventory_category(LLPointer<LLInventoryCategory> cat);
296LLPointer<LLInventoryCategory> ll_create_category_from_sd(const LLSD& sd_cat);
297
298#endif // LL_LLINVENTORY_H