view PyFeatureSet.cpp @ 46:af9c4cee95a8

VC++ fixes. Much of this is changing "and" to "&&". I had never realised until today that "and" is in fact a keyword in C++, albeit not one that has been there since the start, so this should compile (I eventually looked this up having been puzzled by how this code could ever build with any other compiler). However, despite its keywordness, "and" still doesn't seem to be acceptable to VC++. Possibly there's an option to change this, or one could use a macro -- but why not just stick with the token that compilers are known to like?
author cannam
date Mon, 05 Oct 2009 16:14:25 +0000
parents 27bab3a16c9a
children
line wrap: on
line source
/*

 * Vampy : This plugin is a wrapper around the Vamp plugin API.
 * It allows for writing Vamp plugins in Python.

 * Centre for Digital Music, Queen Mary University of London.
 * Copyright (C) 2008-2009 Gyorgy Fazekas, QMUL. (See Vamp sources 
 * for licence information.)

*/

#include <Python.h>
#include "PyFeatureSet.h"
#include "vamp-sdk/Plugin.h"

using namespace std;

static int
FeatureSet_init(FeatureSetObject *self, PyObject *args, PyObject *kwds)
{
    if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0)
        return -1;
    return 0;
}

static int
FeatureSetObject_ass_sub(FeatureSetObject *mp, PyObject *v, PyObject *w)
{
	if (!PyInt_CheckExact(v)) {
		PyErr_SetString(PyExc_ValueError,
			"Output index must be positive integer.");
		return 0;
	}
	if (w == NULL)
		return PyDict_DelItem((PyObject *)mp, v);
	else
		return PyDict_SetItem((PyObject *)mp, v, w);
}

#define FeatureSet_alloc PyType_GenericAlloc
#define FeatureSet_free PyObject_Del
//#define FeatureSet_as_mapping PyDict_Type.tp_as_mapping

static PyMappingMethods FeatureSet_as_mapping = *(PyDict_Type.tp_as_mapping);

PyTypeObject FeatureSet_Type = PyDict_Type;

void
initFeatureSetType(void)
{
	/*This type is derived from PyDict. We just override some slots here.*/
	/*The typical use case is index based assignment as opposed to object memeber access.*/
	FeatureSet_Type.ob_type = &PyType_Type;
	FeatureSet_Type.tp_base = &PyDict_Type;
	FeatureSet_Type.tp_bases = PyTuple_Pack(1, FeatureSet_Type.tp_base);
	FeatureSet_Type.tp_name = "vampy.FeatureSet";
	// FeatureSet_Type.tp_new = FeatureSet_new;
	FeatureSet_Type.tp_init = (initproc)FeatureSet_init;
	FeatureSet_Type.tp_basicsize = sizeof(FeatureSetObject);
	FeatureSet_as_mapping.mp_ass_subscript = (objobjargproc)FeatureSetObject_ass_sub;
	FeatureSet_Type.tp_as_mapping = &FeatureSet_as_mapping;
}