/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
ASTVector.cs
Abstract:
Z3 Managed API: AST Vectors
Author:
Christoph Wintersteiger (cwinter) 2012-03-21
Notes:
--*/
using System;
using System.Diagnostics.Contracts;
namespace Microsoft.Z3
{
///
/// Vectors of ASTs.
///
internal class ASTVector : Z3Object
{
///
/// The size of the vector
///
public uint Size
{
get { return Native.Z3_ast_vector_size(Context.nCtx, NativeObject); }
}
///
/// Retrieves the i-th object in the vector.
///
/// May throw an IndexOutOfBoundsException when is out of range.
/// Index
/// An AST
public AST this[uint i]
{
get
{
Contract.Ensures(Contract.Result() != null);
return new AST(Context, Native.Z3_ast_vector_get(Context.nCtx, NativeObject, i));
}
set
{
Contract.Requires(value!= null);
Native.Z3_ast_vector_set(Context.nCtx, NativeObject, i, value.NativeObject);
}
}
///
/// Resize the vector to .
///
/// The new size of the vector.
public void Resize(uint newSize)
{
Native.Z3_ast_vector_resize(Context.nCtx, NativeObject, newSize);
}
///
/// Add the AST to the back of the vector. The size
/// is increased by 1.
///
/// An AST
public void Push(AST a)
{
Contract.Requires(a != null);
Native.Z3_ast_vector_push(Context.nCtx, NativeObject, a.NativeObject);
}
///
/// Translates all ASTs in the vector to .
///
/// A context
/// A new ASTVector
public ASTVector Translate(Context ctx)
{
Contract.Requires(ctx != null);
Contract.Ensures(Contract.Result() != null);
return new ASTVector(Context, Native.Z3_ast_vector_translate(Context.nCtx, NativeObject, ctx.nCtx));
}
///
/// Retrieves a string representation of the vector.
///
public override string ToString()
{
return Native.Z3_ast_vector_to_string(Context.nCtx, NativeObject);
}
#region Internal
internal ASTVector(Context ctx, IntPtr obj) : base(ctx, obj) { Contract.Requires(ctx != null); }
internal ASTVector(Context ctx) : base(ctx, Native.Z3_mk_ast_vector(ctx.nCtx)) { Contract.Requires(ctx != null); }
internal class DecRefQueue : Z3.DecRefQueue
{
public override void IncRef(Context ctx, IntPtr obj)
{
Native.Z3_ast_vector_inc_ref(ctx.nCtx, obj);
}
public override void DecRef(Context ctx, IntPtr obj)
{
Native.Z3_ast_vector_dec_ref(ctx.nCtx, obj);
}
};
internal override void IncRef(IntPtr o)
{
Context.ASTVector_DRQ.IncAndClear(Context, o);
base.IncRef(o);
}
internal override void DecRef(IntPtr o)
{
Context.ASTVector_DRQ.Add(o);
base.DecRef(o);
}
#endregion
}
}