-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- moved IPointCloudNode to Aardvark.Data.Points.Base - moved PersistentRef to Aardvark.Data.Points.Base (dependency) - aligned Aardvark.Geometry.PointTree license to Aardvark.Data.Points.Base license (AGPL -> Apache2.0)
- Loading branch information
1 parent
0721504
commit bb41659
Showing
23 changed files
with
422 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
Aardvark Platform | ||
Copyright (C) 2006-2024 Aardvark Platform Team | ||
https://aardvark.graphics | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
using System; | ||
|
||
namespace Aardvark.Geometry.Points | ||
{ | ||
|
||
/// <summary> | ||
/// </summary> | ||
public class PersistentRef<T> where T : notnull | ||
{ | ||
private readonly Func<string, T> f_get; | ||
private readonly Func<string, (bool, T?)> f_tryGet; | ||
|
||
/// <summary> | ||
/// </summary> | ||
public PersistentRef(Guid id, Func<string, T> get, Func<string, (bool, T?)> tryGet) | ||
: this(id.ToString(), get, tryGet) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// </summary> | ||
public PersistentRef(Func<string, T> get, Func<string, (bool, T?)> tryGet) | ||
: this(default(string), get, tryGet) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// </summary> | ||
public PersistentRef(string? id, Func<string, T> get, Func<string, (bool, T?)> tryGet) | ||
{ | ||
Id = id; | ||
f_get = get ?? throw new ArgumentNullException(nameof(get)); | ||
f_tryGet = tryGet ?? throw new ArgumentNullException(nameof(tryGet)); | ||
} | ||
|
||
/// <summary> | ||
/// </summary> | ||
public PersistentRef<A> Cast<A>() where A : notnull | ||
{ | ||
var get = f_get; | ||
var tryGet = f_tryGet; | ||
return new PersistentRef<A>( | ||
Id, | ||
s => | ||
{ | ||
return (A)(object)get(s); | ||
}, | ||
s => | ||
{ | ||
var (w, t) = tryGet(s); | ||
if (w) | ||
{ | ||
if (t == null) throw new InvalidOperationException("Invariant 9b67fe44-679b-443c-8621-a32884eea50e."); | ||
return (w, (A)(object)t); | ||
} | ||
else | ||
{ | ||
return (false, default(A)); | ||
} | ||
} | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// </summary> | ||
public static PersistentRef<T> FromValue(T value) => new(null, s => value, s => (true, value)); | ||
|
||
/// <summary> | ||
/// </summary> | ||
public string? Id { get; } | ||
|
||
/// <summary> | ||
/// </summary> | ||
public bool TryGetValue(out T? value) | ||
{ | ||
if (Id != null) | ||
{ | ||
(var isSome, value) = f_tryGet(Id); | ||
return isSome; | ||
} | ||
else | ||
{ | ||
value = default; | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// </summary> | ||
public (bool hasValue, T? value) TryGetValue() | ||
{ | ||
if (Id != null) | ||
{ | ||
return f_tryGet(Id); | ||
} | ||
else | ||
{ | ||
return (false, default); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// </summary> | ||
public T Value | ||
{ | ||
get | ||
{ | ||
if (Id == null) throw new InvalidOperationException("Invariant c96befc0-9dd4-4b38-b301-9d9c59d6685a."); | ||
var result = f_get(Id); | ||
return result == null ? throw new InvalidOperationException("Invariant e73282a1-45c0-4cb3-bccf-e6d416163abc.") : result; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.