//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//  THIS FILE IS GENERATED BY EASY BINDINGS, DO NOT MODIFY IT
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

import Cocoa

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    ReadOnlyArrayOf_DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

class ReadOnlyArrayOf_DeviceSymbolInstanceInProject : ReadOnlyAbstractArrayProperty <DeviceSymbolInstanceInProject> {

  //····················································································································

  override func updateObservers (removedSet inRemovedSet : EBReferenceSet <DeviceSymbolInstanceInProject>,
                                 
                                 addedSet inAddedSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    super.updateObservers (removedSet: inRemovedSet, addedSet: inAddedSet)
  //--- Remove observers from removed objects
    if !inRemovedSet.isEmpty {
      self.removeEBObserversOf_mSymbolInstanceName_fromElementsOfSet (inRemovedSet) // Stored property
      self.removeEBObserversOf_symbolAndTypeName_fromElementsOfSet (inRemovedSet) // Transient property
      self.removeEBObserversOf_symbolTypeName_fromElementsOfSet (inRemovedSet) // Transient property
      self.removeEBObserversOf_filledBezierPath_fromElementsOfSet (inRemovedSet) // Transient property
      self.removeEBObserversOf_strokeBezierPath_fromElementsOfSet (inRemovedSet) // Transient property
    }
  //--- Add observers to added objects
    if !inAddedSet.isEmpty {
      self.addEBObserversOf_mSymbolInstanceName_toElementsOfSet (inAddedSet) // Stored property
      self.addEBObserversOf_symbolAndTypeName_toElementsOfSet (inAddedSet) // Transient property
      self.addEBObserversOf_symbolTypeName_toElementsOfSet (inAddedSet) // Transient property
      self.addEBObserversOf_filledBezierPath_toElementsOfSet (inAddedSet) // Transient property
      self.addEBObserversOf_strokeBezierPath_toElementsOfSet (inAddedSet) // Transient property
   }
  }

  //····················································································································
  //   Observers of 'mSymbolInstanceName' stored property
  //····················································································································

  private final var mObserversOf_mSymbolInstanceName = EBWeakEventSet ()

  //····················································································································

