public static IIntProperty CreateInt(IDDK ddk, IStruct structure, string name, string helpText = null) { ITypeInt typeInt = CreateIntType(ddk); IIntProperty result = structure.CreateProperty(name, helpText, typeInt); return(result); }
public PumpProperties(IDDK ddk, IDevice device) { if (ddk == null) { throw new ArgumentNullException("ddk"); } if (device == null) { throw new ArgumentNullException("device"); } Ready = Property.CreateReady(ddk, device); // Pressure.LowerLimit // Pressure.UpperLimit // Pressure.Value m_Pressure = device.CreateStruct("Pressure", "The pump pressure."); ITypeDouble pressureType = ddk.CreateDouble(0, 400, 3); pressureType.Unit = UnitConversionEx.PhysUnitName(UnitConversion.PhysUnitEnum.PhysUnit_Bar); PressureValue = m_Pressure.CreateStandardProperty(StandardPropertyID.Value, pressureType); PressureValue.Update(0); PressureLowerLimit = m_Pressure.CreateStandardProperty(StandardPropertyID.LowerLimit, pressureType); PressureLowerLimit.Update(pressureType.Minimum); PressureUpperLimit = m_Pressure.CreateStandardProperty(StandardPropertyID.UpperLimit, pressureType); PressureUpperLimit.Update(pressureType.Maximum); m_Pressure.DefaultGetProperty = PressureValue; }
/// <inheritdoc /> public override void VisitStruct(IStruct @struct) { if (@struct.Name == null) { // A struct has been declared with no name. For example `struct {}`. this.AddError( CompilerMessageId.StructMustHaveAName, @struct.Node.STRUCT().Symbol); } else { if (@struct.Parent.IsMemberNameAlreadyDeclared(@struct)) { // Another type has already been declared with the same name. // For example: // ``` // enum User {} // struct User {} // ``` this.AddError( CompilerMessageId.NameAlreadyDeclared, @struct.Node.name, @struct.Name); } } base.VisitStruct(@struct); }
/// <summary> /// Refresh ObjectReferences, throws NPE for broken ObjectReferences. /// /// An ObjectReference is considered broken if it's object has been deleted. /// </summary> /// <param name="instance"></param> private void doRemap(GameObject instance) { Stack <IPropertyContainer> toVisit = new Stack <IPropertyContainer>(); toVisit.Push(instance); while (toVisit.Any()) { IPropertyContainer currentInstance = toVisit.Pop(); foreach (IProperty property in currentInstance.Properties) { switch (property) { case PropertyObject po: { ObjectReference reference = po.Value; if (reference.IsId && reference.ObjectId >= startIndex) { reference.ObjectId = MappedObjects[reference.ObjectId].Id; } break; } case PropertyArray pa: { IArkArray <IStruct> structList = pa.GetTypedValue <IStruct>(); IArkArray <ObjectReference> objectReferenceList = pa.GetTypedValue <ObjectReference>(); if (structList != null) { foreach (IStruct aStruct in structList) { if (aStruct is IPropertyContainer container) { toVisit.Push(container); } } } else if (objectReferenceList != null) { foreach (ObjectReference reference in objectReferenceList) { if (reference.IsId && reference.ObjectId >= startIndex) { reference.ObjectId = MappedObjects[reference.ObjectId].Id; } } } break; } case PropertyStruct ps: { IStruct aStruct = ps.Value; if (aStruct is IPropertyContainer container) { toVisit.Push(container); } break; } } } } }
public void Visit(uint tag, string name, bool require, ref IStruct val) { if (val == null) { return; } if (require) { PackHead(tag, SdpPackDataType.SdpPackDataType_StructBegin); val.Visit(this); PackHead(0u, SdpPackDataType.SdpPackDataType_StructEnd); } else { SdpWriter sdp = new SdpWriter(); sdp.PackHead(tag, SdpPackDataType.SdpPackDataType_StructBegin); uint iStartPos = sdp.CurrPos(); val.Visit(sdp); if (iStartPos < sdp.CurrPos()) { sdp.PackHead(0u, SdpPackDataType.SdpPackDataType_StructEnd); WriteRawByte(sdp.ToBytes()); } } }
public object Read(SdpReader reader, uint tag, bool require, object value) { IStruct t = value as IStruct; reader.Visit(tag, null, require, ref t); return(t); }
public bool Equals(Struct that) { //Weird that @that cannot be used because `that` is already used. IStruct @this = this, _that = that as IStruct; return(IStructExtensions.EqualsIStruct(ref @this, ref _that)); }
public static double GetNumericValue(IStruct structure, string name) { if (structure == null) { throw new ArgumentNullException("structure"); } ISymbol symbol = structure.Child(name); if (symbol == null) { throw new InvalidOperationException("Could not find the property " + name + " in structure " + structure.Name); } INumericProperty property = symbol as INumericProperty; if (property == null) { throw new InvalidOperationException("Symbol " + symbol.Name + " type " + symbol.GetType().FullName + " is not the expected " + typeof(INumericProperty).FullName); } double result = property.Value.GetValueOrDefault(); return(result); }
public void Validate(IStruct type) { Validate(type, type.Methods); Validate(type, type.Fields); Validate(type, type.Operators); Validate(type, type.Constructors); }
public static IStringProperty CreateString(IDDK ddk, IStruct structure, string name, string helpText = null, int valueMaxLength = 300) { if (valueMaxLength <= 0) { throw new ArgumentOutOfRangeException("Parameter valueMaxLength must be > 0"); } return(structure.CreateProperty(name, helpText, ddk.CreateString(valueMaxLength))); }
public void Write(object value, SdpWriter writer, uint tag, bool require) { if (value != null) { IStruct t = (IStruct)value; writer.Visit(tag, null, require, ref t); } }
public override void VisitStruct <TNamespace, TDocument, TProject, TSolution, TAttributeGroup, TGenericParameter, TInterfaceReference, TEventCollection, TPropertyCollection, TIndexerCollection, TMethodCollection, TFieldCollection, TConstructor, TOperatorOverload, TConversionOperator, TNestedClassCollection, TNestedDelegate, TNestedEnum, TNestedInterface, TNestedStructCollection, TStaticConstructor>( IStruct <TNamespace, TDocument, TProject, TSolution, TAttributeGroup, TGenericParameter, TInterfaceReference, TEventCollection, TPropertyCollection, TIndexerCollection, TMethodCollection, TFieldCollection, TConstructor, TOperatorOverload, TConversionOperator, TNestedClassCollection, TNestedDelegate, TNestedEnum, TNestedInterface, TNestedStructCollection, TStaticConstructor> @struct) { if (@struct.Namespace != null) { @struct.Namespace.Accept(this); } }
public static IIntProperty CreateEnum <T>(IDDK ddk, IStruct structure, string name, T value, string helpText = null) { ITypeInt typeInt = CreateEnumType <T>(ddk); IIntProperty result = structure.CreateProperty(name, string.Empty, typeInt); UpdateEnumProperty(result, value, helpText); return(result); }
public override string ToString() { //return base.ToString(); IStruct @this = this; return(IStructExtensions.ToIStructString(ref @this)); }
public static bool Get(ref IStruct @this) { System.TypedReference tr = __makeref(@this); @this = __refvalue(tr, IStruct); return(true); }
public override int GetHashCode() { //return base.GetHashCode(); IStruct @this = this; return(IStructExtensions.GetHashCodeIStruct(ref @this)); }
private static ITypeName GetName(this IStruct structElement, ISubstitution substitution, IDictionary <DeclaredElementInstance, IName> seenElements) { var structName = structElement.GetAssemblyQualifiedName(substitution, seenElements); return(Names.Type("s:{0}", structName)); }
public void Add(IVariable variable) { Contract.Requires <ArgumentException>(variable != null); IStruct varStruct = variable as IStruct; switch (variable.Type) { case Shaders.Type.ConstantBuffer: variable.Index = cbCount++; break; case Shaders.Type.Texture2D: case Shaders.Type.Texture3D: case Shaders.Type.TextureCube: variable.Index = textureCount++; break; case Shaders.Type.Sampler: case Shaders.Type.SamplerComparisonState: variable.Index = samplerCount++; break; case Shaders.Type.Struct: variable.Index = customTypeCount++; break; case Shaders.Type.Matrix: case Shaders.Type.Vector: case Shaders.Type.FloatArray: case Shaders.Type.Float: case Shaders.Type.Float2: case Shaders.Type.Float3: case Shaders.Type.Float4: variable.Index = constantsCount++; break; } if (variables.All(kvp => kvp.Value.Name != variable.Name)) { variables.Add(Variable.GetRegister(variable), variable); } if (varStruct == null) { return; } var childStructs = from vS in varStruct.Variables.OfType <IStruct>() where vS.CustomType != CustomType.None select vS; foreach (IStruct childStruct in childStructs) { customTypeCount++; Add(childStruct); } }
private static LocalList <IDeclaredElement> GetMarksFromStruct([NotNull] IStruct @struct) { var result = new LocalList <IDeclaredElement>(); var superTypes = @struct.GetAllSuperTypes(); var interfaces = new LocalList <ITypeElement>(); foreach (var super in superTypes) { if (!super.IsInterfaceType()) { continue; } var superElement = super.GetTypeElement(); if (superElement == null) { continue; } if (superElement.HasAttributeInstance(KnownTypes.JobProducerAttribute, AttributesSource.Self)) { interfaces.Add(superElement); } } if (interfaces.Count == 0) { return(result); } var canBeOverridenByInterfaceMethods = new LocalList <IMethod>(); foreach (var method in @struct.Methods) { if (!method.IsOverride && method.HasImmediateSuperMembers()) { canBeOverridenByInterfaceMethods.Add(method); } } foreach (var @interface in interfaces) { foreach (var interfaceMethod in @interface.Methods) { foreach (var structMethod in canBeOverridenByInterfaceMethods) { if (structMethod.OverridesOrImplements(interfaceMethod)) { result.Add(structMethod); } } } } return(result); }
protected void TestStruct(Type type) { IStruct @struct = TypeCache.Structs[type.Name()]; string namespaceName = new FindNamespaceForStructVisitor(@struct).Result; LoadedDocument document = CreateLoadedDocument(new StructFactory(@struct).Value, namespaceName); string documentText = document.ToSourceCode(); Verify(type, documentText); }
public static IDoubleProperty CreateDouble(IDDK ddk, IStruct structure, string name, Nullable <UnitConversion.PhysUnitEnum> unit = null, string helpText = null, double minValue = double.MinValue, double maxValue = double.MaxValue, int precision = 3) { ITypeDouble typeDouble = CreateDoubleType(ddk, unit, minValue, maxValue, precision); IDoubleProperty result = structure.CreateProperty(name, helpText, typeDouble); return(result); }
internal void Create(IDDK cmDDK, string deviceName) { m_DDK = cmDDK; m_Device = m_DDK.CreateDevice(deviceName, "Pump device"); IStringProperty typeProperty = m_Device.CreateProperty("DeviceType", "The DeviceType property tells us which component we are talking to.", m_DDK.CreateString(20)); typeProperty.Update("Pump"); // A data type for our pump flow ITypeDouble tFlow = m_DDK.CreateDouble(0, 10, 1); tFlow.Unit = "ml/min"; // Create our flow handler. The flow handler creates a Flow.Nominal, // a Flow.Value and 4 eluent component properties for us. m_FlowHandler = m_Device.CreateFlowHandler(tFlow, 4, 2); m_FlowHandler.FlowNominalProperty.OnSetProperty += OnSetFlow; // initialize the flow m_FlowHandler.FlowNominalProperty.Update(0); // initialize the components m_FlowHandler.ComponentProperties[0].Update(100.0); m_FlowHandler.ComponentProperties[1].Update(0); m_FlowHandler.ComponentProperties[2].Update(0); m_FlowHandler.ComponentProperties[3].Update(0); // A type for our pump pressure ITypeDouble tPressure = m_DDK.CreateDouble(0, 400, 1); tPressure.Unit = "bar"; // We create a struct for the pressure with Value, LowerLimit and UpperLimit m_PressureStruct = m_Device.CreateStruct("Pressure", "The pump pressure."); m_PressureValue = m_PressureStruct.CreateStandardProperty(StandardPropertyID.Value, tPressure); m_PressureLowerLimit = m_PressureStruct.CreateStandardProperty(StandardPropertyID.LowerLimit, tPressure); m_PressureLowerLimit.OnSetProperty += new SetPropertyEventHandler(OnSetPressureLowerLimit); m_PressureLowerLimit.Update(0.0); m_PressureUpperLimit = m_PressureStruct.CreateStandardProperty(StandardPropertyID.UpperLimit, tPressure); m_PressureUpperLimit.OnSetProperty += new SetPropertyEventHandler(OnSetPressureUpperLimit); m_PressureUpperLimit.Update(400.0); m_PressureStruct.DefaultGetProperty = m_PressureValue; m_Device.OnTransferPreflightToRun += new PreflightEventHandler(OnTransferPreflightToRun); }
public override bool Equals(object obj) { if ((obj is IStruct).Equals(false)) { return(false); } IStruct @this = this, that = obj as IStruct; return(IStructExtensions.EqualsIStruct(ref @this, ref that)); }
public static IStruct GetStruct(IPage page, string name) { ISymbol symbol = GetSymbol(page, name); IStruct result = symbol as IStruct; if (result == null) { throw new InvalidOperationException("Symbol " + symbol.Name + " type " + symbol.GetType().FullName + " is not the expected " + typeof(IStruct).FullName); } return(result); }
public static bool Equals(ref IStruct @this, ref IStruct that) { //Use the hashcode of a System.TypedReference return(__makeref(@this).GetHashCode().Equals((__makeref(that).GetHashCode()))); //Box //return System.TypedReference.Equals(@this, that); //System.TypedReference is clearly not an Object. //__makeref(@this).Equals(__makeref(that)); }
public void Visit(uint tag, string name, bool require, ref IStruct val) { if (SkipToTag(tag)) { SdpPackDataType type = UnPackHead(ref tag); if (type == SdpPackDataType.SdpPackDataType_StructBegin) { val.Visit(this); SkipToStructEnd(); } } }
private static void DemoCode(IEditorPlugIn plugIn, IPage page) { IList <ISymbol> deviceNodes = plugIn.Symbol.SelectSymbols("//Device[Properties[@Name='ModelNo' and @Value='Pump']]"); IStruct temperatureSrut = Util.Properties.GetStruct(page, "Temperature"); double temperatureNominal = Util.Properties.GetNumericValue(temperatureSrut, "Nominal"); double temperatureValue = Util.Properties.GetNumericValue(temperatureSrut, "Value"); double temperatureMin = Util.Properties.GetNumericValue(temperatureSrut, "LowerLimit"); double temperatureMax = Util.Properties.GetNumericValue(temperatureSrut, "UpperLimit"); bool ready = Util.Properties.GetBoolValue(page, "Ready"); foreach (ISymbol symbol in deviceNodes) { ISymbol symbolFlowStruct = symbol.Child("Flow"); if (symbolFlowStruct != null) { IStruct structure = symbolFlowStruct as IStruct; if (structure == null) { string errText = "Symbol " + symbolFlowStruct.Name + " must always be of type " + typeof(IStruct).FullName + ", but is " + symbolFlowStruct.GetType().FullName; throw new InvalidCastException(errText); } ISymbol symbolFlow = structure.Child("Value"); if (symbolFlow == null) { throw new InvalidOperationException("Could not find the property Value in structure " + symbolFlowStruct.Name); } double flow = (symbolFlow as INumericProperty).Value.GetValueOrDefault(); // Pump_Name Flow Value Trace.WriteLine(symbol.Name + "." + symbolFlowStruct.Name + "." + plugIn.Symbol.Name + " = " + flow.ToString()); } ISymbol symbolReady = symbol.Child(SymbolName.Ready); if (symbolReady != null) { INumericProperty propertyReady = symbolReady as INumericProperty; if (propertyReady != null) { ready = Util.GetBool(propertyReady); Trace.WriteLine(propertyReady.Name + " = " + ready.ToString()); if (propertyReady.Writeable) { // Pump_Name Ready Trace.WriteLine(symbol.Name + "." + propertyReady.Name + " is Writable"); } } } } }
//struct.As<class>: return null if not possible public static Y As <Y, X>(this X x, IStruct <X> _ = null, IClass <Y> _y = null) where X : struct where Y : class { try { return((Y)(object)x); } catch (InvalidCastException) { return(null); } }
private static string GetStructModifiersDisplay([NotNull] IStruct @struct) { string display = null; if (@struct.IsByRefLike) { display += "ref "; } if (@struct.IsReadonly) { display += "readonly "; } return(display); }
public Context(Context parent, IStruct newSelf) { Self = newSelf; Parent = parent.Self; if (parent.Offset.HasValue) { Stream = new SubStream((parent.Stream as SubStream)?.Root ?? parent.Stream, parent.Offset.Value); } else { Stream = new SubStream(parent.Stream, parent.Stream.Position); } Variables = parent.Variables; }