Rev | Line | |
---|
[17263] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Threading.Tasks;
|
---|
| 6 | using Newtonsoft.Json.Linq;
|
---|
| 7 | using HeuristicLab.Data;
|
---|
| 8 | using HeuristicLab.Core;
|
---|
| 9 |
|
---|
[17266] | 10 | namespace HeuristicLab.Manufacture {
|
---|
[17281] | 11 | public class ValueTypeMatrixConverter<MatrixType, T> : BaseConverter
|
---|
[17263] | 12 | where MatrixType : ValueTypeMatrix<T>
|
---|
| 13 | where T : struct
|
---|
| 14 | {
|
---|
[17283] | 15 | public override void InjectData(IItem item, JsonItem data) =>
|
---|
[17266] | 16 | CopyMatrixData(item.Cast<MatrixType>(), CastValue<T[,]>(data.Default));
|
---|
[17263] | 17 |
|
---|
[17283] | 18 | public override JsonItem ExtractData(IItem value) =>
|
---|
| 19 | new JsonItem() {
|
---|
[17266] | 20 | Default = value.Cast<MatrixType>().CloneAsMatrix()
|
---|
| 21 | };
|
---|
| 22 |
|
---|
| 23 | #region Helper
|
---|
| 24 | private void CopyMatrixData(MatrixType matrix, T[,] data) {
|
---|
| 25 | for (int x = 0; x < data.GetLength(0); ++x) {
|
---|
| 26 | for (int y = 0; y < data.GetLength(1); ++y) {
|
---|
| 27 | matrix[x, y] = data[x, y];
|
---|
[17263] | 28 | }
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
[17266] | 31 | #endregion
|
---|
[17263] | 32 | }
|
---|
| 33 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.