Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / QueryValue.cs / 1 / QueryValue.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System.Collections; using System.Diagnostics; using System.Xml; internal enum ValueDataType : byte { None = 0, Boolean, Double, StackFrame, Sequence, String } // Value is like Variant. Since a Value is only temporary storage, we use memory to avoid typecasting type // casting, which in C# is expensive. Value contains storage for every possible XPath data type. // We avoid data copying by being smart about how we pass Value around - values are either accessed via // method calls, or the value object itself is passed by ref // // The filter engine never deals with a single value per se. We only work with Sets of Values. A single value // is a ValueSet of size 1 // internal struct Value { bool boolVal; double dblVal; StackFrame frame; NodeSequence sequence; string strVal; ValueDataType type; internal bool Boolean { get { return this.boolVal; } set { this.type = ValueDataType.Boolean; this.boolVal = value; } } internal double Double { get { return this.dblVal; } set { this.type = ValueDataType.Double; this.dblVal = value; } } internal StackFrame Frame { get { return this.frame; } #if NO set { this.type = ValueDataType.StackFrame; this.frame = value; } #endif } #if NO internal int FrameCount { get { return this.frame.Count; } } #endif internal int FrameEndPtr { #if NO get { return this.frame.endPtr; } #endif set { DiagnosticUtility.DebugAssert(this.IsType(ValueDataType.StackFrame), ""); this.frame.EndPtr = value; } } #if NO internal int FrameBasePtr { get { return this.frame.basePtr; } } internal int StackPtr { get { return this.frame.basePtr - 1; } } #endif internal int NodeCount { get { return this.sequence.Count; } } internal NodeSequence Sequence { get { return this.sequence; } set { this.type = ValueDataType.Sequence; this.sequence = value; } } internal string String { get { return this.strVal; } set { this.type = ValueDataType.String; this.strVal = value; } } internal ValueDataType Type { get { return this.type; } } internal void Add(double val) { DiagnosticUtility.DebugAssert(ValueDataType.Double == this.type, ""); this.dblVal += val; } #if NO internal void Clear() { this.type = ValueDataType.None; this.sequence = null; } #endif internal void Clear(ProcessingContext context) { if (ValueDataType.Sequence == this.type) { this.ReleaseSequence(context); } this.type = ValueDataType.None; } // Fully general compare internal bool CompareTo(ref Value val, RelationOperator op) { switch (this.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: switch (val.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return QueryValueModel.Compare(this.boolVal, val.boolVal, op); case ValueDataType.Double: return QueryValueModel.Compare(this.boolVal, val.dblVal, op); case ValueDataType.Sequence: return QueryValueModel.Compare(this.boolVal, val.sequence, op); case ValueDataType.String: return QueryValueModel.Compare(this.boolVal, val.strVal, op); } case ValueDataType.Double: switch (val.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return QueryValueModel.Compare(this.dblVal, val.boolVal, op); case ValueDataType.Double: return QueryValueModel.Compare(this.dblVal, val.dblVal, op); case ValueDataType.Sequence: return QueryValueModel.Compare(this.dblVal, val.sequence, op); case ValueDataType.String: return QueryValueModel.Compare(this.dblVal, val.strVal, op); } case ValueDataType.Sequence: switch (val.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return QueryValueModel.Compare(this.sequence, val.boolVal, op); case ValueDataType.Double: return QueryValueModel.Compare(this.sequence, val.dblVal, op); case ValueDataType.Sequence: return QueryValueModel.Compare(this.sequence, val.sequence, op); case ValueDataType.String: return QueryValueModel.Compare(this.sequence, val.strVal, op); } case ValueDataType.String: switch (val.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return QueryValueModel.Compare(this.strVal, val.boolVal, op); case ValueDataType.Double: return QueryValueModel.Compare(this.strVal, val.dblVal, op); case ValueDataType.Sequence: return QueryValueModel.Compare(this.strVal, val.sequence, op); case ValueDataType.String: return QueryValueModel.Compare(this.strVal, val.strVal, op); } } } internal bool CompareTo(double val, RelationOperator op) { switch (this.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return QueryValueModel.Compare(this.boolVal, val, op); case ValueDataType.Double: return QueryValueModel.Compare(this.dblVal, val, op); case ValueDataType.Sequence: return QueryValueModel.Compare(this.sequence, val, op); case ValueDataType.String: return QueryValueModel.Compare(this.strVal, val, op); } } internal void ConvertTo(ProcessingContext context, ValueDataType newType) { DiagnosticUtility.DebugAssert(null != context, ""); if (newType == this.type) { return; } switch(newType) { default: break; case ValueDataType.Boolean: this.boolVal = this.ToBoolean(); break; case ValueDataType.Double: this.dblVal = this.ToDouble(); break; case ValueDataType.String: this.strVal = this.ToString(); break; } if (ValueDataType.Sequence == this.type) { this.ReleaseSequence(context); } this.type = newType; } internal bool Equals(string val) { switch (this.type) { default: DiagnosticUtility.DebugAssert("Invalid Type"); return false; case ValueDataType.Boolean: return QueryValueModel.Equals(this.boolVal, val); case ValueDataType.Double: return QueryValueModel.Equals(this.dblVal, val); case ValueDataType.Sequence: return QueryValueModel.Equals(this.sequence, val); case ValueDataType.String: return QueryValueModel.Equals(this.strVal, val); } } internal bool Equals(double val) { switch (this.type) { default: DiagnosticUtility.DebugAssert("Invalid Type"); return false; case ValueDataType.Boolean: return QueryValueModel.Equals(this.boolVal, val); case ValueDataType.Double: return QueryValueModel.Equals(this.dblVal, val); case ValueDataType.Sequence: return QueryValueModel.Equals(this.sequence, val); case ValueDataType.String: return QueryValueModel.Equals(val, this.strVal); } } #if NO internal bool Equals(bool val) { switch (this.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new QueryProcessingException(QueryProcessingError.TypeMismatch), TraceEventType.Critical); case ValueDataType.Boolean: return QueryValueModel.Equals(this.boolVal, val); case ValueDataType.Double: return QueryValueModel.Equals(this.dblVal, val); case ValueDataType.Sequence: return QueryValueModel.Equals(this.sequence, val); case ValueDataType.String: return QueryValueModel.Equals(this.strVal, val); } } #endif internal bool GetBoolean() { if (ValueDataType.Boolean != this.type) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); } return this.boolVal; } internal double GetDouble() { if (ValueDataType.Double != this.type) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); } return this.dblVal; } internal NodeSequence GetSequence() { if (ValueDataType.Sequence != this.type) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); } return this.sequence; } internal string GetString() { if (ValueDataType.String != this.type) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); } return this.strVal; } internal bool IsType(ValueDataType type) { return (type == this.type); } internal void Multiply(double val) { DiagnosticUtility.DebugAssert(ValueDataType.Double == this.type, ""); this.dblVal *= val; } internal void Negate() { DiagnosticUtility.DebugAssert(this.type == ValueDataType.Double, ""); this.dblVal = -this.dblVal; } internal void Not() { DiagnosticUtility.DebugAssert(this.type == ValueDataType.Boolean, ""); this.boolVal = !this.boolVal; } internal void ReleaseSequence(ProcessingContext context) { DiagnosticUtility.DebugAssert(null != context && this.type == ValueDataType.Sequence && null != this.sequence, ""); context.ReleaseSequence(this.sequence); this.sequence = null; } internal void StartFrame(int start) { this.type = ValueDataType.StackFrame; this.frame.basePtr = start + 1; this.frame.endPtr = start; } #if NO internal void Subtract(double dblVal) { DiagnosticUtility.DebugAssert(ValueDataType.Double == this.type, ""); this.dblVal -= dblVal; } #endif internal bool ToBoolean() { switch(this.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return this.boolVal; case ValueDataType.Double: return QueryValueModel.Boolean(this.dblVal); case ValueDataType.Sequence: return QueryValueModel.Boolean(this.sequence); case ValueDataType.String: return QueryValueModel.Boolean(this.strVal); } } internal double ToDouble() { switch(this.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return QueryValueModel.Double(this.boolVal); case ValueDataType.Double: return this.dblVal; case ValueDataType.Sequence: return QueryValueModel.Double(this.sequence); case ValueDataType.String: return QueryValueModel.Double(this.strVal); } } public override string ToString() { switch(this.type) { default: throw DiagnosticUtility.ExceptionUtility.ThrowHelperCritical(new QueryProcessingException(QueryProcessingError.TypeMismatch)); case ValueDataType.Boolean: return QueryValueModel.String(this.boolVal); case ValueDataType.Double: return QueryValueModel.String(this.dblVal); case ValueDataType.Sequence: return QueryValueModel.String(this.sequence); case ValueDataType.String: return this.strVal; } } internal void Update(ProcessingContext context, bool val) { if (ValueDataType.Sequence == this.type) { context.ReleaseSequence(this.sequence); } this.Boolean = val; } internal void Update(ProcessingContext context, double val) { if (ValueDataType.Sequence == this.type) { context.ReleaseSequence(this.sequence); } this.Double = val; } internal void Update(ProcessingContext context, string val) { if (ValueDataType.Sequence == this.type) { context.ReleaseSequence(this.sequence); } this.String = val; } internal void Update(ProcessingContext context, NodeSequence val) { if (ValueDataType.Sequence == this.type) { context.ReleaseSequence(this.sequence); } this.Sequence = val; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataSourceHelper.cs
- _LazyAsyncResult.cs
- FontStretchConverter.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- Column.cs
- SetterBase.cs
- InstallerTypeAttribute.cs
- OutputCache.cs
- XmlSchemaChoice.cs
- StringWriter.cs
- TypeReference.cs
- SqlBulkCopyColumnMapping.cs
- BeginStoryboard.cs
- FrameworkContentElementAutomationPeer.cs
- GridPatternIdentifiers.cs
- MultipleViewProviderWrapper.cs
- TemplateField.cs
- EdmFunctions.cs
- BoundPropertyEntry.cs
- ObjectDataSourceDisposingEventArgs.cs
- ProcessHostServerConfig.cs
- SoapIncludeAttribute.cs
- ImageFormat.cs
- SetIterators.cs
- MDIWindowDialog.cs
- CallbackValidator.cs
- ParentControlDesigner.cs
- ThreadInterruptedException.cs
- CubicEase.cs
- FontFamilyConverter.cs
- WindowsFont.cs
- EntitySqlQueryCacheEntry.cs
- EntityType.cs
- ComponentManagerBroker.cs
- WindowsGraphics.cs
- HierarchicalDataSourceControl.cs
- SqlCharStream.cs
- ElementMarkupObject.cs
- SettingsContext.cs
- OleDbWrapper.cs
- WindowInteropHelper.cs
- DefaultPrintController.cs
- RegexBoyerMoore.cs
- XmlDownloadManager.cs
- SQLMoney.cs
- CapabilitiesAssignment.cs
- DataGridPageChangedEventArgs.cs
- ToggleButtonAutomationPeer.cs
- SrgsRule.cs
- MultiTrigger.cs
- LassoHelper.cs
- GridView.cs
- StreamingContext.cs
- MethodSignatureGenerator.cs
- XmlDocument.cs
- XmlDownloadManager.cs
- MouseGestureValueSerializer.cs
- SponsorHelper.cs
- ImageBrush.cs
- SchemaTypeEmitter.cs
- XmlUtilWriter.cs
- ReferenceConverter.cs
- NumericUpDown.cs
- RelationshipConverter.cs
- DelegatedStream.cs
- DataRowComparer.cs
- NameValueCache.cs
- objectresult_tresulttype.cs
- RoutedCommand.cs
- DesignerDataTable.cs
- RegistryKey.cs
- XamlTypeMapper.cs
- ControlBuilder.cs
- RenderingBiasValidation.cs
- CollectionCodeDomSerializer.cs
- MarkupCompilePass2.cs
- DecimalStorage.cs
- PixelFormats.cs
- FaultFormatter.cs
- FormViewInsertEventArgs.cs
- XmlElement.cs
- MimeReflector.cs
- ViewStateModeByIdAttribute.cs
- _TimerThread.cs
- XmlTextAttribute.cs
- ToolStripGrip.cs
- KeyNameIdentifierClause.cs
- ClrProviderManifest.cs
- FilteredDataSetHelper.cs
- SchemaImporterExtensionElementCollection.cs
- AppearanceEditorPart.cs
- XmlJsonReader.cs
- PartManifestEntry.cs
- StructuralComparisons.cs
- SafeNativeMethods.cs
- ButtonBase.cs
- EntityProxyTypeInfo.cs
- GetPageNumberCompletedEventArgs.cs
- MergePropertyDescriptor.cs
- SvcMapFile.cs