2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 18:12:43 +00:00

Remove example files that were accidentally added to the main branch.

[SVN r9017]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2001-02-07 23:58:44 +00:00
parent 1d17690f69
commit 0d04bf8e34
11 changed files with 6 additions and 322 deletions

6
example/README Normal file
View File

@@ -0,0 +1,6 @@
To get started with the Boost Python Library, use the examples
getting_started?.cpp and abstract.cpp.
The files example1.cpp and rwgk1.cpp are obsolete. They are only
included because the makefiles in the build directory still refer to
them. This will be fixed later.

View File

@@ -1,69 +0,0 @@
#include "ivect.h"
#include "dvect.h"
#include <boost/python/class_builder.hpp>
#include <boost/python/detail/import_extension_class.hpp>
namespace python = boost::python;
namespace {
vects::ivect dvect_as_ivect(const vects::dvect& dv)
{
vects::ivect iv(dv.size());
vects::ivect::iterator iviter = iv.begin();
for (int i = 0; i < dv.size(); i++) iviter[i] = static_cast<int>(dv[i]);
return iv;
}
boost::python::tuple ivect_as_tuple(const vects::ivect& iv)
{
return iv.as_tuple();
}
std::auto_ptr<vects::ivect> auto_ptr_ivect(const vects::dvect& dv)
{
return std::auto_ptr<vects::ivect>(new vects::ivect(dvect_as_ivect(dv)));
}
boost::shared_ptr<vects::ivect> shared_ptr_ivect(const vects::dvect& dv)
{
return boost::shared_ptr<vects::ivect>(new vects::ivect(dvect_as_ivect(dv)));
}
boost::python::tuple auto_ptr_ivect_as_tuple(std::auto_ptr<vects::ivect>& iv)
{
return iv->as_tuple();
}
boost::python::tuple shared_ptr_ivect_as_tuple(boost::shared_ptr<vects::ivect>& iv)
{
return iv->as_tuple();
}
}
extern "C"
DL_EXPORT(void)
initdvect()
{
try
{
python::module_builder this_module("dvect");
python::x_class_builder<vects::dvect> dvect_class(this_module, "dvect");
python::import_class_builder<vects::ivect> ivect_class("ivect", "ivect");
dvect_class.def(python::constructor<python::tuple>());
dvect_class.def(&vects::dvect::as_tuple, "as_tuple");
dvect_class.def(dvect_as_ivect, "as_ivect");
this_module.def(ivect_as_tuple, "ivect_as_tuple");
dvect_class.def(auto_ptr_ivect, "auto_ptr_ivect");
dvect_class.def(shared_ptr_ivect, "shared_ptr_ivect");
this_module.def(auto_ptr_ivect_as_tuple, "auto_ptr_ivect_as_tuple");
this_module.def(shared_ptr_ivect_as_tuple, "shared_ptr_ivect_as_tuple");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -1,32 +0,0 @@
#ifndef DVECT_H
#define DVECT_H
#include <vector>
#include <boost/python/class_builder.hpp>
namespace vects {
struct dvect : public std::vector<double>
{
dvect() : std::vector<double>() {}
dvect(size_t n) : std::vector<double>(n) {}
dvect(boost::python::tuple tuple) : std::vector<double>(tuple.size())
{
std::vector<double>::iterator v_it = begin();
for (int i = 0; i < tuple.size(); i++)
v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
boost::python::type<double>());
}
boost::python::tuple as_tuple() const
{
boost::python::tuple t(size());
for (int i = 0; i < size(); i++)
t.set_item(i,
boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
return t;
}
};
}
#endif // DVECT_H

View File

@@ -1,69 +0,0 @@
#include "ivect.h"
#include "dvect.h"
#include <boost/python/class_builder.hpp>
#include <boost/python/detail/import_extension_class.hpp>
namespace python = boost::python;
namespace {
vects::dvect ivect_as_dvect(const vects::ivect& iv)
{
vects::dvect dv(iv.size());
vects::dvect::iterator dviter = dv.begin();
for (int i = 0; i < iv.size(); i++) dviter[i] = static_cast<double>(iv[i]);
return dv;
}
boost::python::tuple dvect_as_tuple(const vects::dvect& dv)
{
return dv.as_tuple();
}
std::auto_ptr<vects::dvect> auto_ptr_dvect(const vects::ivect& iv)
{
return std::auto_ptr<vects::dvect>(new vects::dvect(ivect_as_dvect(iv)));
}
boost::shared_ptr<vects::dvect> shared_ptr_dvect(const vects::ivect& iv)
{
return boost::shared_ptr<vects::dvect>(new vects::dvect(ivect_as_dvect(iv)));
}
boost::python::tuple auto_ptr_dvect_as_tuple(std::auto_ptr<vects::dvect>& dv)
{
return dv->as_tuple();
}
boost::python::tuple shared_ptr_dvect_as_tuple(boost::shared_ptr<vects::dvect>& dv)
{
return dv->as_tuple();
}
}
extern "C"
DL_EXPORT(void)
initivect()
{
try
{
python::module_builder this_module("ivect");
python::x_class_builder<vects::ivect> ivect_class(this_module, "ivect");
python::import_class_builder<vects::dvect> dvect_class("dvect", "dvect");
ivect_class.def(python::constructor<python::tuple>());
ivect_class.def(&vects::ivect::as_tuple, "as_tuple");
ivect_class.def(ivect_as_dvect, "as_dvect");
this_module.def(dvect_as_tuple, "dvect_as_tuple");
ivect_class.def(auto_ptr_dvect, "auto_ptr_dvect");
ivect_class.def(shared_ptr_dvect, "shared_ptr_dvect");
this_module.def(auto_ptr_dvect_as_tuple, "auto_ptr_dvect_as_tuple");
this_module.def(shared_ptr_dvect_as_tuple, "shared_ptr_dvect_as_tuple");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -1,32 +0,0 @@
#ifndef IVECT_H
#define IVECT_H
#include <vector>
#include <boost/python/class_builder.hpp>
namespace vects {
struct ivect : public std::vector<int>
{
ivect() : std::vector<int>() {}
ivect(size_t n) : std::vector<int>(n) {}
ivect(boost::python::tuple tuple) : std::vector<int>(tuple.size())
{
std::vector<int>::iterator v_it = begin();
for (int i = 0; i < tuple.size(); i++)
v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
boost::python::type<int>());
}
boost::python::tuple as_tuple() const
{
boost::python::tuple t(size());
for (int i = 0; i < size(); i++)
t.set_item(i,
boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
return t;
}
};
}
#endif // IVECT_H

View File

@@ -1,24 +0,0 @@
#include <boost/python/class_builder.hpp>
#include <boost/python/detail/import_extension_class.hpp>
namespace python = boost::python;
#include "store.h"
extern "C"
DL_EXPORT(void)
initnoncopyable_export()
{
try
{
python::module_builder this_module("noncopyable_export");
python::xptr_class_builder<store> store_class(this_module, "store");
store_class.def(python::constructor<int>());
store_class.def(&store::recall, "recall");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -1,42 +0,0 @@
#include <boost/python/class_builder.hpp>
#include <boost/python/detail/import_extension_class.hpp>
namespace python = boost::python;
#include "store.h"
namespace { // Avoid cluttering the global namespace.
// A function with store objects as both input and output parameters.
// Because the copy constructor is disabled, we cannot pass a store
// object by value. Instead, we pass a smart pointer.
std::auto_ptr<store> add_stores(const store& s1, const store& s2)
{
int sum = s1.recall() + s2.recall();
std::auto_ptr<store> ss = std::auto_ptr<store>(new store(sum));
return ss;
}
}
extern "C"
DL_EXPORT(void)
initnoncopyable_import()
{
try
{
python::module_builder this_module("noncopyable_import");
python::import_class_builder<store>
dvect_class("noncopyable_export", "store");
// Imagine all the additional classes with member functions
// that have store objects as input and output parameters.
// Lots and lots of them.
// However, to keep this example simple, we only define a
// module-level function.
this_module.def(add_stores, "add_stores");
}
catch(...)
{
python::handle_exception(); // Deal with the exception for Python
}
}

View File

@@ -1,14 +0,0 @@
#ifndef STORE_H
#define STORE_H
class store
{
private:
store(const store&) { } // Disable the copy constructor.
int number;
public:
store(const int i) : number(i) { }
int recall() const { return number; }
};
#endif // STORE_H

View File

@@ -1,16 +0,0 @@
import dvect
print dvect.dvect.__converters__
dv = dvect.dvect((1,2,3,4,5))
print dv
print dv.as_tuple()
iv = dv.as_ivect()
print iv
print iv.as_tuple()
print dvect.ivect_as_tuple(iv)
aiv = dv.auto_ptr_ivect()
print aiv
siv = dv.shared_ptr_ivect()
print dvect.auto_ptr_ivect_as_tuple(aiv)
print dvect.ivect_as_tuple(aiv)
print dvect.shared_ptr_ivect_as_tuple(siv)
print dvect.ivect_as_tuple(siv)

View File

@@ -1,16 +0,0 @@
import ivect
print ivect.ivect.__converters__
iv = ivect.ivect((1,2,3,4,5))
print iv
print iv.as_tuple()
dv = iv.as_dvect()
print dv
print dv.as_tuple()
print ivect.dvect_as_tuple(dv)
adv = iv.auto_ptr_dvect()
print adv
sdv = iv.shared_ptr_dvect()
print ivect.auto_ptr_dvect_as_tuple(adv)
print ivect.dvect_as_tuple(adv)
print ivect.shared_ptr_dvect_as_tuple(sdv)
print ivect.dvect_as_tuple(sdv)

View File

@@ -1,8 +0,0 @@
import noncopyable_export
import noncopyable_import
s1 = noncopyable_export.store(1)
print s1.recall()
s2 = noncopyable_export.store(2)
print s2.recall()
s3 = noncopyable_import.add_stores(s1, s2)
print s3.recall()