Ejemplo n.º 1
0
	ControllerData(const sixenseControllerData& data)
	{
		for(int i = 0; i < 3; ++i)
		{
			pos.append(data.pos[i]);
		}
		for(int y = 0; y < 3; ++y)
		{
			boost::python::list col;
			for(int x = 0; x < 3; ++x)
			{
				col.append(data.rot_mat[y][x]);
			}
			rot_mat.append(col);
		}
		joystick_x = data.joystick_x;
		joystick_y = data.joystick_y;
		trigger = data.trigger;
		buttons = data.buttons;
		sequence_number = data.sequence_number;
		for(int i = 0; i < 4; ++i)
		{
			rot_quat.append(data.rot_quat[i]);
		}
		firmware_revision = data.firmware_revision;
		hardware_revision = data.hardware_revision;
		packet_type = data.packet_type;
		magnetic_frequency = data.magnetic_frequency;
		enabled = data.enabled == 1;
		controller_index = data.controller_index;
		is_docked = data.is_docked == 1;
		which_hand = data.which_hand;
	}
Ejemplo n.º 2
0
bool PythonSignal::open(boost::python::list macAddress) {
  BOOST_VERIFY(mpSignal != 0);
  uint8_t mac[6] = {0,0,0,0,0,0};  
  if(boost::python::extract<size_t>(macAddress.attr("__len__")()) >= 6) {
    for (int i = 5; i >= 0; i--) {
      mac[i] = boost::python::extract<uint8_t>(macAddress.pop());
    }
  }
  return mpSignal->open(mac);
}
Ejemplo n.º 3
0
int periodise_wrap(boost::python::list args ) {
  int iSize = extract<int> (args.attr("__len__")()),
    iIb ;
  char ** argv = new char*[iSize+1] ;
  
#define NOM "periodise"

  argv[0] = new char[strlen(NOM)+1] ;
  strcpy (argv[0], NOM);

  for (iIb=0; iIb < iSize ; iIb ++) {
    const char * pcArg ;
    extract <const char*> earg(args[iIb]);
    if (earg.check()) {
      pcArg= earg() ;
      argv[iIb+1] = new char[strlen(pcArg)+1] ;
      strcpy (argv[iIb+1], pcArg);
    }
  } 

  int result = periodise (iSize+1, argv ) ;

  for (iIb = 0 ; iIb < iSize ;iIb ++) {
    delete [] argv[iIb] ;
  }
  delete [](argv) ;
  return result ;
}
Ejemplo n.º 4
0
inline void json::insert(const json::key_type& k, const boost::python::list& li)  {
	unsigned n = boost::python::extract<unsigned>(li.attr("__len__")());
	if(!n) return;
	jsonvec jv;
	for(unsigned i=0;i<n;++i)  {
		try  {
			qm_real v = boost::python::extract<qm_real>(li[i]);
			jv.add(v);
		}
		catch(...)  {
			try  {
				qm_string s = boost::python::extract<qm_string>(li[i]);
				jv.add(s);
			}
			catch(...)  {
				try  {
					json js(*boost::python::extract<json*>(li[i]));
					jv.add(js);
				}
				catch(...)  {
					QM_FAIL("Could not add list");
				}
			}
		}
	}		
	this->insert(k,jv);
}
Ejemplo n.º 5
0
void grid2utf(T const& grid_type,
                     boost::python::list& l,
                     std::vector<typename T::lookup_type>& key_order)
{
    using keys_type = std::map< typename T::lookup_type, typename T::value_type>;
    using keys_iterator = typename keys_type::iterator;

    typename T::data_type const& data = grid_type.data();
    typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
    typename T::feature_key_type::const_iterator feature_pos;

    keys_type keys;
    // start counting at utf8 codepoint 32, aka space character
    std::uint16_t codepoint = 32;

    std::size_t array_size = data.width();
    for (std::size_t y = 0; y < data.height(); ++y)
    {
        std::uint16_t idx = 0;
        const std::unique_ptr<Py_UNICODE[]> line(new Py_UNICODE[array_size]);
        typename T::value_type const* row = data.get_row(y);
        for (std::size_t x = 0; x < data.width(); ++x)
        {
            typename T::value_type feature_id = row[x];
            feature_pos = feature_keys.find(feature_id);
            if (feature_pos != feature_keys.end())
            {
                mapnik::grid::lookup_type val = feature_pos->second;
                keys_iterator key_pos = keys.find(val);
                if (key_pos == keys.end())
                {
                    // Create a new entry for this key. Skip the codepoints that
                    // can't be encoded directly in JSON.
                    if (codepoint == 34) ++codepoint;      // Skip "
                    else if (codepoint == 92) ++codepoint; // Skip backslash
                    if (feature_id == mapnik::grid::base_mask)
                    {
                        keys[""] = codepoint;
                        key_order.push_back("");
                    }
                    else
                    {
                        keys[val] = codepoint;
                        key_order.push_back(val);
                    }
                    line[idx++] = static_cast<Py_UNICODE>(codepoint);
                    ++codepoint;
                }
                else
                {
                    line[idx++] = static_cast<Py_UNICODE>(key_pos->second);
                }
            }
            // else, shouldn't get here...
        }
        l.append(boost::python::object(
                     boost::python::handle<>(
                         PyUnicode_FromUnicode(line.get(), array_size))));
    }
}
Ejemplo n.º 6
0
void grid2utf2(T const& grid_type,
               boost::python::list& l,
               std::vector<typename T::lookup_type>& key_order,
               unsigned int resolution)
{
    using keys_type = std::map< typename T::lookup_type, typename T::value_type>;
    using keys_iterator = typename keys_type::const_iterator;

    typename T::data_type const& data = grid_type.data();
    typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
    typename T::feature_key_type::const_iterator feature_pos;

    keys_type keys;
    // start counting at utf8 codepoint 32, aka space character
    uint16_t codepoint = 32;

    mapnik::grid::data_type target(data.width()/resolution,data.height()/resolution);
    mapnik::scale_grid(target,grid_type.data(),0.0,0.0);

    unsigned array_size = target.width();
    for (unsigned y = 0; y < target.height(); ++y)
    {
        uint16_t idx = 0;
        const std::unique_ptr<Py_UNICODE[]> line(new Py_UNICODE[array_size]);
        mapnik::grid::value_type * row = target.getRow(y);
        unsigned x;
        for (x = 0; x < target.width(); ++x)
        {
            feature_pos = feature_keys.find(row[x]);
            if (feature_pos != feature_keys.end())
            {
                mapnik::grid::lookup_type val = feature_pos->second;
                keys_iterator key_pos = keys.find(val);
                if (key_pos == keys.end())
                {
                    // Create a new entry for this key. Skip the codepoints that
                    // can't be encoded directly in JSON.
                    if (codepoint == 34) ++codepoint;      // Skip "
                    else if (codepoint == 92) ++codepoint; // Skip backslash
                    keys[val] = codepoint;
                    key_order.push_back(val);
                    line[idx++] = static_cast<Py_UNICODE>(codepoint);
                    ++codepoint;
                }
                else
                {
                    line[idx++] = static_cast<Py_UNICODE>(key_pos->second);
                }
            }
            // else, shouldn't get here...
        }
        l.append(boost::python::object(
                     boost::python::handle<>(
                         PyUnicode_FromUnicode(line.get(), array_size))));
    }
}
Ejemplo n.º 7
0
Array<double,1>* ObjToVector (const list& list)
{
    int len = boost::python::extract<int>(list.attr("__len__")());/**< Get the list length */
    Array<double,1>* vector = new Array<double,1>(len);
    for (int i = 0; i < len; i++)
    {
        (*vector)(i) = (boost::python::extract<int>(list[i]));
    }
    return vector;
}
Ejemplo n.º 8
0
Array<double,1>* ObjToVector (const vector<double>& list)
{
    int len = list.size();/**< Get the list length */
    Array<double,1>* vector = new Array<double,1>(len);
    for (int i = 0; i < len; i++)
    {
        (*vector)(i) = list[i];
    }
    return vector;
}
Ejemplo n.º 9
0
bool mpi_init(boost::python::list python_argv)
{
  using boost::python::extract;
  using boost::python::object;

  // If already initialized, do nothing but note that initialization
  // is done.
  int flag = 0;
  int result = MPI_Initialized(&flag);
  assert(result == MPI_SUCCESS);
  if (flag) return false;

  // Convert Python argv into C-style argc/argv. Ewwwww!
  int my_argc = extract<int>(python_argv.attr("__len__")());
  char** my_argv = new char*[my_argc];
  for (int arg = 0; arg < my_argc; ++arg)
    my_argv[arg] = strdup(extract<const char*>(python_argv[arg]));

  // Initialize MPI
  int mpi_argc = my_argc;
  char** mpi_argv = my_argv;
  result = MPI_Init(&mpi_argc, &mpi_argv);
  assert(result == MPI_SUCCESS);

  // If anything changed, convert C-style argc/argv into Python argv
  if (mpi_argv != my_argv) {
    // Tear down Python argv
    while (int(extract<int>(python_argv.attr("__len__")())) > 0)
      python_argv.pop();

    // Build up new Python argv
    for (int arg = 0; arg < mpi_argc; ++arg)
      python_argv.append(object(mpi_argv[arg]));
  }

  for (int arg = 0; arg < my_argc; ++arg)
    free(my_argv[arg]);
  delete [] my_argv;

  return true;
}
Ejemplo n.º 10
0
void CyMapGenerator::setPlotTypes(boost::python::list& listPlotTypes)
{
	if (!m_pMapGenerator)
	{
		return;
	}

	int* paiPlotTypes = NULL;
	gDLL->getPythonIFace()->putSeqInArray(listPlotTypes.ptr() /*src*/, &paiPlotTypes /*dst*/);
	m_pMapGenerator->setPlotTypes(paiPlotTypes);
	delete [] paiPlotTypes;
}
Ejemplo n.º 11
0
static void grid2utf(T const& grid_type,
                     boost::python::list& l,
                     std::vector<typename T::lookup_type>& key_order,
                     unsigned int resolution)
{
    //typename T::data_type const& data = grid_type.data();
    typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys();
    typename T::key_type keys;
    typename T::key_type::const_iterator key_pos;
    typename T::feature_key_type::const_iterator feature_pos;
    // start counting at utf8 codepoint 32, aka space character
    boost::uint16_t codepoint = 32;

    // TODO - use double?
    unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution);
    for (unsigned y = 0; y < grid_type.height(); y=y+resolution)
    {
        boost::uint16_t idx = 0;
        boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]);
        mapnik::grid::value_type const* row = grid_type.getRow(y);
        for (unsigned x = 0; x < grid_type.width(); x=x+resolution)
        {
            feature_pos = feature_keys.find(row[x]);
            if (feature_pos != feature_keys.end())
            {
                mapnik::grid::lookup_type val = feature_pos->second;
                key_pos = keys.find(val);
                if (key_pos == keys.end())
                {
                    // Create a new entry for this key. Skip the codepoints that
                    // can't be encoded directly in JSON.
                    if (codepoint == 34) ++codepoint;      // Skip "
                    else if (codepoint == 92) ++codepoint; // Skip backslash
                    keys[val] = codepoint;
                    key_order.push_back(val);
                    line[idx++] = static_cast<Py_UNICODE>(codepoint);
                    ++codepoint;
                }
                else
                {
                    line[idx++] = static_cast<Py_UNICODE>(key_pos->second);
                }
            }
            // else, shouldn't get here...
        }
        l.append(boost::python::object(
                     boost::python::handle<>(
                         PyUnicode_FromUnicode(line.get(), array_size))));
    }
}
Ejemplo n.º 12
0
Array<double,2>* ObjToArray(const vector<vector<double> >& list)
{
    int row = list.size();/**< Get the row length */
    int col = list[1].size();/**< Get the column length, all columns have the same size */
    Array<double,2>* tab = new Array<double,2>(row,col);
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j ++)
        {
            (*tab)(i,j) = list[i][j];
        }
    }
    return tab;
}
Ejemplo n.º 13
0
Array<double,2>* ObjToArray(const list& list)
{
    int row = boost::python::extract<int>(list.attr("__len__")());/**< Get the row length */
    int col = boost::python::extract<int>(list[1].attr("__len__")());/**< Get the column length, all columns have the same size * */
    Array<double,2>* tab = new Array<double,2>(row,col);
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j ++)
        {
            (*tab)(i,j) = (boost::python::extract<int>(list[i][j]));
        }
    }
    return tab;
}
Ejemplo n.º 14
0
ConvexHull2::ConvexHull2(boost::python::list points)
{
	boost::python::object lenObj = points.attr( "__len__" )();
	boost::python::extract<int> lenExtract( lenObj );
	if ( lenExtract.check() )
	{
		int numPoints = lenExtract;
		for (int pointI = 0; pointI < numPoints; pointI++)
		{
			boost::python::object pointObj = points[pointI];
			boost::python::extract<Point2&> pointExtract( pointObj );
			if ( pointExtract.check() )
			{
				addPoint( pointExtract );
			}
		}
	}
}
Ejemplo n.º 15
0
void NotepadPlusWrapper::clearCallback(boost::python::object callback, boost::python::list events)
{
	for(callbackT::iterator it = m_callbacks.begin(); it != m_callbacks.end(); )
	{
		if(it->second == callback && boost::python::extract<bool>(events.contains(it->first)))
		{
			it = m_callbacks.erase(it);
		}
		else
		{
			++it;
		}
	}
	if (m_callbacks.empty())
	{
		m_notificationsEnabled = false;
	}
}
Ejemplo n.º 16
0
Polygon2::Polygon2(boost::python::list verts)
{
	boost::python::object lenObj = verts.attr( "__len__" )();
	boost::python::extract<int> lenExtract( lenObj );
	if ( lenExtract.check() )
	{
		int numVerts = lenExtract;
		vertices.reserve( numVerts );
		for (int i = 0; i < numVerts; i++)
		{
			boost::python::object pointObj = verts[i];
			boost::python::extract<Point2&> pointExtract( pointObj );
			if ( pointExtract.check() )
			{
				vertices.push_back( pointExtract );
			}
		}
	}
}
Ejemplo n.º 17
0
void ScintillaWrapper::clearCallbackEvents(boost::python::list events)
{
	for(callbackT::iterator it = m_callbacks.begin(); it != m_callbacks.end(); )
	{
		if(boost::python::extract<bool>(events.contains(it->first)))
		{
			Py_DECREF(it->second);
			it = m_callbacks.erase(it);
		}
		else
		{
			++it;
		}
	}

	if (m_callbacks.empty())
	{
		m_notificationsEnabled = false;
	}
}
Ejemplo n.º 18
0
 void operator ()(boost::python::list mylist, const T& value) const
 {
   mylist.append( value );
 }