ECInstance.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 #include "ECObjects.h"
11 #include <Bentley/DateTime.h>
12 #include <Geom/GeomApi.h>
13 
14 BENTLEY_TYPEDEFS (BeXmlDom)
15 BENTLEY_TYPEDEFS (BeXmlNode)
16 
17 namespace Bentley { namespace DgnPlatform {
18  struct DgnECInstance;
19  }}
20 
22 
42 
44 // The following definitions are used to allow a struct property to generate a
45 // custom XML representation of itself. This was required to support 8.11
46 // installedTypes as Vancouver ECStructs
48 typedef bmap<WString, ICustomECStructSerializerP> NameSerializerMap;
49 
54  {
59  virtual bool UsesCustomStructXmlString (StructECPropertyP structProperty, IECInstanceCR ecInstance) const = 0;
60 
67  virtual ECObjectsStatus GenerateXmlString (WString& xmlString, StructECPropertyP structProperty, IECInstanceCR ecInstance, WCharCP baseAccessString) const = 0;
68 
74  virtual void LoadStructureFromString (StructECPropertyP structProperty, IECInstanceR ecInstance, WCharCP baseAccessString, WCharCP valueString) = 0;
75  };
76 
80 {
81 public:
82 
87  ECOBJECTS_EXPORT ICustomECStructSerializerP GetCustomSerializer (StructECPropertyP structProperty, IECInstanceCR ecInstance) const;
88 
91 
95  ECOBJECTS_EXPORT BentleyStatus AddCustomSerializer (WCharCP serializerName, ICustomECStructSerializerP serializer);
96 };
97 
99 //=======================================================================================
114 //=======================================================================================
116  {
117 private:
118  ECObjectsStatus ChangeValue (uint32_t propertyIndex, ECValueCR v, bool useArrayIndex, uint32_t arrayIndex);
119 
120  bool GetInstanceLabelPropertyName (WString& propertyName) const;
121 
128  ECObjectsStatus ValidateDateTimeMetadata (uint32_t propertyIndex, ECValueCR v) const;
135  ECObjectsStatus SetDateTimeMetadataInECValue (ECValueR v, uint32_t propertyIndex) const;
136  bool TryGetDateTimeInfo (DateTimeInfoR dateTimeInfo, uint32_t propertyIndex) const;
137 
138 protected:
140  ECOBJECTS_EXPORT virtual ~IECInstance();
141 
143  virtual WString _GetInstanceId() const = 0; // Virtual and returning WString because a subclass may want to calculate it on demand
145  virtual WString _GetInstanceIdForSerialization() const { return GetInstanceId(); }
146 
154  virtual ECObjectsStatus _GetValue (ECValueR v, uint32_t propertyIndex, bool useArrayIndex, uint32_t arrayIndex) const = 0;
155 
163  virtual ECObjectsStatus _SetValue (uint32_t propertyIndex, ECValueCR v, bool useArrayIndex, uint32_t arrayIndex) = 0;
164 
170  virtual ECObjectsStatus _InsertArrayElements (uint32_t propertyIndex, uint32_t index, uint32_t size) = 0;
171 
176  virtual ECObjectsStatus _AddArrayElements (uint32_t propertyIndex, uint32_t size) = 0;
177 
182  virtual ECObjectsStatus _RemoveArrayElement (uint32_t propertyIndex, uint32_t index) = 0;
183 
187  virtual ECObjectsStatus _ClearArray (uint32_t propertyIndex) = 0;
189  virtual ECEnablerCR _GetEnabler() const = 0;
191  virtual bool _IsReadOnly() const = 0;
194  virtual WString _ToString (WCharCP indent) const = 0;
196  virtual size_t _GetOffsetToIECInstance () const = 0;
197 
204  ECOBJECTS_EXPORT virtual ECObjectsStatus _GetIsPropertyNull (bool& isNull, uint32_t propertyIndex, bool useArrayIndex, uint32_t arrayIndex) const;
205 
207  ECOBJECTS_EXPORT virtual ECObjectsStatus _SetInstanceId(WCharCP);
209  ECOBJECTS_EXPORT virtual ECObjectsStatus _GetDisplayLabel (WString& displayLabel) const;
211  ECOBJECTS_EXPORT virtual ECObjectsStatus _SetDisplayLabel (WCharCP displayLabel);
213  ECOBJECTS_EXPORT virtual MemoryECInstanceBase* _GetAsMemoryECInstance () const;
215  ECOBJECTS_EXPORT virtual ECDBuffer* _GetECDBuffer() const;
216 
221  ECOBJECTS_EXPORT virtual bool _IsPropertyReadOnly (WCharCP accessString) const;
222 
227  ECOBJECTS_EXPORT virtual bool _IsPropertyReadOnly (uint32_t propertyIndex) const;
228 
236  ECOBJECTS_EXPORT virtual ECObjectsStatus _SetInternalValue (uint32_t propertyIndex, ECValueCR v, bool useArrayIndex, uint32_t arrayIndex);
237 
240 
242  virtual bool _SaveOnlyLoadedPropertiesToXml() const { return false; }
243 
246  virtual bool _ChangeValuesAllowed() const { return ! IsReadOnly(); }
247 public:
250  bool ChangeValuesAllowed() { return _ChangeValuesAllowed(); }
251 
253  ECOBJECTS_EXPORT void const* GetBaseAddress () {return this;}
254 
256  ECOBJECTS_EXPORT ECEnablerCR GetEnabler() const;
257 
259  ECOBJECTS_EXPORT ECEnablerR GetEnablerR() const; // use when enabler.ObtainStandaloneEnabler is called since a new enabler may be created.
260 
262  ECOBJECTS_EXPORT WString GetInstanceId() const;
264  ECOBJECTS_EXPORT WString GetInstanceIdForSerialization() const;
266  ECOBJECTS_EXPORT ECObjectsStatus SetInstanceId(WCharCP instanceId);
268  ECOBJECTS_EXPORT bool IsReadOnly() const;
270  ECOBJECTS_EXPORT ECClassCR GetClass() const;
275  ECOBJECTS_EXPORT ECObjectsStatus GetValue (ECValueR v, WCharCP propertyAccessString) const;
281  ECOBJECTS_EXPORT ECObjectsStatus GetValue (ECValueR v, WCharCP propertyAccessString, uint32_t arrayIndex) const;
287  ECOBJECTS_EXPORT ECObjectsStatus GetValue (ECValueR v, uint32_t propertyIndex) const;
294  ECOBJECTS_EXPORT ECObjectsStatus GetValue (ECValueR v, uint32_t propertyIndex, uint32_t arrayIndex) const;
299  ECOBJECTS_EXPORT ECObjectsStatus SetValue (WCharCP propertyAccessString, ECValueCR v);
305  ECOBJECTS_EXPORT ECObjectsStatus SetValue (WCharCP propertyAccessString, ECValueCR v, uint32_t arrayIndex);
311  ECOBJECTS_EXPORT ECObjectsStatus SetValue (uint32_t propertyIndex, ECValueCR v);
318  ECOBJECTS_EXPORT ECObjectsStatus SetValue (uint32_t propertyIndex, ECValueCR v, uint32_t arrayIndex);
319 
324  ECOBJECTS_EXPORT ECObjectsStatus ChangeValue (WCharCP propertyAccessString, ECValueCR v);
330  ECOBJECTS_EXPORT ECObjectsStatus ChangeValue (WCharCP propertyAccessString, ECValueCR v, uint32_t arrayIndex);
336  ECOBJECTS_EXPORT ECObjectsStatus ChangeValue (uint32_t propertyIndex, ECValueCR v);
343  ECOBJECTS_EXPORT ECObjectsStatus ChangeValue (uint32_t propertyIndex, ECValueCR v, uint32_t arrayIndex);
344 
346  ECOBJECTS_EXPORT ECObjectsStatus GetValueUsingAccessor (ECValueR v, ECValueAccessorCR accessor) const;
348  ECOBJECTS_EXPORT ECObjectsStatus SetValueUsingAccessor (ECValueAccessorCR accessor, ECValueCR v);
349 
355  ECOBJECTS_EXPORT ECObjectsStatus IsPropertyNull (bool& isNull, WCharCP propertyAccessString) const;
356 
362  ECOBJECTS_EXPORT ECObjectsStatus IsPropertyNull (bool& isNull, WCharCP propertyAccessString, uint32_t arrayIndex) const;
363 
369  ECOBJECTS_EXPORT ECObjectsStatus IsPropertyNull (bool& isNull, uint32_t propertyIndex) const;
370 
377  ECOBJECTS_EXPORT ECObjectsStatus IsPropertyNull (bool& isNull, uint32_t propertyIndex, uint32_t arrayIndex) const;
378 
384 
390  ECOBJECTS_EXPORT static bool IsFixedArrayProperty (ECN::IECInstanceR instance, WCharCP accessString, uint32_t* numFixedEntries=NULL);
391 
395  ECOBJECTS_EXPORT bool IsPropertyReadOnly (WCharCP accessString) const;
396 
399  ECOBJECTS_EXPORT bool IsPropertyReadOnly (uint32_t propertyIndex) const;
400 
409  ECOBJECTS_EXPORT ECObjectsStatus InsertArrayElements (WCharCP propertyAccessString, uint32_t index, uint32_t size);
410 
415  ECOBJECTS_EXPORT ECObjectsStatus RemoveArrayElement (WCharCP propertyAccessString, uint32_t index);
416 
421  ECOBJECTS_EXPORT ECObjectsStatus AddArrayElements (WCharCP propertyAccessString, uint32_t size);
422 
426  ECOBJECTS_EXPORT ECObjectsStatus ClearArray (WCharCP propertyAccessString);
427 
433  ECOBJECTS_EXPORT ECObjectsStatus InsertArrayElements (uint32_t propertyIndex, uint32_t index, uint32_t size);
434 
439  ECOBJECTS_EXPORT ECObjectsStatus RemoveArrayElement (uint32_t propertyIndex, uint32_t index);
440 
445  ECOBJECTS_EXPORT ECObjectsStatus AddArrayElements (uint32_t propertyIndex, uint32_t size);
446 
450  ECOBJECTS_EXPORT ECObjectsStatus ClearArray (uint32_t propertyIndex);
451 
458  ECOBJECTS_EXPORT ECObjectsStatus GetDisplayLabel (WString& displayLabel) const;
459 
463  ECOBJECTS_EXPORT ECObjectsStatus SetDisplayLabel (WCharCP displayLabel);
464 
465  ECOBJECTS_EXPORT ECDBuffer const* GetECDBuffer() const;
466  ECOBJECTS_EXPORT ECDBuffer* GetECDBufferP();
467  ECOBJECTS_EXPORT MemoryECInstanceBase const* GetAsMemoryECInstance () const;
468  ECOBJECTS_EXPORT MemoryECInstanceBase* GetAsMemoryECInstanceP();
469  ECOBJECTS_EXPORT size_t GetOffsetToIECInstance () const;
470 
473  ECOBJECTS_EXPORT WString ToString (WCharCP indent) const;
474 
476  ECOBJECTS_EXPORT IECInstancePtr CreateCopyThroughSerialization();
477 
479  ECOBJECTS_EXPORT IECInstancePtr CreateCopyThroughSerialization(ECSchemaCR targetSchema);
480 
486  ECOBJECTS_EXPORT static InstanceReadStatus ReadFromXmlFile (IECInstancePtr& ecInstance, WCharCP fileName, ECInstanceReadContextR context);
487 
493  ECOBJECTS_EXPORT static InstanceReadStatus ReadFromXmlStream (IECInstancePtr& ecInstance, IStreamP stream, ECInstanceReadContextR context);
494 
500  ECOBJECTS_EXPORT static InstanceReadStatus ReadFromXmlString (IECInstancePtr& ecInstance, WCharCP xmlString, ECInstanceReadContextR context);
501 
507  ECOBJECTS_EXPORT static InstanceReadStatus ReadFromXmlString (IECInstancePtr& ecInstance, Utf8CP xmlString, ECInstanceReadContextR context);
508 
514  ECOBJECTS_EXPORT static InstanceReadStatus ReadFromBeXmlDom (IECInstancePtr& ecInstance, BeXmlDomR xmlNode, ECInstanceReadContextR context);
515 
521  ECOBJECTS_EXPORT static InstanceReadStatus ReadFromBeXmlNode (IECInstancePtr& ecInstance, BeXmlNodeR xmlNode, ECInstanceReadContextR context);
522 
528  ECOBJECTS_EXPORT InstanceWriteStatus WriteToXmlFile (WCharCP fileName, bool writeInstanceId, bool utf16);
529 
536  ECOBJECTS_EXPORT InstanceWriteStatus WriteToXmlStream (IStreamP stream, bool isStandAlone, bool writeInstanceId, bool utf16);
537 
543  ECOBJECTS_EXPORT InstanceWriteStatus WriteToXmlString (Utf8String & ecInstanceXml, bool isStandAlone, bool writeInstanceId);
544 
550  ECOBJECTS_EXPORT InstanceWriteStatus WriteToXmlString (WString & ecInstanceXml, bool isStandAlone, bool writeInstanceId);
551 
555  ECOBJECTS_EXPORT InstanceWriteStatus WriteToBeXmlNode (BeXmlNodeR xmlNode);
556 
559  ECOBJECTS_EXPORT bool SaveOnlyLoadedPropertiesToXml() const;
560  };
561 
562 //=======================================================================================
567 //=======================================================================================
569  {
570  private:
571  virtual void _SetSource (IECInstanceP instance) = 0;
572  virtual IECInstancePtr _GetSource () const = 0;
573  virtual ECObjectsStatus _GetSourceOrderId (int64_t& sourceOrderId) const = 0;
574  virtual void _SetTarget (IECInstanceP instance)= 0;
575  virtual IECInstancePtr _GetTarget () const = 0;
576  virtual ECObjectsStatus _GetTargetOrderId (int64_t& targetOrderId) const = 0;
577 
578  public:
579 
582  ECOBJECTS_EXPORT void SetSource (IECInstanceP instance);
583 
585  ECOBJECTS_EXPORT IECInstancePtr GetSource () const;
586 
589  ECOBJECTS_EXPORT ECObjectsStatus GetSourceOrderId (int64_t& sourceOrderId) const;
590 
593  ECOBJECTS_EXPORT void SetTarget (IECInstanceP instance);
594 
596  ECOBJECTS_EXPORT IECInstancePtr GetTarget () const;
597 
600  ECOBJECTS_EXPORT ECObjectsStatus GetTargetOrderId (int64_t& targetOrderId) const;
601  };
602 
604 
605 
606 typedef bvector<IECInstancePtr> ECInstanceList;
610 
613 
Contains a UTF-8 encoded string.
Definition: WString.h:275
bvector< IECInstancePtr > ECInstanceList
Definition: ECInstance.h:606
ECObjectsStatus
General purpose result codes.
Definition: ECObjects.h:128
The in-memory representation of an ECProperty as defined by ECSchemaXML.
Definition: ECSchema.h:468
long long int64_t
Definition: Bentley.r.h:94
Provides Bentley specific date/time functions (Bentley/BeAssert.h).
ECN::IECRelationshipInstance is an instance of an ECRelationshipClass and represents the relationship...
Definition: ECInstance.h:568
virtual WString _GetInstanceIdForSerialization() const
Gets the ID which should be written to ECInstance XML for this instance.
Definition: ECInstance.h:145
ECEnabler & ECEnablerR
Definition: ECObjects.h:78
RefCountedPtr< IECInstance > IECInstancePtr
Definition: ECInstance.h:98
RefCountedPtr< IECRelationshipInstance > IECRelationshipInstancePtr
Definition: ECInstance.h:603
InstanceWriteStatus
Result status of writing an IECInstance to Xml.
Definition: ECObjects.h:231
ECValue const & ECValueCR
Definition: ECObjects.h:46
wchar_t const * WCharCP
Definition: Bentley.h:224
ECInstanceList const * ECInstanceListCP
Definition: ECInstance.h:608
Used to manage multiple custom struct serializers.
Definition: ECInstance.h:79
ECSchema const & ECSchemaCR
Definition: ECObjects.h:53
DateTimeInfo contains the meta data held by the custom attribute DateTimeInfo on an ECProperty of typ...
Definition: StandardCustomAttributeHelper.h:31
virtual bool _SaveOnlyLoadedPropertiesToXml() const
Allow each instance type to determine if it want to only serialize "loaded" properties to XML...
Definition: ECInstance.h:242
#define NULL
Definition: Bentley.h:157
ECInstanceList * ECInstanceListP
Definition: ECInstance.h:607
#define ECOBJECTS_EXPORT
Definition: ECObjects.h:20
bool ChangeValuesAllowed()
Returns true if callers are permitted to modify values of this IECInstance in memory.
Definition: ECInstance.h:250
GeomApi: Bentley::Rounding, Bentley::ValueSizeSize, Bentley::OrderedValueSizeSize, Bentley::IGeometry, Bentley::OrderedIGeometryPtr, Bentley::pointList.
BentleyStatus
Definition: Bentley.h:208
virtual bool _ChangeValuesAllowed() const
Returns true if callers are permitted to modify values of this IECInstance in memory.
Definition: ECInstance.h:246
IManager * GetManager()
Return a pointer to the one and only relationship manager.
ECN::MemoryECInstanceBase is base class for ECInstances that holds its values in memory that it alloc...
Definition: StandaloneECInstance.h:52
A shared pointer template for reference-counted objects.
Definition: RefCounted.h:119
struct Bentley::BeXmlDom & BeXmlDomR
Definition: ECInstance.h:14
IECInstance const & IECInstanceCR
Definition: ECObjects.h:67
Interface for a custom ECStruct Serializer.
Definition: ECInstance.h:53
Context object used for instance creation and deserialization.
Definition: ECContext.h:89
ECClass const & ECClassCR
Definition: ECObjects.h:63
#define BENTLEY_TYPEDEFS(_name_)
Definition: Bentley.h:152
Variant-like object used to set and retrieve property values in ECInstances.
Definition: ECValue.h:73
#define END_BENTLEY_ECOBJECT_NAMESPACE
Definition: DgnPlatform.h:41
InstanceReadStatus
Result status of deserializing an IECInstance from Xml.
Definition: ECObjects.h:196
ECInstanceList const & ECInstanceListCR
Definition: ECInstance.h:609
struct Bentley::BeXmlNode & BeXmlNodeR
Definition: ECInstance.h:15
virtual Bentley::DgnPlatform::DgnECInstance const * _GetAsDgnECInstance() const
Convenience method for DgnPlatform to return this instance as a DgnECInstance.
Definition: ECInstance.h:239
ECValueAccessor const & ECValueAccessorCR
Definition: ECObjects.h:47
void const * GetBaseAddress()
Returns the base address for this instance.
Definition: ECInstance.h:253
Concrete class that can be used to implement the reference-counting pattern.
Definition: RefCounted.h:109
bmap< WString, ICustomECStructSerializerP > NameSerializerMap
Definition: ECInstance.h:48
Utf8Char const * Utf8CP
Definition: Bentley.h:229
DgnInstance is an abstract class that represents an ecinstance which is persisted in the DgnPlatform ...
Definition: DgnECInstance.h:439
Base class for ECN::IECInstance implementations that get/set values from a block of memory...
Definition: ECDBuffer.h:230
ECEnabler const & ECEnablerCR
Definition: ECObjects.h:78
unsigned int uint32_t
Definition: Bentley.r.h:93
ECInstanceList & ECInstanceListR
Definition: ECInstance.h:607
An IECInstance represents an instance of an ECClass.
Definition: ECInstance.h:115
size_type size() const
Definition: stdcxx/bstdmap.h:214
struct IStream * IStreamP
Definition: ECObjects.h:114
A string class that has many of the same capabilities as std::string, plus additional functions such ...
Definition: WString.h:51
#define BEGIN_BENTLEY_ECOBJECT_NAMESPACE
Definition: DgnPlatform.h:40

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.