Base: apply clang format

This commit is contained in:
wmayer
2023-11-10 18:27:44 +01:00
committed by WandererFan
parent bb333d9a74
commit 985def3416
154 changed files with 11874 additions and 9872 deletions

View File

@@ -25,17 +25,17 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# ifdef FC_OS_WIN32
# include <xercesc/sax/SAXParseException.hpp>
# endif
# include <list>
# include <sstream>
# include <string>
# include <utility>
#ifdef FC_OS_WIN32
#include <xercesc/sax/SAXParseException.hpp>
#endif
#include <list>
#include <sstream>
#include <string>
#include <utility>
#endif
#ifdef FC_OS_LINUX
# include <unistd.h>
#include <unistd.h>
#endif
#include "Parameter.h"
@@ -43,26 +43,28 @@
#include "Interpreter.h"
namespace Base {
namespace Base
{
class ParameterGrpObserver : public ParameterGrp::ObserverType
class ParameterGrpObserver: public ParameterGrp::ObserverType
{
public:
explicit ParameterGrpObserver(const Py::Object& obj)
{
inst = obj;
}
ParameterGrpObserver(const Py::Object& obj, const Py::Object &callable, ParameterGrp *target)
: callable(callable), _target(target), inst(obj)
{
}
ParameterGrpObserver(const Py::Object& obj, const Py::Object& callable, ParameterGrp* target)
: callable(callable)
, _target(target)
, inst(obj)
{}
~ParameterGrpObserver() override
{
Base::PyGILStateLocker lock;
inst = Py::None();
callable = Py::None();
}
void OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::MessageType Reason) override
void OnChange(ParameterGrp::SubjectType& rCaller, ParameterGrp::MessageType Reason) override
{
Base::PyGILStateLocker lock;
try {
@@ -72,12 +74,13 @@ public:
Py::Tuple args(2);
args.setItem(0, Py::asObject(GetPyObject(hGrp)));
// A Reason of null indicates to clear the parameter group
if (Reason && Reason[0] != '\0')
if (Reason && Reason[0] != '\0') {
args.setItem(1, Py::String(Reason));
}
method.apply(args);
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
@@ -89,7 +92,7 @@ public:
public:
Py::Object callable;
boost::signals2::scoped_connection conn;
ParameterGrp *_target = nullptr; // no reference counted, do not access
ParameterGrp* _target = nullptr; // no reference counted, do not access
private:
Py::Object inst;
@@ -97,12 +100,12 @@ private:
using ParameterGrpObserverList = std::list<ParameterGrpObserver*>;
class ParameterGrpPy : public Py::PythonExtension<ParameterGrpPy>
class ParameterGrpPy: public Py::PythonExtension<ParameterGrpPy>
{
public:
static void init_type(); // announce properties and methods
static void init_type(); // announce properties and methods
explicit ParameterGrpPy(const Base::Reference<ParameterGrp> &rcParamGrp);
explicit ParameterGrpPy(const Base::Reference<ParameterGrp>& rcParamGrp);
~ParameterGrpPy() override;
Py::Object repr() override;
@@ -173,20 +176,22 @@ void ParameterGrpPy::init_type()
behaviors().supportSetattr();
behaviors().readyType();
add_varargs_method("GetGroup",&ParameterGrpPy::getGroup,"GetGroup(str)");
add_varargs_method("GetGroupName",&ParameterGrpPy::getGroupName,"GetGroupName()");
add_varargs_method("GetGroups",&ParameterGrpPy::getGroups,"GetGroups()");
add_varargs_method("RemGroup",&ParameterGrpPy::remGroup,"RemGroup(str)");
add_varargs_method("HasGroup",&ParameterGrpPy::hasGroup,"HasGroup(str)");
add_varargs_method("GetGroup", &ParameterGrpPy::getGroup, "GetGroup(str)");
add_varargs_method("GetGroupName", &ParameterGrpPy::getGroupName, "GetGroupName()");
add_varargs_method("GetGroups", &ParameterGrpPy::getGroups, "GetGroups()");
add_varargs_method("RemGroup", &ParameterGrpPy::remGroup, "RemGroup(str)");
add_varargs_method("HasGroup", &ParameterGrpPy::hasGroup, "HasGroup(str)");
add_varargs_method("Manager",&ParameterGrpPy::getManager,"Manager()");
add_varargs_method("Parent",&ParameterGrpPy::getParent,"Parent()");
add_varargs_method("Manager", &ParameterGrpPy::getManager, "Manager()");
add_varargs_method("Parent", &ParameterGrpPy::getParent, "Parent()");
add_varargs_method("IsEmpty",&ParameterGrpPy::isEmpty,"IsEmpty()");
add_varargs_method("Clear",&ParameterGrpPy::clear,"Clear()");
add_varargs_method("IsEmpty", &ParameterGrpPy::isEmpty, "IsEmpty()");
add_varargs_method("Clear", &ParameterGrpPy::clear, "Clear()");
add_varargs_method("Attach",&ParameterGrpPy::attach,"Attach()");
add_varargs_method("AttachManager",&ParameterGrpPy::attachManager,
add_varargs_method("Attach", &ParameterGrpPy::attach, "Attach()");
add_varargs_method(
"AttachManager",
&ParameterGrpPy::attachManager,
"AttachManager(observer) -- attach parameter manager for notification\n\n"
"This method attaches a user defined observer to the manager (i.e. the root)\n"
"of the current parameter group to receive notification of all its parameters\n"
@@ -204,52 +209,52 @@ void ParameterGrpPy::init_type()
"* Group creation: both 'name' and 'value' contain the name of the new group\n"
"* Group removal: both 'name' and 'value' are empty\n"
"* Group rename: 'name' is the new name, and 'value' is the old name");
add_varargs_method("Detach",&ParameterGrpPy::detach,"Detach()");
add_varargs_method("Notify",&ParameterGrpPy::notify,"Notify()");
add_varargs_method("NotifyAll",&ParameterGrpPy::notifyAll,"NotifyAll()");
add_varargs_method("Detach", &ParameterGrpPy::detach, "Detach()");
add_varargs_method("Notify", &ParameterGrpPy::notify, "Notify()");
add_varargs_method("NotifyAll", &ParameterGrpPy::notifyAll, "NotifyAll()");
add_varargs_method("SetBool",&ParameterGrpPy::setBool,"SetBool()");
add_varargs_method("GetBool",&ParameterGrpPy::getBool,"GetBool()");
add_varargs_method("GetBools",&ParameterGrpPy::getBools,"GetBools()");
add_varargs_method("RemBool",&ParameterGrpPy::remBool,"RemBool()");
add_varargs_method("SetBool", &ParameterGrpPy::setBool, "SetBool()");
add_varargs_method("GetBool", &ParameterGrpPy::getBool, "GetBool()");
add_varargs_method("GetBools", &ParameterGrpPy::getBools, "GetBools()");
add_varargs_method("RemBool", &ParameterGrpPy::remBool, "RemBool()");
add_varargs_method("SetInt",&ParameterGrpPy::setInt,"SetInt()");
add_varargs_method("GetInt",&ParameterGrpPy::getInt,"GetInt()");
add_varargs_method("GetInts",&ParameterGrpPy::getInts,"GetInts()");
add_varargs_method("RemInt",&ParameterGrpPy::remInt,"RemInt()");
add_varargs_method("SetInt", &ParameterGrpPy::setInt, "SetInt()");
add_varargs_method("GetInt", &ParameterGrpPy::getInt, "GetInt()");
add_varargs_method("GetInts", &ParameterGrpPy::getInts, "GetInts()");
add_varargs_method("RemInt", &ParameterGrpPy::remInt, "RemInt()");
add_varargs_method("SetUnsigned",&ParameterGrpPy::setUnsigned,"SetUnsigned()");
add_varargs_method("GetUnsigned",&ParameterGrpPy::getUnsigned,"GetUnsigned()");
add_varargs_method("GetUnsigneds",&ParameterGrpPy::getUnsigneds,"GetUnsigneds()");
add_varargs_method("RemUnsigned",&ParameterGrpPy::remUnsigned,"RemUnsigned()");
add_varargs_method("SetUnsigned", &ParameterGrpPy::setUnsigned, "SetUnsigned()");
add_varargs_method("GetUnsigned", &ParameterGrpPy::getUnsigned, "GetUnsigned()");
add_varargs_method("GetUnsigneds", &ParameterGrpPy::getUnsigneds, "GetUnsigneds()");
add_varargs_method("RemUnsigned", &ParameterGrpPy::remUnsigned, "RemUnsigned()");
add_varargs_method("SetFloat",&ParameterGrpPy::setFloat,"SetFloat()");
add_varargs_method("GetFloat",&ParameterGrpPy::getFloat,"GetFloat()");
add_varargs_method("GetFloats",&ParameterGrpPy::getFloats,"GetFloats()");
add_varargs_method("RemFloat",&ParameterGrpPy::remFloat,"RemFloat()");
add_varargs_method("SetFloat", &ParameterGrpPy::setFloat, "SetFloat()");
add_varargs_method("GetFloat", &ParameterGrpPy::getFloat, "GetFloat()");
add_varargs_method("GetFloats", &ParameterGrpPy::getFloats, "GetFloats()");
add_varargs_method("RemFloat", &ParameterGrpPy::remFloat, "RemFloat()");
add_varargs_method("SetString",&ParameterGrpPy::setString,"SetString()");
add_varargs_method("GetString",&ParameterGrpPy::getString,"GetString()");
add_varargs_method("GetStrings",&ParameterGrpPy::getStrings,"GetStrings()");
add_varargs_method("RemString",&ParameterGrpPy::remString,"RemString()");
add_varargs_method("SetString", &ParameterGrpPy::setString, "SetString()");
add_varargs_method("GetString", &ParameterGrpPy::getString, "GetString()");
add_varargs_method("GetStrings", &ParameterGrpPy::getStrings, "GetStrings()");
add_varargs_method("RemString", &ParameterGrpPy::remString, "RemString()");
add_varargs_method("Import",&ParameterGrpPy::importFrom,"Import()");
add_varargs_method("Insert",&ParameterGrpPy::insert,"Insert()");
add_varargs_method("Export",&ParameterGrpPy::exportTo,"Export()");
add_varargs_method("Import", &ParameterGrpPy::importFrom, "Import()");
add_varargs_method("Insert", &ParameterGrpPy::insert, "Insert()");
add_varargs_method("Export", &ParameterGrpPy::exportTo, "Export()");
add_varargs_method("GetContents",&ParameterGrpPy::getContents,"GetContents()");
add_varargs_method("GetContents", &ParameterGrpPy::getContents, "GetContents()");
}
ParameterGrpPy::ParameterGrpPy(const Base::Reference<ParameterGrp> &rcParamGrp)
: _cParamGrp(rcParamGrp)
{
}
ParameterGrpPy::ParameterGrpPy(const Base::Reference<ParameterGrp>& rcParamGrp)
: _cParamGrp(rcParamGrp)
{}
ParameterGrpPy::~ParameterGrpPy()
{
for (ParameterGrpObserver* obs : _observers) {
if (!obs->_target)
if (!obs->_target) {
_cParamGrp->Detach(obs);
}
delete obs;
}
}
@@ -263,9 +268,10 @@ Py::Object ParameterGrpPy::repr()
Py::Object ParameterGrpPy::importFrom(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->importFrom(pstr);
return Py::None();
@@ -273,9 +279,10 @@ Py::Object ParameterGrpPy::importFrom(const Py::Tuple& args)
Py::Object ParameterGrpPy::insert(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->insert(pstr);
return Py::None();
@@ -283,9 +290,10 @@ Py::Object ParameterGrpPy::insert(const Py::Tuple& args)
Py::Object ParameterGrpPy::exportTo(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->exportTo(pstr);
return Py::None();
@@ -293,16 +301,17 @@ Py::Object ParameterGrpPy::exportTo(const Py::Tuple& args)
Py::Object ParameterGrpPy::getGroup(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
try {
// get the Handle of the wanted group
Base::Reference<ParameterGrp> handle = _cParamGrp->GetGroup(pstr);
if (handle.isValid()) {
// create a python wrapper class
ParameterGrpPy *pcParamGrp = new ParameterGrpPy(handle);
ParameterGrpPy* pcParamGrp = new ParameterGrpPy(handle);
// increment the ref count
return Py::asObject(pcParamGrp);
}
@@ -318,14 +327,15 @@ Py::Object ParameterGrpPy::getGroup(const Py::Tuple& args)
Py::Object ParameterGrpPy::getManager(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
// get the Handle of the wanted group
Base::Reference<ParameterGrp> handle = _cParamGrp->Manager();
if (handle.isValid()) {
// create a python wrapper class
ParameterGrpPy *pcParamGrp = new ParameterGrpPy(handle);
ParameterGrpPy* pcParamGrp = new ParameterGrpPy(handle);
// increment the ref count
return Py::asObject(pcParamGrp);
}
@@ -335,14 +345,15 @@ Py::Object ParameterGrpPy::getManager(const Py::Tuple& args)
Py::Object ParameterGrpPy::getParent(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
// get the Handle of the wanted group
Base::Reference<ParameterGrp> handle = _cParamGrp->Parent();
if (handle.isValid()) {
// create a python wrapper class
ParameterGrpPy *pcParamGrp = new ParameterGrpPy(handle);
ParameterGrpPy* pcParamGrp = new ParameterGrpPy(handle);
// increment the ref count
return Py::asObject(pcParamGrp);
}
@@ -352,8 +363,9 @@ Py::Object ParameterGrpPy::getParent(const Py::Tuple& args)
Py::Object ParameterGrpPy::getGroupName(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
// get the Handle of the wanted group
std::string name = _cParamGrp->GetGroupName();
@@ -362,11 +374,12 @@ Py::Object ParameterGrpPy::getGroupName(const Py::Tuple& args)
Py::Object ParameterGrpPy::getGroups(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
// get the Handle of the wanted group
std::vector<Base::Reference<ParameterGrp> > handle = _cParamGrp->GetGroups();
std::vector<Base::Reference<ParameterGrp>> handle = _cParamGrp->GetGroups();
Py::List list;
for (const auto& it : handle) {
list.append(Py::String(it->GetGroupName()));
@@ -377,32 +390,35 @@ Py::Object ParameterGrpPy::getGroups(const Py::Tuple& args)
Py::Object ParameterGrpPy::setBool(const Py::Tuple& args)
{
char *pstr = nullptr;
int Bool = 0;
if (!PyArg_ParseTuple(args.ptr(), "si", &pstr,&Bool))
char* pstr = nullptr;
int Bool = 0;
if (!PyArg_ParseTuple(args.ptr(), "si", &pstr, &Bool)) {
throw Py::Exception();
}
_cParamGrp->SetBool(pstr,Bool!=0);
_cParamGrp->SetBool(pstr, Bool != 0);
return Py::None();
}
Py::Object ParameterGrpPy::getBool(const Py::Tuple& args)
{
char *pstr = nullptr;
int Bool=0;
if (!PyArg_ParseTuple(args.ptr(), "s|i", &pstr,&Bool))
char* pstr = nullptr;
int Bool = 0;
if (!PyArg_ParseTuple(args.ptr(), "s|i", &pstr, &Bool)) {
throw Py::Exception();
}
return Py::Boolean(_cParamGrp->GetBool(pstr,Bool!=0));
return Py::Boolean(_cParamGrp->GetBool(pstr, Bool != 0));
}
Py::Object ParameterGrpPy::getBools(const Py::Tuple& args)
{
char *filter=nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter))
char* filter = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter)) {
throw Py::Exception();
}
std::vector<std::pair<std::string,bool> > map = _cParamGrp->GetBoolMap(filter);
std::vector<std::pair<std::string, bool>> map = _cParamGrp->GetBoolMap(filter);
Py::List list;
for (const auto& it : map) {
list.append(Py::String(it.first));
@@ -413,31 +429,34 @@ Py::Object ParameterGrpPy::getBools(const Py::Tuple& args)
Py::Object ParameterGrpPy::setInt(const Py::Tuple& args)
{
char *pstr = nullptr;
int Int = 0;
if (!PyArg_ParseTuple(args.ptr(), "si", &pstr,&Int))
char* pstr = nullptr;
int Int = 0;
if (!PyArg_ParseTuple(args.ptr(), "si", &pstr, &Int)) {
throw Py::Exception();
}
_cParamGrp->SetInt(pstr,Int);
_cParamGrp->SetInt(pstr, Int);
return Py::None();
}
Py::Object ParameterGrpPy::getInt(const Py::Tuple& args)
{
char *pstr = nullptr;
int Int=0;
if (!PyArg_ParseTuple(args.ptr(), "s|i", &pstr,&Int))
char* pstr = nullptr;
int Int = 0;
if (!PyArg_ParseTuple(args.ptr(), "s|i", &pstr, &Int)) {
throw Py::Exception();
return Py::Long(_cParamGrp->GetInt(pstr,Int));
}
return Py::Long(_cParamGrp->GetInt(pstr, Int));
}
Py::Object ParameterGrpPy::getInts(const Py::Tuple& args)
{
char *filter=nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter))
char* filter = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter)) {
throw Py::Exception();
}
std::vector<std::pair<std::string,long> > map = _cParamGrp->GetIntMap(filter);
std::vector<std::pair<std::string, long>> map = _cParamGrp->GetIntMap(filter);
Py::List list;
for (const auto& it : map) {
list.append(Py::String(it.first));
@@ -448,31 +467,34 @@ Py::Object ParameterGrpPy::getInts(const Py::Tuple& args)
Py::Object ParameterGrpPy::setUnsigned(const Py::Tuple& args)
{
char *pstr = nullptr;
unsigned int UInt = 0;
if (!PyArg_ParseTuple(args.ptr(), "sI", &pstr,&UInt))
char* pstr = nullptr;
unsigned int UInt = 0;
if (!PyArg_ParseTuple(args.ptr(), "sI", &pstr, &UInt)) {
throw Py::Exception();
}
_cParamGrp->SetUnsigned(pstr,UInt);
_cParamGrp->SetUnsigned(pstr, UInt);
return Py::None();
}
Py::Object ParameterGrpPy::getUnsigned(const Py::Tuple& args)
{
char *pstr = nullptr;
unsigned int UInt=0;
if (!PyArg_ParseTuple(args.ptr(), "s|I", &pstr,&UInt))
char* pstr = nullptr;
unsigned int UInt = 0;
if (!PyArg_ParseTuple(args.ptr(), "s|I", &pstr, &UInt)) {
throw Py::Exception();
return Py::Long(_cParamGrp->GetUnsigned(pstr,UInt));
}
return Py::Long(_cParamGrp->GetUnsigned(pstr, UInt));
}
Py::Object ParameterGrpPy::getUnsigneds(const Py::Tuple& args)
{
char *filter=nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter))
char* filter = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter)) {
throw Py::Exception();
}
std::vector<std::pair<std::string,unsigned long> > map = _cParamGrp->GetUnsignedMap(filter);
std::vector<std::pair<std::string, unsigned long>> map = _cParamGrp->GetUnsignedMap(filter);
Py::List list;
for (const auto& it : map) {
list.append(Py::String(it.first));
@@ -483,32 +505,35 @@ Py::Object ParameterGrpPy::getUnsigneds(const Py::Tuple& args)
Py::Object ParameterGrpPy::setFloat(const Py::Tuple& args)
{
char *pstr = nullptr;
double Float{};
if (!PyArg_ParseTuple(args.ptr(), "sd", &pstr,&Float))
char* pstr = nullptr;
double Float {};
if (!PyArg_ParseTuple(args.ptr(), "sd", &pstr, &Float)) {
throw Py::Exception();
}
_cParamGrp->SetFloat(pstr,Float);
_cParamGrp->SetFloat(pstr, Float);
return Py::None();
}
Py::Object ParameterGrpPy::getFloat(const Py::Tuple& args)
{
char *pstr = nullptr;
double Float=0.0;
if (!PyArg_ParseTuple(args.ptr(), "s|d", &pstr,&Float))
char* pstr = nullptr;
double Float = 0.0;
if (!PyArg_ParseTuple(args.ptr(), "s|d", &pstr, &Float)) {
throw Py::Exception();
}
return Py::Float(_cParamGrp->GetFloat(pstr,Float));
return Py::Float(_cParamGrp->GetFloat(pstr, Float));
}
Py::Object ParameterGrpPy::getFloats(const Py::Tuple& args)
{
char *filter=nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter))
char* filter = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter)) {
throw Py::Exception();
}
std::vector<std::pair<std::string,double> > map = _cParamGrp->GetFloatMap(filter);
std::vector<std::pair<std::string, double>> map = _cParamGrp->GetFloatMap(filter);
Py::List list;
for (const auto& it : map) {
list.append(Py::String(it.first));
@@ -519,32 +544,35 @@ Py::Object ParameterGrpPy::getFloats(const Py::Tuple& args)
Py::Object ParameterGrpPy::setString(const Py::Tuple& args)
{
char *pstr = nullptr;
char * str = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "ss", &pstr,&str))
char* pstr = nullptr;
char* str = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "ss", &pstr, &str)) {
throw Py::Exception();
}
_cParamGrp->SetASCII(pstr,str);
_cParamGrp->SetASCII(pstr, str);
return Py::None();
}
Py::Object ParameterGrpPy::getString(const Py::Tuple& args)
{
char *pstr = nullptr;
char * str="";
if (!PyArg_ParseTuple(args.ptr(), "s|s", &pstr,&str))
char* pstr = nullptr;
char* str = "";
if (!PyArg_ParseTuple(args.ptr(), "s|s", &pstr, &str)) {
throw Py::Exception();
}
return Py::String(_cParamGrp->GetASCII(pstr,str));
return Py::String(_cParamGrp->GetASCII(pstr, str));
}
Py::Object ParameterGrpPy::getStrings(const Py::Tuple& args)
{
char *filter=nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter))
char* filter = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "|s", &filter)) {
throw Py::Exception();
}
std::vector<std::pair<std::string,std::string> > map = _cParamGrp->GetASCIIMap(filter);
std::vector<std::pair<std::string, std::string>> map = _cParamGrp->GetASCIIMap(filter);
Py::List list;
for (const auto& it : map) {
list.append(Py::String(it.first));
@@ -555,9 +583,10 @@ Py::Object ParameterGrpPy::getStrings(const Py::Tuple& args)
Py::Object ParameterGrpPy::remInt(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->RemoveInt(pstr);
return Py::None();
@@ -565,9 +594,10 @@ Py::Object ParameterGrpPy::remInt(const Py::Tuple& args)
Py::Object ParameterGrpPy::remUnsigned(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->RemoveUnsigned(pstr);
return Py::None();
@@ -575,9 +605,10 @@ Py::Object ParameterGrpPy::remUnsigned(const Py::Tuple& args)
Py::Object ParameterGrpPy::remBool(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->RemoveBool(pstr);
return Py::None();
@@ -585,9 +616,10 @@ Py::Object ParameterGrpPy::remBool(const Py::Tuple& args)
Py::Object ParameterGrpPy::remGroup(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->RemoveGrp(pstr);
return Py::None();
@@ -595,9 +627,10 @@ Py::Object ParameterGrpPy::remGroup(const Py::Tuple& args)
Py::Object ParameterGrpPy::remFloat(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->RemoveFloat(pstr);
return Py::None();
@@ -605,9 +638,10 @@ Py::Object ParameterGrpPy::remFloat(const Py::Tuple& args)
Py::Object ParameterGrpPy::remString(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->RemoveASCII(pstr);
return Py::None();
@@ -615,8 +649,9 @@ Py::Object ParameterGrpPy::remString(const Py::Tuple& args)
Py::Object ParameterGrpPy::clear(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
_cParamGrp->Clear();
return Py::None();
@@ -624,17 +659,19 @@ Py::Object ParameterGrpPy::clear(const Py::Tuple& args)
Py::Object ParameterGrpPy::isEmpty(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
return Py::Boolean(_cParamGrp->IsEmpty());
}
Py::Object ParameterGrpPy::hasGroup(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
return Py::Boolean(_cParamGrp->HasGroup(pstr));
}
@@ -642,12 +679,14 @@ Py::Object ParameterGrpPy::hasGroup(const Py::Tuple& args)
Py::Object ParameterGrpPy::attach(const Py::Tuple& args)
{
PyObject* obj = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "O", &obj))
if (!PyArg_ParseTuple(args.ptr(), "O", &obj)) {
throw Py::Exception();
}
Py::Object o(obj);
if (!o.hasAttr(std::string("onChange")))
if (!o.hasAttr(std::string("onChange"))) {
throw Py::TypeError("Object has no onChange attribute");
}
for (ParameterGrpObserver* it : _observers) {
if (it->isEqual(o)) {
@@ -665,19 +704,23 @@ Py::Object ParameterGrpPy::attach(const Py::Tuple& args)
Py::Object ParameterGrpPy::attachManager(const Py::Tuple& args)
{
PyObject* obj = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "O", &obj))
if (!PyArg_ParseTuple(args.ptr(), "O", &obj)) {
throw Py::Exception();
}
if (!_cParamGrp->Manager())
if (!_cParamGrp->Manager()) {
throw Py::RuntimeError("Parameter has no manager");
}
Py::Object o(obj);
if (!o.hasAttr(std::string("slotParamChanged")))
if (!o.hasAttr(std::string("slotParamChanged"))) {
throw Py::TypeError("Object has no slotParamChanged attribute");
}
Py::Object attr(o.getAttr("slotParamChanged"));
if (!attr.isCallable())
if (!attr.isCallable()) {
throw Py::TypeError("Object has no slotParamChanged callable attribute");
}
for (ParameterGrpObserver* it : _observers) {
if (it->isEqual(o)) {
@@ -686,20 +729,25 @@ Py::Object ParameterGrpPy::attachManager(const Py::Tuple& args)
}
ParameterGrpObserver* obs = new ParameterGrpObserver(o, attr, _cParamGrp);
obs->conn = _cParamGrp->Manager()->signalParamChanged.connect(
[obs](ParameterGrp *Param, ParameterGrp::ParamType Type, const char *Name, const char *Value) {
if (!Param) return;
obs->conn =
_cParamGrp->Manager()->signalParamChanged.connect([obs](ParameterGrp* Param,
ParameterGrp::ParamType Type,
const char* Name,
const char* Value) {
if (!Param) {
return;
}
for (auto p = Param; p; p = p->Parent()) {
if (p == obs->_target) {
Base::PyGILStateLocker lock;
Py::TupleN args(
Py::asObject(new ParameterGrpPy(Param)),
Py::String(ParameterGrp::TypeName(Type)),
Py::String(Name ? Name : ""),
Py::String(Value ? Value : ""));
Py::TupleN args(Py::asObject(new ParameterGrpPy(Param)),
Py::String(ParameterGrp::TypeName(Type)),
Py::String(Name ? Name : ""),
Py::String(Value ? Value : ""));
try {
Py::Callable(obs->callable).apply(args);
} catch (Py::Exception &) {
}
catch (Py::Exception&) {
Base::PyException e;
e.ReportException();
}
@@ -715,12 +763,14 @@ Py::Object ParameterGrpPy::attachManager(const Py::Tuple& args)
Py::Object ParameterGrpPy::detach(const Py::Tuple& args)
{
PyObject* obj = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "O", &obj))
if (!PyArg_ParseTuple(args.ptr(), "O", &obj)) {
throw Py::Exception();
}
Py::Object o(obj);
if (!o.hasAttr(std::string("onChange")))
if (!o.hasAttr(std::string("onChange"))) {
throw Py::TypeError("Object has no onChange attribute");
}
for (ParameterGrpObserverList::iterator it = _observers.begin(); it != _observers.end(); ++it) {
if ((*it)->isEqual(o)) {
@@ -737,9 +787,10 @@ Py::Object ParameterGrpPy::detach(const Py::Tuple& args)
Py::Object ParameterGrpPy::notify(const Py::Tuple& args)
{
char *pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr))
char* pstr = nullptr;
if (!PyArg_ParseTuple(args.ptr(), "s", &pstr)) {
throw Py::Exception();
}
_cParamGrp->Notify(pstr);
return Py::None();
@@ -747,8 +798,9 @@ Py::Object ParameterGrpPy::notify(const Py::Tuple& args)
Py::Object ParameterGrpPy::notifyAll(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
_cParamGrp->NotifyAll();
return Py::None();
@@ -756,71 +808,73 @@ Py::Object ParameterGrpPy::notifyAll(const Py::Tuple& args)
Py::Object ParameterGrpPy::getContents(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
if (!PyArg_ParseTuple(args.ptr(), "")) {
throw Py::Exception();
}
if (_cParamGrp->IsEmpty())
if (_cParamGrp->IsEmpty()) {
return Py::None();
}
Py::List list;
// filling up Text nodes
std::vector<std::pair<std::string,std::string> > mcTextMap = _cParamGrp->GetASCIIMap();
for (const auto & it : mcTextMap) {
std::vector<std::pair<std::string, std::string>> mcTextMap = _cParamGrp->GetASCIIMap();
for (const auto& it : mcTextMap) {
Py::Tuple t2(3);
t2.setItem(0,Py::String("String"));
t2.setItem(1,Py::String(it.first.c_str()));
t2.setItem(2,Py::String(it.second.c_str()));
t2.setItem(0, Py::String("String"));
t2.setItem(1, Py::String(it.first.c_str()));
t2.setItem(2, Py::String(it.second.c_str()));
list.append(t2);
}
// filling up Int nodes
std::vector<std::pair<std::string,long> > mcIntMap = _cParamGrp->GetIntMap();
for (const auto & it : mcIntMap) {
std::vector<std::pair<std::string, long>> mcIntMap = _cParamGrp->GetIntMap();
for (const auto& it : mcIntMap) {
Py::Tuple t3(3);
t3.setItem(0,Py::String("Integer"));
t3.setItem(1,Py::String(it.first.c_str()));
t3.setItem(2,Py::Long(it.second));
t3.setItem(0, Py::String("Integer"));
t3.setItem(1, Py::String(it.first.c_str()));
t3.setItem(2, Py::Long(it.second));
list.append(t3);
}
// filling up Float nodes
std::vector<std::pair<std::string,double> > mcFloatMap = _cParamGrp->GetFloatMap();
for (const auto & it : mcFloatMap) {
std::vector<std::pair<std::string, double>> mcFloatMap = _cParamGrp->GetFloatMap();
for (const auto& it : mcFloatMap) {
Py::Tuple t4(3);
t4.setItem(0,Py::String("Float"));
t4.setItem(1,Py::String(it.first.c_str()));
t4.setItem(2,Py::Float(it.second));
t4.setItem(0, Py::String("Float"));
t4.setItem(1, Py::String(it.first.c_str()));
t4.setItem(2, Py::Float(it.second));
list.append(t4);
}
// filling up bool nodes
std::vector<std::pair<std::string,bool> > mcBoolMap = _cParamGrp->GetBoolMap();
for (const auto & it : mcBoolMap) {
std::vector<std::pair<std::string, bool>> mcBoolMap = _cParamGrp->GetBoolMap();
for (const auto& it : mcBoolMap) {
Py::Tuple t5(3);
t5.setItem(0,Py::String("Boolean"));
t5.setItem(1,Py::String(it.first.c_str()));
t5.setItem(2,Py::Boolean(it.second));
t5.setItem(0, Py::String("Boolean"));
t5.setItem(1, Py::String(it.first.c_str()));
t5.setItem(2, Py::Boolean(it.second));
list.append(t5);
}
// filling up UInt nodes
std::vector<std::pair<std::string,unsigned long> > mcUIntMap = _cParamGrp->GetUnsignedMap();
for (const auto & it : mcUIntMap) {
std::vector<std::pair<std::string, unsigned long>> mcUIntMap = _cParamGrp->GetUnsignedMap();
for (const auto& it : mcUIntMap) {
Py::Tuple t6(3);
t6.setItem(0,Py::String("Unsigned Long"));
t6.setItem(1,Py::String(it.first.c_str()));
t6.setItem(2,Py::Long(it.second));
t6.setItem(0, Py::String("Unsigned Long"));
t6.setItem(1, Py::String(it.first.c_str()));
t6.setItem(2, Py::Long(it.second));
list.append(t6);
}
return list;
}
} // namespace Base
} // namespace Base
/** python wrapper function
*/
PyObject* GetPyObject(const Base::Reference<ParameterGrp> &hcParamGrp)
*/
PyObject* GetPyObject(const Base::Reference<ParameterGrp>& hcParamGrp)
{
static bool init = false;
if (!init) {