/*++
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;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
///
/// Map from AST to AST
///
[ContractVerification(true)]
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)
{
Contract.Requires(k != null);
return Native.Z3_ast_map_contains(Context.nCtx, NativeObject, k.NativeObject) != 0;
}
///
/// 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)
{
Contract.Requires(k != null);
Contract.Ensures(Contract.Result() != 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)
{
Contract.Requires(k != null);
Contract.Requires(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)
{
Contract.Requires(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 ASTVector Keys
{
get
{
return new ASTVector(Context, Native.Z3_ast_map_keys(Context.nCtx, NativeObject));
}
}
///
/// 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)
{
Contract.Requires(ctx != null);
}
internal ASTMap(Context ctx)
: base(ctx, Native.Z3_mk_ast_map(ctx.nCtx))
{
Contract.Requires(ctx != null);
}
internal class DecRefQueue : Z3.DecRefQueue
{
public override void IncRef(Context ctx, IntPtr obj)
{
Native.Z3_ast_map_inc_ref(ctx.nCtx, obj);
}
public override void DecRef(Context ctx, IntPtr obj)
{
Native.Z3_ast_map_dec_ref(ctx.nCtx, obj);
}
};
internal override void IncRef(IntPtr o)
{
Context.ASTMap_DRQ.IncAndClear(Context, o);
base.IncRef(o);
}
internal override void DecRef(IntPtr o)
{
Context.ASTMap_DRQ.Add(o);
base.DecRef(o);
}
#endregion
}
}