1 /*
2     Copyright (c) 2008-2009 NetAllied Systems GmbH
3 
4     This file is part of COLLADASaxFrameworkLoader.
5 
6     Licensed under the MIT Open Source License,
7     for details please see LICENSE file or the website
8     http://www.opensource.org/licenses/mit-license.php
9 */
10 
11 #ifndef __COLLADASAXFWL_SIDADDRESS_H__
12 #define __COLLADASAXFWL_SIDADDRESS_H__
13 
14 #include "COLLADASaxFWLPrerequisites.h"
15 
16 #include "COLLADABUURI.h"
17 
18 
19 namespace COLLADASaxFWL
20 {
21 
22     /** Represents the  address of an sid. */
23 	class SidAddress
24 	{
25 	public:
26 		typedef std::vector<String/*sid*/> SidList;
27 
28 		enum MemberSelection
29 		{
30 			MEMBER_SELECTION_NONE,			//!< No member is selected, all values are targeted ("id/sid")
31 			MEMBER_SELECTION_NAME,			//!< A member is selected by name, evaluate mMemberSelection ("id/sid.name")
32 			MEMBER_SELECTION_ONE_INDEX,		//!< A member is selected by an index, evaluate mFirstIndex ("id/sid(0)")
33 			MEMBER_SELECTION_TWO_INDICES	//!< A member is selected by two indices, evaluate mFirstIndex and mSecondIndex ("id/sid(0)(3)")
34 		};
35 	private:
36 		/** The id of the starting point. Empty, if address is relative.*/
37 		String mId;
38 
39 		/** List of all the sid in the address, starting with the first.*/
40 		SidList mSids;
41 
42 		/** Defines the method of member selection.*/
43 		MemberSelection mMemberSelection;
44 
45 		/** The name of the member selection.*/
46 		String mMemberSelectionName;
47 
48 		/** The first index of a matrix.*/
49 		size_t mFirstIndex;
50 
51 		/** The second index of a matrix.*/
52 		size_t mSecondIndex;
53 
54 		/** True, if the address is a valid sid address, false otherwise.*/
55 		bool mIsValid;
56 
57 	public:
58 
59 		/** Constructor, invalid SidAddress. */
60 		SidAddress( );
61 
62 		/** Constructor. */
63 		SidAddress( const String& sidAddress );
64 
65 		/** Constructor. */
66 		SidAddress( const COLLADABU::URI& id, const String& sid);
67 
68 		/** Constructor. */
69 		SidAddress( const COLLADABU::URI& id);
70 
71         /** Destructor. */
72 		virtual ~SidAddress();
73 
74 		/** The id of the starting point. Empty, if address is relative.*/
getId()75 		const String& getId() const { return mId; }
76 
77 		/** List of all the sid in the address, starting with the first.*/
getSids()78 		const SidList& getSids() const { return mSids; }
79 
80 		/** Appends @a sid to the list of sids.*/
appendSid(const String & sid)81 		void appendSid( const String& sid) { mSids.push_back(sid); }
82 
83 		/** Defines the method of member selection.*/
getMemberSelection()84 		MemberSelection getMemberSelection() const { return mMemberSelection; }
85 
86 		/** Defines the method of member selection.*/
setMemberSelection(MemberSelection memberSelection)87 		void setMemberSelection( MemberSelection memberSelection ) { mMemberSelection = memberSelection; }
88 
89 		/** The name of the member selection.*/
getMemberSelectionName()90 		const String& getMemberSelectionName() const { return mMemberSelectionName; }
91 
92 		/** The name of the member selection.*/
setMemberSelectionName(const String & memberSelectionName)93 		void setMemberSelectionName( const String& memberSelectionName) { mMemberSelectionName = memberSelectionName; }
94 
95 		/** The first index of a matrix.*/
getFirstIndex()96 		size_t getFirstIndex() const { return mFirstIndex; }
97 
98 		/** The first index of a matrix.*/
setFirstIndex(size_t firstIndex)99 		void setFirstIndex( size_t firstIndex) { mFirstIndex = firstIndex; }
100 
101 		/** The second index of a matrix.*/
getSecondIndex()102 		size_t getSecondIndex() const { return mSecondIndex; }
103 
104 		/** The second index of a matrix.*/
setSecondIndex(size_t secondIndex)105 		void setSecondIndex( size_t secondIndex) { mSecondIndex = secondIndex; }
106 
107 		/** True, if the address is a valid sid address, false otherwise.*/
isValid()108 		bool isValid() const { return mIsValid; }
109 
110 		/** Returns the sid address as a string.*/
111 		String getSidAddressString() const;
112 
113 
114 	private:
115 
116 		void parseAddress( const String& sidAddress);
117 
118 	};
119 
120 } // namespace COLLADASAXFWL
121 
122 #endif // __COLLADASAXFWL_SIDADDRESS_H__
123