  final func addEBObserverOf_mSymbolInstanceName (_ inObserver : EBObserverProtocol) {
    self.addEBObserver (inObserver)
    self.mObserversOf_mSymbolInstanceName.insert (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.mSymbolInstanceName_property.addEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func removeEBObserverOf_mSymbolInstanceName (_ inObserver : EBObserverProtocol) {
    self.removeEBObserver (inObserver)
    self.mObserversOf_mSymbolInstanceName.remove (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.mSymbolInstanceName_property.removeEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func addEBObserversOf_mSymbolInstanceName_toElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    if !self.mObserversOf_mSymbolInstanceName.isEmpty {
      for managedObject in inSet.values {
        self.mObserversOf_mSymbolInstanceName.apply { (_ observer : EBObserverProtocol) in
          managedObject.mSymbolInstanceName_property.addEBObserver (observer)
        }
      }
    }
  }

  //····················································································································

  final func removeEBObserversOf_mSymbolInstanceName_fromElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    self.mObserversOf_mSymbolInstanceName.apply { (_ observer : EBObserverProtocol) in
      observer.observedObjectDidChange ()
      for managedObject in inSet.values {
        managedObject.mSymbolInstanceName_property.removeEBObserver (observer)
      }
    }
  }

  //····················································································································
  //   Observers of 'symbolAndTypeName' transient property
  //····················································································································

  private final var mObserversOf_symbolAndTypeName = EBWeakEventSet ()

  //····················································································································

  final func addEBObserverOf_symbolAndTypeName (_ inObserver : EBObserverProtocol) {
    self.addEBObserver (inObserver)
    self.mObserversOf_symbolAndTypeName.insert (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.symbolAndTypeName_property.addEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func removeEBObserverOf_symbolAndTypeName (_ inObserver : EBObserverProtocol) {
    self.removeEBObserver (inObserver)
    self.mObserversOf_symbolAndTypeName.remove (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.symbolAndTypeName_property.removeEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func addEBObserversOf_symbolAndTypeName_toElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_symbolAndTypeName.apply { (_ observer : EBObserverProtocol) in
        managedObject.symbolAndTypeName_property.addEBObserver (observer)
      }
    }
  }

  //····················································································································

  final func removeEBObserversOf_symbolAndTypeName_fromElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_symbolAndTypeName.apply { (_ observer : EBObserverProtocol) in
        managedObject.symbolAndTypeName_property.removeEBObserver (observer)
      }
    }
  }

  //····················································································································
  //   Observers of 'symbolTypeName' transient property
  //····················································································································

  private final var mObserversOf_symbolTypeName = EBWeakEventSet ()

  //····················································································································

  final func addEBObserverOf_symbolTypeName (_ inObserver : EBObserverProtocol) {
    self.addEBObserver (inObserver)
    self.mObserversOf_symbolTypeName.insert (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.symbolTypeName_property.addEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func removeEBObserverOf_symbolTypeName (_ inObserver : EBObserverProtocol) {
    self.removeEBObserver (inObserver)
    self.mObserversOf_symbolTypeName.remove (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.symbolTypeName_property.removeEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func addEBObserversOf_symbolTypeName_toElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_symbolTypeName.apply { (_ observer : EBObserverProtocol) in
        managedObject.symbolTypeName_property.addEBObserver (observer)
      }
    }
  }

  //····················································································································

  final func removeEBObserversOf_symbolTypeName_fromElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_symbolTypeName.apply { (_ observer : EBObserverProtocol) in
        managedObject.symbolTypeName_property.removeEBObserver (observer)
      }
    }
  }

  //····················································································································
  //   Observers of 'filledBezierPath' transient property
  //····················································································································

  private final var mObserversOf_filledBezierPath = EBWeakEventSet ()

  //····················································································································

  final func addEBObserverOf_filledBezierPath (_ inObserver : EBObserverProtocol) {
    self.addEBObserver (inObserver)
    self.mObserversOf_filledBezierPath.insert (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.filledBezierPath_property.addEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func removeEBObserverOf_filledBezierPath (_ inObserver : EBObserverProtocol) {
    self.removeEBObserver (inObserver)
    self.mObserversOf_filledBezierPath.remove (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.filledBezierPath_property.removeEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func addEBObserversOf_filledBezierPath_toElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_filledBezierPath.apply { (_ observer : EBObserverProtocol) in
        managedObject.filledBezierPath_property.addEBObserver (observer)
      }
    }
  }

  //····················································································································

  final func removeEBObserversOf_filledBezierPath_fromElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_filledBezierPath.apply { (_ observer : EBObserverProtocol) in
        managedObject.filledBezierPath_property.removeEBObserver (observer)
      }
    }
  }

  //····················································································································
  //   Observers of 'strokeBezierPath' transient property
  //····················································································································

  private final var mObserversOf_strokeBezierPath = EBWeakEventSet ()

  //····················································································································

  final func addEBObserverOf_strokeBezierPath (_ inObserver : EBObserverProtocol) {
    self.addEBObserver (inObserver)
    self.mObserversOf_strokeBezierPath.insert (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.strokeBezierPath_property.addEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func removeEBObserverOf_strokeBezierPath (_ inObserver : EBObserverProtocol) {
    self.removeEBObserver (inObserver)
    self.mObserversOf_strokeBezierPath.remove (inObserver)
    switch self.selection {
    case .empty, .multiple :
      break
    case .single (let v) :
      for managedObject in v {
        managedObject.strokeBezierPath_property.removeEBObserver (inObserver)
      }
    }
  }

  //····················································································································

  final func addEBObserversOf_strokeBezierPath_toElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_strokeBezierPath.apply { (_ observer : EBObserverProtocol) in
        managedObject.strokeBezierPath_property.addEBObserver (observer)
      }
    }
  }

  //····················································································································

  final func removeEBObserversOf_strokeBezierPath_fromElementsOfSet (_ inSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inSet.values {
      self.mObserversOf_strokeBezierPath.apply { (_ observer : EBObserverProtocol) in
        managedObject.strokeBezierPath_property.removeEBObserver (observer)
      }
    }
  }

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    TransientArrayOf DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

final class TransientArrayOf_DeviceSymbolInstanceInProject : ReadOnlyArrayOf_DeviceSymbolInstanceInProject {

  //····················································································································
  //   Sort
  //····················································································································

  private var mIsOrderedBefore : Optional < (_ left : DeviceSymbolInstanceInProject, _ right : DeviceSymbolInstanceInProject) -> Bool > = nil
  private var mSortObserver : EBModelNotifierEvent? = nil
  private var mModelEvent = EBModelEvent ()

  //····················································································································

  override init () {
    super.init ()
    self.mModelEvent.mEventCallBack = { [weak self] in self?.computeModelArray () }
  }

  //····················································································································
  //   Data provider
  //····················································································································

  private var mDataProvider : ReadOnlyArrayOf_DeviceSymbolInstanceInProject? = nil
  private var mTransientKind : PropertyKind = .empty
  private var mModelArrayShouldBeComputed = true

  //····················································································································

  func setDataProvider (_ inProvider : ReadOnlyArrayOf_DeviceSymbolInstanceInProject,
                        sortCallback inSortCallBack : Optional < (_ left : DeviceSymbolInstanceInProject, _ right : DeviceSymbolInstanceInProject) -> Bool >,
                        addSortObserversCallback inAddSortObserversCallback : (EBModelNotifierEvent) -> Void,
                        removeSortObserversCallback inRemoveSortObserversCallback : @escaping (EBModelNotifierEvent) -> Void) {
    if self.mDataProvider !== inProvider {
      self.mSortObserver?.removeSortObservers ()
      self.mSortObserver = nil
      self.mDataProvider?.detachClient (self)
      self.mDataProvider = inProvider
      self.mIsOrderedBefore = inSortCallBack
      self.mDataProvider?.attachClient (self)
      if inSortCallBack != nil {
        self.mSortObserver = EBModelNotifierEvent (
          self,
          addSortObserversCallback: inAddSortObserversCallback,
          removeSortObserversCallback: inRemoveSortObserversCallback
        )
      }else{
        self.mInternalArrayValue = EBReferenceArray ()
      }
    }
  }

  //····················································································································

  func resetDataProvider () {
    if self.mDataProvider != nil {
      self.mSortObserver = nil
      self.mDataProvider?.detachClient (self)
      self.mDataProvider = nil
      self.mIsOrderedBefore = nil
    }
  }

  //····················································································································

  override func notifyModelDidChange () {
    self.mModelEvent.observedObjectDidChange ()
    self.mModelArrayShouldBeComputed = true
    super.notifyModelDidChange ()
  }

  //····················································································································

  private final func computeModelArray () {
    if self.mModelArrayShouldBeComputed {
      self.mModelArrayShouldBeComputed = false
      let newArray : EBReferenceArray <DeviceSymbolInstanceInProject>
      if let dataProvider = self.mDataProvider {
        switch dataProvider.selection {
        case .empty :
          newArray = EBReferenceArray ()
          self.mTransientKind = .empty
        case .single (let v) :
          if let sortFunction = self.mIsOrderedBefore {
            newArray = EBReferenceArray (v.sorted { sortFunction ($0, $1) })
          }else{
            newArray = EBReferenceArray (v)
          }
          self.mTransientKind = .single
        case .multiple :
          newArray = EBReferenceArray ()
          self.mTransientKind = .multiple
        }
      }else{
        newArray = EBReferenceArray ()
        self.mTransientKind = .empty
      }
      self.mInternalArrayValue = newArray
    }
  }

  //····················································································································

  override var selection : EBSelection < [DeviceSymbolInstanceInProject] > {
    self.computeModelArray ()
    switch self.mTransientKind {
    case .empty :
      return .empty
    case .single :
      return .single (self.mInternalArrayValue.values)
    case .multiple :
      return .multiple
    }
  }

  //····················································································································

  override var propval : EBReferenceArray <DeviceSymbolInstanceInProject> {
    self.computeModelArray ()
    return self.mInternalArrayValue
  }

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    TransientArrayOfSuperOf DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

final class TransientArrayOfSuperOf_DeviceSymbolInstanceInProject <SUPER : EBManagedObject> : ReadOnlyArrayOf_DeviceSymbolInstanceInProject {

  //····················································································································
  //   Data provider
  //····················································································································

  private var mDataProvider : ReadOnlyAbstractArrayProperty <SUPER>? = nil
  private var mTransientKind : PropertyKind = .empty
  private var mModelArrayShouldBeComputed = true
  private var mModelEvent = EBModelEvent ()

  //····················································································································

  override init () {
    super.init ()
    self.mModelEvent.mEventCallBack = { [weak self] in self?.computeModelArray () }
  }

  //····················································································································

  func setDataProvider (_ inProvider : ReadOnlyAbstractArrayProperty <SUPER>?) {
    if self.mDataProvider !== inProvider {
      self.mDataProvider?.detachClient (self)
      self.mDataProvider = inProvider
      self.mDataProvider?.attachClient (self)
    }
  }

  //····················································································································

  override func notifyModelDidChange () {
    self.mModelEvent.observedObjectDidChange ()
    self.mModelArrayShouldBeComputed = true
    super.notifyModelDidChange ()
  }

  //····················································································································

  private final func computeModelArray () {
    if self.mModelArrayShouldBeComputed {
      self.mModelArrayShouldBeComputed = false
      var newModelArray : EBReferenceArray <SUPER>
      if let dataProvider = self.mDataProvider {
        switch dataProvider.selection {
        case .empty :
          newModelArray = EBReferenceArray ()
          self.mTransientKind = .empty
        case .single (let v) :
          newModelArray = EBReferenceArray (v)
          self.mTransientKind = .single
         case .multiple :
          newModelArray = EBReferenceArray ()
          self.mTransientKind = .multiple
        }
      }else{
        newModelArray = EBReferenceArray ()
        self.mTransientKind = .empty
      }
      var newArray = EBReferenceArray <DeviceSymbolInstanceInProject> ()
      for superObject in newModelArray.values {
        if let object = superObject as? DeviceSymbolInstanceInProject {
          newArray.append (object)
        }
      }
      self.mInternalArrayValue = newArray
    }
  }

  //····················································································································

  override var selection : EBSelection < [DeviceSymbolInstanceInProject] > {
    self.computeModelArray ()
    switch self.mTransientKind {
    case .empty :
      return .empty
    case .single :
      return .single (self.mInternalArrayValue.values)
    case .multiple :
      return .multiple
    }
  }

  //····················································································································

  override var propval : EBReferenceArray <DeviceSymbolInstanceInProject> {
    self.computeModelArray ()
    return self.mInternalArrayValue
  }

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    To many relationship read write: DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

class ReadWriteArrayOf_DeviceSymbolInstanceInProject : ReadOnlyArrayOf_DeviceSymbolInstanceInProject {

  //····················································································································

  func setProp (_ value :  EBReferenceArray <DeviceSymbolInstanceInProject>) { } // Abstract method

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    Proxy: ProxyArrayOf_DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

final class ProxyArrayOf_DeviceSymbolInstanceInProject : ReadWriteArrayOf_DeviceSymbolInstanceInProject {

  //····················································································································

  private var mModel : ReadWriteArrayOf_DeviceSymbolInstanceInProject? = nil

  //····················································································································

  func setModel (_ inModel : ReadWriteArrayOf_DeviceSymbolInstanceInProject?) {
    if self.mModel !== inModel {
      self.mModel?.detachClient (self)
      self.mModel = inModel
      self.mModel?.attachClient (self)
    }
  }

  //····················································································································

  override func notifyModelDidChange () {
    let newModelArray : EBReferenceArray <DeviceSymbolInstanceInProject>
    if let model = self.mModel {
      switch model.selection {
      case .empty :
        newModelArray = EBReferenceArray ()
      case .single (let v) :
        newModelArray = EBReferenceArray <DeviceSymbolInstanceInProject> (v)
      case .multiple :
        newModelArray = EBReferenceArray ()
      }
    }else{
      newModelArray = EBReferenceArray ()
    }
    self.mInternalArrayValue = newModelArray
    super.notifyModelDidChange ()
  }

  //····················································································································

  override func setProp (_ inArrayValue : EBReferenceArray <DeviceSymbolInstanceInProject>) {
    self.mModel?.setProp (inArrayValue)
  }

  //····················································································································

  override var selection : EBSelection < [DeviceSymbolInstanceInProject] > {
    if let model = self.mModel {
      return model.selection
    }else{
      return .empty
    }
  }

  //····················································································································

  override var propval : EBReferenceArray <DeviceSymbolInstanceInProject> {
    if let model = self.mModel {
      switch model.selection {
      case .empty, .multiple :
        return EBReferenceArray ()
      case .single (let v) :
        return EBReferenceArray (v)
      }
    }else{
      return EBReferenceArray ()
    }
  }

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    Stored Array: DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

class StoredArrayOf_DeviceSymbolInstanceInProject : ReadWriteArrayOf_DeviceSymbolInstanceInProject, EBSignatureObserverProtocol {

  //····················································································································

  init (usedForSignature inUsedForSignature : Bool) {
    self.mUsedForSignature = inUsedForSignature
    super.init ()
  }

  //····················································································································
  //   Signature ?
  //····················································································································

  private final let mUsedForSignature : Bool

  //····················································································································
  //   Undo manager
  //····················································································································

  weak final var ebUndoManager : EBUndoManager? = nil // SOULD BE WEAK

  //····················································································································
  //   Opposite relationship management
  //····················································································································

  private final var mSetOppositeRelationship : Optional < (_ inManagedObject : DeviceSymbolInstanceInProject) -> Void > = nil
  private final var mResetOppositeRelationship : Optional < (_ inManagedObject : DeviceSymbolInstanceInProject) -> Void > = nil

  //····················································································································

  final func setOppositeRelationShipFunctions (setter inSetter : @escaping (_ inManagedObject : DeviceSymbolInstanceInProject) -> Void,
                                               resetter inResetter : @escaping (_ inManagedObject : DeviceSymbolInstanceInProject) -> Void) {
    self.mSetOppositeRelationship = inSetter
    self.mResetOppositeRelationship = inResetter
  }

  //····················································································································

  #if BUILD_OBJECT_EXPLORER
    final var mValueExplorer : NSPopUpButton? {
      didSet {
        if let unwrappedExplorer = self.mValueExplorer {
          switch self.selection {
          case .empty, .multiple :
            break ;
          case .single (let v) :
            updateManagedObjectToManyRelationshipDisplay (objectArray: v, popUpButton: unwrappedExplorer)
          }
        }
      }
    }
  #endif

  //····················································································································
  // Model will change
  //····················································································································

  override func notifyModelDidChangeFrom (oldValue inOldValue : EBReferenceArray <DeviceSymbolInstanceInProject>) {
  //--- Register old value in undo manager
    self.ebUndoManager?.registerUndo (withTarget: self) { $0.mInternalArrayValue = inOldValue }
  //---
    super.notifyModelDidChangeFrom (oldValue: inOldValue)
  }

  //····················································································································
  // Model did change
  //····················································································································

  override func notifyModelDidChange () {
  //--- Update explorer
    #if BUILD_OBJECT_EXPLORER
      if let valueExplorer = self.mValueExplorer {
        updateManagedObjectToManyRelationshipDisplay (objectArray: self.mInternalArrayValue.values, popUpButton: valueExplorer)
      }
    #endif
  //--- Notify observers
    self.observedObjectDidChange ()
  //---
    super.notifyModelDidChange ()
  }

  //····················································································································
  // Update observers
  //····················································································································

  override func updateObservers (removedSet inRemovedSet : EBReferenceSet <DeviceSymbolInstanceInProject>,
                                 addedSet inAddedSet : EBReferenceSet <DeviceSymbolInstanceInProject>) {
    for managedObject in inRemovedSet.values {
      if self.mUsedForSignature {
        managedObject.setSignatureObserver (observer: nil)
      }
      self.mResetOppositeRelationship? (managedObject)
   }
  //---
    for managedObject in inAddedSet.values {
      if self.mUsedForSignature {
        managedObject.setSignatureObserver (observer: self)
      }
      self.mSetOppositeRelationship? (managedObject)
    }
  //---
    super.updateObservers (removedSet: inRemovedSet, addedSet: inAddedSet)
 }

  //····················································································································

  override final var selection : EBSelection < [DeviceSymbolInstanceInProject] > { return .single (self.mInternalArrayValue.values) }

  //····················································································································

  override func setProp (_ inValue : EBReferenceArray <DeviceSymbolInstanceInProject>) { self.mInternalArrayValue = inValue }

  //····················································································································

  override final var propval : EBReferenceArray <DeviceSymbolInstanceInProject> { return self.mInternalArrayValue }

  //····················································································································

  final func remove (_ object : DeviceSymbolInstanceInProject) {
    if let idx = self.mInternalArrayValue.firstIndex (of: object) {
      self.mInternalArrayValue.remove (at: idx)
    }
  }

  //····················································································································

  final func add (_ object : DeviceSymbolInstanceInProject) {
    if !self.internalSetValue.contains (object) {
      self.mInternalArrayValue.append (object)
    }
  }

  //····················································································································
  //   signature
  //····················································································································

  private weak final var mSignatureObserver : EBSignatureObserverProtocol? = nil // SOULD BE WEAK

  //····················································································································

  private final var mSignatureCache : UInt32? = nil

  //····················································································································

  final func setSignatureObserver (observer : EBSignatureObserverProtocol?) {
    self.mSignatureObserver?.clearSignatureCache ()
    self.mSignatureObserver = observer
    observer?.clearSignatureCache ()
    self.clearSignatureCache ()
 }

  //····················································································································

  final func signature () -> UInt32 {
    let computedSignature : UInt32
    if let s = self.mSignatureCache {
      computedSignature = s
    }else{
      computedSignature = self.computeSignature ()
      self.mSignatureCache = computedSignature
    }
    return computedSignature
  }

  //····················································································································

  final private func computeSignature () -> UInt32 {
    var crc : UInt32 = 0
    for object in self.mInternalArrayValue.values {
      crc.accumulateUInt32 (object.signature ())
    }
    return crc
  }

  //····················································································································

  final func clearSignatureCache () {
    if self.mSignatureCache != nil {
      self.mSignatureCache = nil
      self.mSignatureObserver?.clearSignatureCache ()
    }
  }

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    Stand alone Array: DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

final class StandAloneArrayOf_DeviceSymbolInstanceInProject : ReadWriteArrayOf_DeviceSymbolInstanceInProject {

  //····················································································································

  override var selection : EBSelection < [DeviceSymbolInstanceInProject] > { return .single (self.mInternalArrayValue.values) }

  //····················································································································

  override func setProp (_ inValue : EBReferenceArray <DeviceSymbolInstanceInProject>) { self.mInternalArrayValue = inValue }

  //····················································································································

  override var propval : EBReferenceArray <DeviceSymbolInstanceInProject> { return self.mInternalArrayValue }

  //····················································································································

  override func notifyModelDidChange () {
    self.observedObjectDidChange ()
    super.notifyModelDidChange ()
  }

  //····················································································································

  func remove (_ object : DeviceSymbolInstanceInProject) {
    if let idx = self.mInternalArrayValue.firstIndex (of: object) {
      self.mInternalArrayValue.remove (at: idx)
    }
  }

  //····················································································································

  func add (_ object : DeviceSymbolInstanceInProject) {
    if !self.internalSetValue.contains (object) {
      self.mInternalArrayValue.append (object)
    }
  }

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//    Preferences array: DeviceSymbolInstanceInProject
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

final class PreferencesArrayOf_DeviceSymbolInstanceInProject : StoredArrayOf_DeviceSymbolInstanceInProject {

  //····················································································································

  private let mPrefKey : String
  private let mObserverForWritingPreferences = EBOutletEvent ()

  //····················································································································

  init (prefKey : String) {
    self.mPrefKey = prefKey
    super.init (usedForSignature: false)
    if let array = UserDefaults.standard.array (forKey: prefKey) as? [NSDictionary] {
      var objectArray = EBReferenceArray <DeviceSymbolInstanceInProject> ()
      for dictionary in array {
        if let object = newInstanceOfEntityNamed (self.ebUndoManager, "DeviceSymbolInstanceInProject") as? DeviceSymbolInstanceInProject {
          object.setUpAtomicPropertiesWithDictionary (dictionary)
          objectArray.append (object)
        }
      }
      self.setProp (objectArray)
    }
    self.addEBObserverOf_mSymbolInstanceName (self.mObserverForWritingPreferences)
    self.mObserverForWritingPreferences.mEventCallBack = { self.writeInPreferences () }
 }

  //····················································································································

  private func writeInPreferences () {
    var dictionaryArray = [NSDictionary] ()
    for object in self.mInternalArrayValue.values {
      let d = NSMutableDictionary ()
      object.saveIntoDictionary (d)
      d [ENTITY_KEY] = nil // Remove entity key, not used in preferences
      dictionaryArray.append (d)
    }
    UserDefaults.standard.set (dictionaryArray, forKey: self.mPrefKey)
  }

  //····················································································································

}

//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

