InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
NamedAttribute.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: wtislar
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // ADOBE CONFIDENTIAL
24 //
25 //========================================================================================
26 
27 #ifndef __NamedAttribute__
28 #define __NamedAttribute__
29 
30 
31 #include "IPMStream.h"
32 
33 #include <vector>
34 
39 {
40 public:
43  : fValue(0) {}
44 
46  NamedUint32Attribute( PMString name, uint32 value )
47  : fName(name),
48  fValue(value) {}
49 
51  NamedUint32Attribute( const NamedUint32Attribute& orig ) { Set( orig ); }
52 
53  //----------OPERATORS---------------
54 
57  { Set(copy); return *this; }
58 
60  inline bool operator == (const NamedUint32Attribute &na) const
61  { return fName == na.fName &&
62  fValue == na.fValue; }
63 
65  inline bool operator != (const NamedUint32Attribute &na) const
66  { return (!(*this == na)); }
67 
71  virtual PMString GetName() const { return fName; }
72 
73  virtual void GetValue( uint32 & value ) const { value = fValue; }
74  virtual void ReadWrite( IPMStream* iPMStream )
75  {
76  fName.ReadWrite( iPMStream );
77  int32 int32Value = int32(fValue);
78  iPMStream->XferInt32( int32Value );
79  fValue = uint32(int32Value);
80  }
81 
82 private:
83  PMString fName;
84  uint32 fValue;
85 
86  void Set( const NamedUint32Attribute & copy )
87  { fName = copy.fName; fValue = copy.fValue; }
88 
89 }; // end NamedUint32Attribute class
90 
91 
96 {
97 public:
100 
102  NamedUint32AttributeList( const NamedUint32AttributeList& orig ) { Set( orig ); }
103 
104  //----------OPERATORS---------------
105 
106  NamedUint32AttributeList& operator = (const NamedUint32AttributeList &copy)
107  { Set(copy); return *this; }
108 
109  inline bool operator == (const NamedUint32AttributeList &list) const
110  {
111  if ( fList.size() == list.fList.size() )
112  {
113  int listSize = int(fList.size());
114  for ( int i = 0; i < listSize; i++ )
115  if ( fList[i] != list.fList[i] )
116  return false;
117  return true;
118  }
119  return false;
120  }
121 
122  inline bool operator != (const NamedUint32AttributeList & list) const { return (!(*this == list)); }
123 
124  inline NamedUint32Attribute & operator [] (int i) { return fList[i]; }
125 
126  void Add( NamedUint32Attribute na ) { fList.push_back( na ); }
127 
128  void Add( int32 i, NamedUint32Attribute na )
129  {
130  int32 listSize((int32)fList.size());
131  if ( i >= 0 && i <= listSize )
132  fList.insert( fList.begin() + i, na );
133  }
134 
135  void Clear() { fList.clear(); }
136 
137  void RemoveAt( int32 i ) { fList.erase( fList.begin() + i ); }
138 
139  int32 Length() { return int32(fList.size()); }
140  uint32 GetLength() const { return uint32(fList.size()); }
141 
142  void ReadWrite( IPMStream* iPMStream )
143  {
144  int32 listSize((int32)fList.size());
145  iPMStream->XferInt32( listSize );
146  if ( iPMStream->IsReading() )
147  {
148  fList.clear();
149  for ( int32 i = 0; i < listSize; i++ )
150  {
152  na.ReadWrite( iPMStream );
153  fList.push_back( na );
154  }
155  }
156  else
157  {
158  for ( std::vector<NamedUint32Attribute>::const_iterator iter = fList.begin(); iter != fList.end(); ++iter )
159  {
160  NamedUint32Attribute na = *iter;
161  na.ReadWrite( iPMStream );
162  }
163  }
164  } // end ReadWrite()
165 
166 private:
167  std::vector<NamedUint32Attribute> fList;
168 
169  void Set( const NamedUint32AttributeList & copy )
170  {
171  fList.clear();
172  int listSize = int(copy.fList.size());
173  for ( int i = 0; i < listSize; i++ )
174  fList.push_back( copy.fList[i] );
175  }
176 }; // end NamedUint32AttributeList class
177 
178 #endif // __NamedUint32AttributeList__