Free Electron
SurfaceAccessibleBase.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __surface_SurfaceAccessibleBase_h__
8 #define __surface_SurfaceAccessibleBase_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Common Functionality for Accessible Surface
17 
18  @ingroup surface
19 *//***************************************************************************/
20 class FE_DL_EXPORT SurfaceAccessibleBase:
21  public ObjectSafeShared<SurfaceAccessibleBase>,
22  virtual public SurfaceAccessibleI,
23  public CastableAs<SurfaceAccessibleBase>
24 {
25  public:
27 virtual ~SurfaceAccessibleBase(void);
28 
29  //* as SurfaceAccessibleI
30 virtual BWORD isBound(void) { return FALSE; }
31 virtual void bind(Instance a_instance) {}
32 virtual void bind(sp<Scope> a_scope) {}
34  a_spThreadingState)
35  { m_spThreadingState=a_spThreadingState; }
36 
37 virtual BWORD threadable(void) { return TRUE; }
38 
39 virtual void lock(I64 a_id);
40 virtual void lock(void) { lock(0); }
41 
42 virtual void unlock(I64 a_id);
43 virtual void unlock(void) { unlock(0); }
44 
45 virtual BWORD load(String a_filename)
46  { return load(a_filename,sp<Catalog>(NULL)); }
47 virtual BWORD load(String a_filename,sp<Catalog> a_spSettings);
48 virtual BWORD save(String a_filename)
49  { return save(a_filename,sp<Catalog>(NULL)); }
50 virtual BWORD save(String a_filename,sp<Catalog> a_spSettings)
51  { return FALSE; }
52 
53 virtual void groupNames(Array<String>& a_rNameArray,
54  SurfaceAccessibleI::Element
55  a_element) const
56  { a_rNameArray.clear(); }
57 
58  //* NOTE You must supply at least one of the
59  //* attributeSpecs methods.
60  //* These defaults will be be cross-dependent.
61 virtual void attributeSpecs(
63  a_rSpecs,
64  SurfaceAccessibleI::Element
65  a_element) const
66  { attributeSpecs(a_rSpecs,"",a_element); }
67 virtual void attributeSpecs(
69  a_rSpecs,
70  String a_node,
71  SurfaceAccessibleI::Element
72  a_element) const;
73 
74 virtual void clear(void) { reset(); }
75 
76 virtual I32 count(String a_node,
77  SurfaceAccessibleI::Element
78  a_element) const;
79 virtual I32 count(SurfaceAccessibleI::Element
80  a_element) const
81  { return count("",a_element); }
82 
83  //* NOTE Derived classes must supply
84  //* the two 5-arg accessor methods.
85 
87 virtual sp<SurfaceAccessorI> accessor(String a_node,Element a_element,
88  String a_name,
89  Creation a_create,Writable a_writable)
90  {
91  return sp<SurfaceAccessorI>(NULL);
92  }
93 
94 virtual sp<SurfaceAccessorI> accessor(String a_node,Element a_element,
95  Attribute a_attribute,
96  Creation a_create,Writable a_writable)
97  {
98  return sp<SurfaceAccessorI>(NULL);
99  }
100 
101 virtual sp<SurfaceAccessorI> accessor(String a_node,Element a_element,
102  String a_name,
103  Creation a_create)
104  { return accessor(a_node,a_element,a_name,
105  a_create,e_readOnly); }
106 
107 virtual sp<SurfaceAccessorI> accessor(String a_node,Element a_element,
108  Attribute a_attribute,
109  Creation a_create)
110  { return accessor(a_node,
111  a_element,a_attribute,
112  a_create,e_readOnly); }
113 
114 virtual sp<SurfaceAccessorI> accessor(Element a_element,String a_name,
115  Creation a_create)
116  { return accessor("",a_element,a_name,
117  a_create,e_readOnly); }
118 
119 virtual sp<SurfaceAccessorI> accessor(Element a_element,
120  Attribute a_attribute,
121  Creation a_create)
122  { return accessor("",a_element,a_attribute,
123  a_create,e_readOnly); }
124 
125 virtual sp<SurfaceAccessorI> accessor(Element a_element,String a_name)
126  { return accessor(a_element,a_name,
127  e_createMissing); }
128 
129 virtual sp<SurfaceAccessorI> accessor(Element a_element,
130  Attribute a_attribute)
131  { return accessor(a_element,a_attribute,
132  e_createMissing); }
133 
134 virtual I32 discardPattern(
135  SurfaceAccessibleI::Element a_element,
136  String a_pattern);
137 virtual BWORD discard(SurfaceAccessibleI::Element a_element,
138  String a_name);
139 virtual BWORD discard(SurfaceAccessibleI::Element a_element,
140  SurfaceAccessibleI::Attribute
141  a_attribute);
142 
143 virtual sp<SurfaceI> surface(void)
144  { return surface(String(),
145  SurfaceI::e_unrestricted); }
146 virtual sp<SurfaceI> surface(String a_group)
147  { return surface(a_group,
148  SurfaceI::e_unrestricted); }
149 virtual sp<SurfaceI> surface(String a_group,
150  SurfaceI::Restrictions a_restrictions);
151 
152 virtual sp<SurfaceI> subSurface(U32 a_subIndex)
153  { return subSurface(a_subIndex,String(),
154  SurfaceI::e_unrestricted); }
155 virtual sp<SurfaceI> subSurface(U32 a_subIndex,String a_group)
156  { return subSurface(a_subIndex,a_subIndex,
157  SurfaceI::e_unrestricted); }
158 virtual sp<SurfaceI> subSurface(U32 a_subIndex,String a_group,
159  SurfaceI::Restrictions a_restrictions);
160 
161 virtual void copy(sp<SurfaceAccessibleI>
162  a_spSurfaceAccessible)
163  { reset();
164  append(a_spSurfaceAccessible,NULL); }
165 
166 virtual void copy(sp<SurfaceAccessibleI>
167  a_spSurfaceAccessible,
168  String a_nodeName)
169  { reset();
170  Array<SpatialTransform> transformArray;
171  append(a_spSurfaceAccessible,a_nodeName,
172  transformArray,sp<FilterI>(NULL)); }
173 
174 virtual void copy(sp<SurfaceAccessibleI>
175  a_spSurfaceAccessible,
176  sp<FilterI> a_spFilter)
177  { reset();
178  append(a_spSurfaceAccessible,
179  NULL,a_spFilter); }
180 
181 virtual void instance(sp<SurfaceAccessibleI>
182  a_spSurfaceAccessible,
184  a_rTransformArray);
185 
186 virtual void append(sp<SurfaceAccessibleI>
187  a_spSurfaceAccessible,
188  const SpatialTransform*
189  a_pTransform)
190  { append(a_spSurfaceAccessible,
191  a_pTransform,sp<FilterI>(NULL)); }
192 
193  void append(sp<SurfaceAccessibleI>
194  a_spSurfaceAccessible,
195  String a_nodeName,
197  a_rTransformArray,
198  sp<FilterI> a_spFilter);
199 
200  //* promote?
201  void append(sp<SurfaceAccessibleI>
202  a_spSurfaceAccessible,
203  const SpatialTransform*
204  a_pTransform,
205  sp<FilterI> a_spFilter);
206 
207  //* default implementation is non-atomic
208 virtual sp<SpannedRange> atomize(AtomicChange a_atomicChange,
209  String a_group,U32 a_desiredCount);
210 
211 virtual sp<SpannedRange> atomizeConnectivity(AtomicChange a_atomicChange,
212  String a_group,U32 a_desiredCount,
213  BWORD a_checkPages);
214 
215 virtual void setPaging(BWORD a_paging)
216  { m_paging=a_paging; }
217 virtual BWORD paging(void) const { return m_paging; }
218 
219 virtual void preparePaging(AtomicChange a_atomicChange,
220  String a_group) {}
221 virtual I32 pointPage(U32 a_pointIndex) const
222  { return 0; }
223 virtual I32 primitivePage(U32 a_primitiveIndex) const
224  { return 0; }
225 
226 virtual BWORD copyOutline(Array<String>&
227  a_rStringArray) const;
228 
229 static String elementLayout(
230  SurfaceAccessibleI::Element a_element);
231 static String attributeString(SurfaceAccessibleI::Attribute
232  a_attribute);
233 
234  String findNameAttribute(void);
235 
236  void setAttributeToDefault(Element a_element,
237  I32 a_start,I32 a_count,
238  const Spec& a_rSpec);
239 
240 virtual sp<Component> payload(void) { return sp<Component>(NULL); }
241 
242 static BWORD specsContain(const Array<Spec>& a_rSpecs,
243  const Spec& a_rSpec);
244 
245  class FE_DL_EXPORT MultiGroup:
246  public Counted,
247  public CastableAs<MultiGroup>
248  {
249  public:
250  MultiGroup(void):
251  m_iterator(m_indices.begin()),
252  m_currentPosition(0) {}
253  virtual ~MultiGroup(void) {}
254 
255  BWORD contains(I32 a_index) const
256  { return m_indices.find(a_index) !=
257  m_indices.end(); }
258 
259  U32 count(void) const { return m_indices.size(); }
260  I32 at(I32 a_position);
261  void insert(I32 a_index)
262  {
263  m_indices.insert(a_index);
264  m_iterator=m_indices.begin();
265  m_currentPosition=0;
266  }
267  void insert(I32 a_first,I32 a_last)
268  {
269  for(I32 index=a_first;index<=a_last;index++)
270  { m_indices.insert(index); }
271  m_iterator=m_indices.begin();
272  m_currentPosition=0;
273  }
274  void insert(std::set<I32>& a_rIntSet)
275  {
276  for(I32 index: a_rIntSet)
277  { m_indices.insert(index); }
278  m_iterator=m_indices.begin();
279  m_currentPosition=0;
280  }
281  void erase(I32 a_index)
282  {
283  m_indices.erase(a_index);
284  m_iterator=m_indices.begin();
285  m_currentPosition=0;
286  }
287  void erase(I32 a_first,I32 a_last)
288  {
289  for(I32 index=a_first;index<=a_last;index++)
290  { m_indices.erase(index); }
291  m_iterator=m_indices.begin();
292  m_currentPosition=0;
293  }
294  virtual void add(I32 a_index) { insert(a_index); }
295  virtual void remove(I32 a_index) { erase(a_index); }
296 
297  private:
298  std::set<I32> m_indices;
299  std::set<I32>::iterator m_iterator;
300  I32 m_currentPosition;
301  sp<SurfaceAccessibleBase> m_spSurfaceAccessibleBase;
302  };
303 
304 virtual I32 deleteElements(
305  SurfaceAccessibleI::Element a_element,
306  String a_groupString,
307  BWORD a_retainGroups);
308 
309 virtual I32 deleteElements(
310  SurfaceAccessibleI::Element a_element,
311  std::set<I32>& a_rIntSet,
312  BWORD a_retainGroups);
313 
314 virtual I32 deleteElements(
315  SurfaceAccessibleI::Element a_element,
317  a_spMultiGroup,
318  BWORD a_retainGroups);
319 
320  //* convert impl data in generic set of indices
321 virtual sp<MultiGroup> generateGroup(
322  SurfaceAccessibleI::Element a_element,
323  String a_groupString);
324 
325  BWORD removeGroup(
326  SurfaceAccessibleI::Element a_element,
327  String a_groupString);
328  BWORD hasGroup(
329  SurfaceAccessibleI::Element a_element,
330  String a_groupString);
331  sp<MultiGroup> group(SurfaceAccessibleI::Element a_element,
332  String a_groupString);
333 
334  std::map<String, sp<MultiGroup> >& groupMap(
335  SurfaceAccessibleI::Element a_element);
336 
337  protected:
338 virtual void reset(void);
339 
340 static String commonName(String a_attrName);
341 static String attributeName(String a_specName);
342 
343  SurfaceAccessibleI::Threading threading(void) const
344  {
345  if(m_spThreadingState.isNull())
346  {
347  return SurfaceAccessibleI::e_unknown;
348  }
349  return Threading(
350  m_spThreadingState->threading());
351  }
352 
353  void outlineClear(void);
354  void outlineAppend(String a_line);
355  void outlineCreateDefault(void);
356 
357  sp<SurfaceAccessibleI::ThreadingState> m_spThreadingState;
358 
359  BWORD m_paging;
360  I64 m_locker;
361  Array<String> m_outline;
362 
363  String addGroupRanges(
365  String a_groupString);
366 
367  std::map<String, sp<MultiGroup> > m_pointGroupMap;
368  std::map<String, sp<MultiGroup> > m_primitiveGroupMap;
369 };
370 
372  SurfaceAccessibleI::Element a_element,std::set<I32>& a_rIntSet,
373  BWORD a_retainGroups)
374 {
375 // feLog("SurfaceAccessibleBase::deleteElements '%s' count %d retain %d\n",
376 // elementLayout(a_element).c_str(),a_rIntSet.count(),
377 // a_retainGroups);
378 
379  if(!a_rIntSet.size())
380  {
381  return 0;
382  }
383 
384  sp<MultiGroup> spMultiGroup=generateGroup(a_element,"");
385  if(spMultiGroup.isNull())
386  {
387  feLog("SurfaceAccessibleBase::deleteElements MultiGroup NULL\n");
388  return 0;
389  }
390 
391  spMultiGroup->insert(a_rIntSet);
392 
393  return deleteElements(a_element,spMultiGroup,a_retainGroups);
394 }
395 
396 
397 } /* namespace ext */
398 } /* namespace fe */
399 
400 #endif /* __surface_SurfaceAccessibleBase_h__ */
Common Functionality for Accessible Surface.
Definition: SurfaceAccessibleBase.h:20
Surface Element Access and Alteration.
Definition: SurfaceAccessibleI.h:22
virtual sp< SurfaceI > surface(void)
Return current underlying SurfaceI.
Definition: SurfaceAccessibleBase.h:143
virtual void unlock(void)
Finish a thread-unsafe action.
Definition: SurfaceAccessibleBase.h:43
virtual void bind(sp< SurfaceAccessibleI::ThreadingState > a_spThreadingState)
Inform threading intentions.
Definition: SurfaceAccessibleBase.h:33
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
kernel
Definition: namespace.dox:3
virtual I32 deleteElements(SurfaceAccessibleI::Element a_element, String a_groupString, BWORD a_retainGroups)
Remove elements from surface.
Definition: SurfaceAccessibleBase.cc:747
virtual void bind(sp< Scope > a_scope)
choose a data scope
Definition: SurfaceAccessibleBase.h:32
virtual BWORD isBound(void)
Return true if surface is available.
Definition: SurfaceAccessibleBase.h:30
virtual BWORD threadable(void)
Indicate whether an implementation can be accessed from multiple threads.
Definition: SurfaceAccessibleBase.h:37
virtual void bind(Instance a_instance)
associate with model data
Definition: SurfaceAccessibleBase.h:31
Automatically reference-counted string container.
Definition: String.h:128
Wrapper for std::vector.
Definition: Array.h:21
virtual void lock(void)
Start a thread-unsafe action.
Definition: SurfaceAccessibleBase.h:40
virtual BWORD save(String a_filename)
save model data to file
Definition: SurfaceAccessibleBase.h:48
virtual BWORD save(String a_filename, sp< Catalog > a_spSettings)
save model data with settings
Definition: SurfaceAccessibleBase.h:50
virtual sp< SurfaceAccessorI > accessor(String a_node, SurfaceAccessibleI::Element a_element, String a_name, SurfaceAccessibleI::Creation a_create, SurfaceAccessibleI::Writable a_writable)=0
Return access to an attribute.
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192
Object level locking for thread safety.
Definition: SafeShared.h:220
virtual BWORD load(String a_filename)
load model data from file
Definition: SurfaceAccessibleBase.h:45
virtual sp< SurfaceAccessorI > accessor(String a_node, Element a_element, String a_name, Creation a_create, Writable a_writable)
Return access to an attribute.
Definition: SurfaceAccessibleBase.h:87