/* quantumreg.pmc
 *  SVN Info
 *     $Id: quantumreg.pmc 17084 2007-02-20 20:03:37Z paultcochrane $
 *  Overview:
 *     These are the vtable functions for the QuantumReg PMC
 *  Data Structure and Algorithms:
 *  History:
 *    2005-11-13: Get started, start with example in
 *                http://www.enyo.de/libquantum/api/node12.html
 *  Notes:
 *     Please remove unneeded entries.
 *  References:
 *    http://www.enyo.de/libquantum/

=head1 NAME

src/dynpmc/quantumreg.pmc - QuantumReg PMC

=head1 STATUS

Development has stalled. Takers are welcome.

=head1 DESCRIPTION

This is an interface to the libquantum library.
The QuantumReg PMC looks from the outside like an fixed size array.

=head2 Functions

=over 4

=cut

 */

#include "parrot/parrot.h"
#include <quantum.h>

pmclass QuantumReg does array dynpmc lib quantum {

/*

=item C<void class_init()>

Class initialization. QuantumReg is a dynamic PMC, meaning that a dynamically
loadable module is created. On Unix-like systems this is a shared library.
When it is available, the shared library has linked in the library 'libquantum'.

=cut

*/

    void class_init() {
        if (pass) {
        }
    }

    void init() {
        PMC_struct_val(SELF) = NULL;
    }

/*

=item C<VOID set_integer_native(INTVAL size)>

Create a new QuantumReg with specified number of registers.

=cut

*/

    void set_integer_native(INTVAL size) {
        quantum_reg * reg_p = (quantum_reg *) malloc(1 * sizeof (quantum_reg));
        PMC_struct_val(SELF) = (void *) reg_p;
        *reg_p = quantum_new_qureg(0,size);

        /* change 1|0> to 0.5*sqrt(2)*|0> + 0.5*sqrt(2)*|1>  for first qubit */
        /* Measuring |0> will give a random value */
        /* TODO: op or method for hadamard */
        quantum_hadamard(0, reg_p);

        return;
    }


/*

=item C<INTVAL get_bool_keyed_int(INTVAL key)>

Makes a measurement on |0> of the qubit at position key.

=cut

*/

    INTVAL get_integer_keyed_int(INTVAL key) {
        quantum_reg * reg_p = (quantum_reg *) PMC_struct_val(SELF);

        return quantum_bmeasure(key, reg_p);
    }

/*

=item C<INTVAL get_integer()>

Returns the number of qbits in the quantum register.

=cut

*/

    INTVAL get_integer() {
        quantum_reg *reg_p = (quantum_reg *)PMC_struct_val(SELF);
        if (! reg_p) {
            return 0;
        }
        else {
            /* TODO: implement this */
            return 0;
        }
    }
}

/*

=back

=head1 SEE ALSO

L<http://www.enyo.de/libquantum/>

=cut

*/

/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
