5 // Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
7 // Copyright (c) 2010 Jérémie "Garuma" Laval
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 using System.Threading;
30 using System.Collections.Generic;
32 namespace System.Linq.Parallel.QueryNodes
34 // The first four elements correspond to the public operator With*
35 // Last CancellationToken parameter is used internally for ImplementerToken
36 using OptionsList = Tuple<ParallelMergeOptions?, ParallelExecutionMode?, CancellationToken?, int, CancellationTokenSource>;
39 interface QueryOptionNode : IVisitableNode {
40 OptionsList GetOptions ();
43 internal class QueryOptionNode<T> : QueryChildNode<T, T>, QueryOptionNode
46 public QueryOptionNode (QueryBaseNode<T> parent)
52 public virtual OptionsList GetOptions ()
54 return new OptionsList (null, null, null, -1, null);
57 internal override IList<IEnumerable<T>> GetEnumerables (QueryOptions options)
59 return Parent.GetEnumerables (options);
62 internal override IList<IEnumerable<KeyValuePair<long, T>>> GetOrderedEnumerables (QueryOptions options)
64 return Parent.GetOrderedEnumerables (options);
67 internal override IEnumerable<T> GetSequential ()
69 return Parent.GetSequential ();
72 public override void Visit (INodeVisitor visitor)
74 visitor.Visit ((QueryOptionNode)this);
78 internal class ParallelExecutionModeNode<T> : QueryOptionNode<T>
80 ParallelExecutionMode mode;
82 internal ParallelExecutionModeNode (ParallelExecutionMode mode, QueryBaseNode<T> parent)
88 public override OptionsList GetOptions ()
90 return new OptionsList (null, mode, null, -1, null);
95 internal class ParallelMergeOptionsNode<T> : QueryOptionNode<T>
97 ParallelMergeOptions opts;
99 internal ParallelMergeOptionsNode (ParallelMergeOptions opts, QueryBaseNode<T> parent)
105 public override OptionsList GetOptions ()
107 return new OptionsList (opts, null, null, -1, null);
112 internal class CancellationTokenNode<T> : QueryOptionNode<T>
114 CancellationToken token;
116 internal CancellationTokenNode (CancellationToken token, QueryBaseNode<T> parent)
122 public override OptionsList GetOptions ()
124 return new OptionsList (null, null, token, -1, null);
128 internal class DegreeOfParallelismNode<T> : QueryOptionNode<T>
130 int degreeParallelism;
132 internal DegreeOfParallelismNode (int degreeParallelism, QueryBaseNode<T> parent)
135 this.degreeParallelism = degreeParallelism;
138 public override OptionsList GetOptions ()
140 return new OptionsList (null, null, null, degreeParallelism, null);
144 internal class ImplementerTokenNode<T> : QueryOptionNode<T>
146 CancellationTokenSource source;
148 internal ImplementerTokenNode (CancellationTokenSource token, QueryBaseNode<T> parent)
154 public override OptionsList GetOptions ()
156 return new OptionsList (null, null, null, -1, source);