z3-z3-4.13.0.src.api.dotnet.ASTMap.cs Maven / Gradle / Ivy
The newest version!
/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
ASTMap.cs
Abstract:
Z3 Managed API: AST Maps
Author:
Christoph Wintersteiger (cwinter) 2012-03-21
Notes:
--*/
using System.Diagnostics;
using System;
namespace Microsoft.Z3
{
///
/// Map from AST to AST
///
internal class ASTMap : Z3Object
{
///
/// Checks whether the map contains the key .
///
/// An AST
/// True if is a key in the map, false otherwise.
public bool Contains(AST k)
{
Debug.Assert(k != null);
return 0 != Native.Z3_ast_map_contains(Context.nCtx, NativeObject, k.NativeObject);
}
///
/// Finds the value associated with the key .
///
///
/// This function signs an error when is not a key in the map.
///
/// An AST
public AST Find(AST k)
{
Debug.Assert(k != null);
return new AST(Context, Native.Z3_ast_map_find(Context.nCtx, NativeObject, k.NativeObject));
}
///
/// Stores or replaces a new key/value pair in the map.
///
/// The key AST
/// The value AST
public void Insert(AST k, AST v)
{
Debug.Assert(k != null);
Debug.Assert(v != null);
Native.Z3_ast_map_insert(Context.nCtx, NativeObject, k.NativeObject, v.NativeObject);
}
///
/// Erases the key from the map.
///
/// An AST
public void Erase(AST k)
{
Debug.Assert(k != null);
Native.Z3_ast_map_erase(Context.nCtx, NativeObject, k.NativeObject);
}
///
/// Removes all keys from the map.
///
public void Reset()
{
Native.Z3_ast_map_reset(Context.nCtx, NativeObject);
}
///
/// The size of the map
///
public uint Size
{
get { return Native.Z3_ast_map_size(Context.nCtx, NativeObject); }
}
///
/// The keys stored in the map.
///
public AST[] Keys
{
get
{
using ASTVector res = new ASTVector(Context, Native.Z3_ast_map_keys(Context.nCtx, NativeObject));
return res.ToArray();
}
}
///
/// Retrieves a string representation of the map.
///
public override string ToString()
{
return Native.Z3_ast_map_to_string(Context.nCtx, NativeObject);
}
#region Internal
internal ASTMap(Context ctx, IntPtr obj)
: base(ctx, obj)
{
Debug.Assert(ctx != null);
}
internal ASTMap(Context ctx)
: base(ctx, Native.Z3_mk_ast_map(ctx.nCtx))
{
Debug.Assert(ctx != null);
}
internal override void IncRef(IntPtr o)
{
Native.Z3_ast_map_inc_ref(Context.nCtx, o);
}
internal override void DecRef(IntPtr o)
{
lock (Context)
{
if (Context.nCtx != IntPtr.Zero)
Native.Z3_ast_map_dec_ref(Context.nCtx, o);
}
}
#endregion
}
}