<commit_before>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, development version     *
*                (c) 2006-2017 INRIA, USTL, UJF, CNRS, MGH                    *
*                                                                             *
* This program is free software; you can redistribute it and/or modify it     *
* under the terms of the GNU Lesser General Public License as published by    *
* the Free Software Foundation; either version 2.1 of the License, or (at     *
* your option) any later version.                                             *
*                                                                             *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details.                                                           *
*                                                                             *
* You should have received a copy of the GNU Lesser General Public License    *
* along with this program. If not, see <http://www.gnu.org/licenses/>.        *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#include "Binding_Link.h"

#include <sofa/core/objectmodel/BaseLink.h>
#include <sofa/core/objectmodel/Link.h>


using namespace sofa::core::objectmodel;
using namespace sofa::defaulttype;


// TODO:
// se servir du LinkTypeInfo pour utiliser directement les bons type :-)
// Il y a un seul type "Link" exposé en python, le transtypage est géré automatiquement


SP_CLASS_ATTR_GET(Link,name)(PyObject *self, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    return PyString_FromString(link->getName().c_str());
}
SP_CLASS_ATTR_SET(Link,name)(PyObject *self, PyObject * args, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    char *str = PyString_AsString(args); // for setters, only one object and not a tuple....
    link->setName(str);
    return 0;
}

PyObject *GetLinkValuePython(BaseLink* link)
{
    // only by string for now
    return PyString_FromString(link->getValueString().c_str());
}

int SetLinkValuePython(BaseLink* link, PyObject* args)
{
    // only by string for now

    // de quel type est args ?
    if( PyString_Check(args) )
    {
        // it's a string
        char *str = PyString_AsString(args); // for setters, only one object and not a tuple....
        link->read(str);
        return 0;
    }

    return -1;
}



SP_CLASS_ATTR_GET(Link,value)(PyObject *self, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    return GetLinkValuePython(link);
}

SP_CLASS_ATTR_SET(Link,value)(PyObject *self, PyObject * args, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    if (SetLinkValuePython(link,args)) {
        return 0;
    }

    SP_MESSAGE_ERROR( "argument type not supported" )
    PyErr_BadArgument();
    return -1;
}

//// access ONE element of the vector
//extern "C" PyObject * Link_getValue(PyObject *self, PyObject * args)
//{
//    BaseLink* link=((PyPtr<BaseLink>*)self)->object;<commit_msg>[SofaPython] fixing Link value attribute setter<commit_after>/******************************************************************************
*       SOFA, Simulation Open-Framework Architecture, development version     *
*                (c) 2006-2017 INRIA, USTL, UJF, CNRS, MGH                    *
*                                                                             *
* This program is free software; you can redistribute it and/or modify it     *
* under the terms of the GNU Lesser General Public License as published by    *
* the Free Software Foundation; either version 2.1 of the License, or (at     *
* your option) any later version.                                             *
*                                                                             *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details.                                                           *
*                                                                             *
* You should have received a copy of the GNU Lesser General Public License    *
* along with this program. If not, see <http://www.gnu.org/licenses/>.        *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
*                                                                             *
* Contact information: <EMAIL>                             *
******************************************************************************/
#include "Binding_Link.h"

#include <sofa/core/objectmodel/BaseLink.h>
#include <sofa/core/objectmodel/Link.h>


using namespace sofa::core::objectmodel;
using namespace sofa::defaulttype;


// TODO:
// se servir du LinkTypeInfo pour utiliser directement les bons type :-)
// Il y a un seul type "Link" exposé en python, le transtypage est géré automatiquement


SP_CLASS_ATTR_GET(Link,name)(PyObject *self, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    return PyString_FromString(link->getName().c_str());
}
SP_CLASS_ATTR_SET(Link,name)(PyObject *self, PyObject * args, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    char *str = PyString_AsString(args); // for setters, only one object and not a tuple....
    link->setName(str);
    return 0;
}

PyObject *GetLinkValuePython(BaseLink* link)
{
    // only by string for now
    return PyString_FromString(link->getValueString().c_str());
}

int SetLinkValuePython(BaseLink* link, PyObject* args)
{
    // only by string for now

    // de quel type est args ?
    if( PyString_Check(args) )
    {
        // it's a string
        char *str = PyString_AsString(args); // for setters, only one object and not a tuple....
        link->read(str);
        return 0;
    }

    return -1;
}



SP_CLASS_ATTR_GET(Link,value)(PyObject *self, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    return GetLinkValuePython(link);
}

SP_CLASS_ATTR_SET(Link,value)(PyObject *self, PyObject * args, void*)
{
    BaseLink* link=((PyPtr<BaseLink>*)self)->object; // TODO: check dynamic cast
    return SetLinkValuePython(link,args);
}

//// access ONE element of the vector
//extern "C" PyObject * Link_getValue(PyObject *self, PyObject * args)
//{
//    BaseLink* link=((PyPtr<BaseLink>*)self)->object;
{'fraction_non_alphanumeric': 0.16277472527472528, 'fraction_numerical': 0.0038461538461538464, 'mean_word_length': 2.284167794316644, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6533419', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1816, 'n_words': 592}