-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathSegmentTransform.cs
68 lines (58 loc) · 1.96 KB
/
SegmentTransform.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexey Kochetov
// Created: 2008.05.20
using System;
using System.Diagnostics;
using Xtensive.Core;
using Xtensive.Reflection;
namespace Xtensive.Tuples.Transform
{
/// <summary>
/// Extracts specified <see cref="Segment"/> from the <see cref="Tuple"/>.
/// </summary>
public sealed class SegmentTransform : MapTransform
{
private Segment<int> segment;
/// <summary>
/// Gets the segment this transform extracts.
/// </summary>
public Segment<int> Segment
{
[DebuggerStepThrough]
get { return segment; }
}
/// <see cref="MapTransform.Apply(TupleTransformType,Tuple)" copy="true" />
public new Tuple Apply(TupleTransformType transformType, Tuple source)
{
return base.Apply(transformType, source);
}
/// <inheritdoc/>
public override string ToString()
{
string description = $"{segment}, {(IsReadOnly ? Strings.ReadOnlyShort : Strings.ReadWriteShort)}";
return string.Format(Strings.TupleTransformFormat, GetType().Name, description);
}
// Constructors
/// <summary>
/// Initializes a new instance of this type.
/// </summary>
/// <param name="isReadOnly"><see cref="MapTransform.IsReadOnly"/> property value.</param>
/// <param name="sourceDescriptor">Source tuple descriptor.</param>
/// <param name="segment">The segment to extract.</param>
public SegmentTransform(bool isReadOnly, TupleDescriptor sourceDescriptor, in Segment<int> segment)
: base(isReadOnly)
{
this.segment = segment;
Type[] fields = new Type[segment.Length];
int[] map = new int[segment.Length];
for (int i = 0, j = segment.Offset; i < segment.Length; i++, j++) {
fields[i] = sourceDescriptor[j];
map[i] = j;
}
Descriptor = TupleDescriptor.Create(fields);
SetSingleSourceMap(map);
}
}
}