2010-04-15 Jérémie Laval <jeremie.laval@gmail.com>
[mono.git] / mcs / class / System.Core / System.Linq / Internal / QueryNodes / QueryOrderGuardNode.cs
1 #if NET_4_0
2 // QueryOrderGuardNode.cs
3 //
4 // Author:
5 //       Jérémie "Garuma" Laval <jeremie.laval@gmail.com>
6 //
7 // Copyright (c) 2010 Jérémie "Garuma" Laval
8 //
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:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
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
25 // THE SOFTWARE.
26
27 using System;
28 using System.Collections.Generic;
29
30 namespace System.Linq
31 {
32         internal abstract class QueryOrderGuardNode<T> : QueryStreamNode<T, T>
33         {
34                 bool ensureOrder;
35
36                 internal QueryOrderGuardNode (QueryBaseNode<T> parent, bool ensureOrder)
37                         : base (parent, ensureOrder)
38                 {
39                         this.ensureOrder = ensureOrder;
40                 }
41
42                 public bool EnsureOrder {
43                         get {
44                                 return ensureOrder;
45                         }
46                 }
47
48                 internal override IEnumerable<T> GetSequential ()
49                 {
50                         return Parent.GetSequential ();
51                 }
52
53                 public override void Visit (INodeVisitor visitor)
54                 {
55                         visitor.Visit<T> (this);
56                 }
57         }
58
59         internal class QueryAsUnorderedNode<T> : QueryOrderGuardNode<T>
60         {
61                 internal QueryAsUnorderedNode (QueryBaseNode<T> parent)
62                         : base (parent, false)
63                 {
64
65                 }
66
67                 internal override IList<IEnumerable<T>> GetEnumerables (QueryOptions options)
68                 {
69                         return Parent.GetEnumerables (options);
70                 }
71
72                 internal override IList<IEnumerable<KeyValuePair<long, T>>> GetOrderedEnumerables (QueryOptions options)
73                 {
74                         return Parent.GetOrderedEnumerables (options);
75                 }
76
77         }
78
79         internal class QueryAsOrderedNode<T> : QueryOrderGuardNode<T>
80         {
81                 internal QueryAsOrderedNode (QueryBaseNode<T> parent)
82                         : base (parent, true)
83                 {
84
85                 }
86
87                 internal override IList<IEnumerable<T>> GetEnumerables (QueryOptions options)
88                 {
89                         return Parent.GetEnumerables (options);
90                 }
91
92                 internal override IList<IEnumerable<KeyValuePair<long, T>>> GetOrderedEnumerables (QueryOptions options)
93                 {
94                         return Parent.GetOrderedEnumerables (options);
95                 }
96
97         }
98 }
99 #endif