Skip to content

Commit 68a6038

Browse files
committed
restore cxx5
svn path=/trunk/matplotlib/; revision=8087
1 parent 7a5429e commit 68a6038

File tree

11 files changed

+6928
-0
lines changed

11 files changed

+6928
-0
lines changed

CXX/Config.hxx

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//-----------------------------------------------------------------------------
2+
//
3+
// Copyright (c) 1998 - 2007, The Regents of the University of California
4+
// Produced at the Lawrence Livermore National Laboratory
5+
// All rights reserved.
6+
//
7+
// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The
8+
// full copyright notice is contained in the file COPYRIGHT located at the root
9+
// of the PyCXX distribution.
10+
//
11+
// Redistribution and use in source and binary forms, with or without
12+
// modification, are permitted provided that the following conditions are met:
13+
//
14+
// - Redistributions of source code must retain the above copyright notice,
15+
// this list of conditions and the disclaimer below.
16+
// - Redistributions in binary form must reproduce the above copyright notice,
17+
// this list of conditions and the disclaimer (as noted below) in the
18+
// documentation and/or materials provided with the distribution.
19+
// - Neither the name of the UC/LLNL nor the names of its contributors may be
20+
// used to endorse or promote products derived from this software without
21+
// specific prior written permission.
22+
//
23+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF
27+
// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR
28+
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32+
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33+
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
34+
// DAMAGE.
35+
//
36+
//-----------------------------------------------------------------------------
37+
38+
#ifndef __PyCXX_config_hh__
39+
#define __PyCXX_config_hh__
40+
41+
//
42+
// Microsoft VC++ 6.0 has no traits
43+
//
44+
#if defined( _MSC_VER )
45+
46+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
47+
48+
#elif defined( __GNUC__ )
49+
# if __GNUC__ >= 3
50+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
51+
# else
52+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 0
53+
#endif
54+
55+
//
56+
// Assume all other compilers do
57+
//
58+
#else
59+
60+
// Macros to deal with deficiencies in compilers
61+
# define STANDARD_LIBRARY_HAS_ITERATOR_TRAITS 1
62+
#endif
63+
64+
#if STANDARD_LIBRARY_HAS_ITERATOR_TRAITS
65+
# define random_access_iterator_parent(itemtype) std::iterator<std::random_access_iterator_tag,itemtype,int>
66+
#else
67+
# define random_access_iterator_parent(itemtype) std::random_access_iterator<itemtype, int>
68+
#endif
69+
70+
//
71+
// Which C++ standard is in use?
72+
//
73+
#if defined( _MSC_VER )
74+
# if _MSC_VER <= 1200
75+
// MSVC++ 6.0
76+
# define PYCXX_ISO_CPP_LIB 0
77+
# define STR_STREAM <strstream>
78+
# define TEMPLATE_TYPENAME class
79+
# else
80+
# define PYCXX_ISO_CPP_LIB 1
81+
# define STR_STREAM <sstream>
82+
# define TEMPLATE_TYPENAME typename
83+
# endif
84+
#elif defined( __GNUC__ )
85+
# if __GNUC__ >= 3
86+
# define PYCXX_ISO_CPP_LIB 1
87+
# define STR_STREAM <sstream>
88+
# define TEMPLATE_TYPENAME typename
89+
# else
90+
# define PYCXX_ISO_CPP_LIB 0
91+
# define STR_STREAM <strstream>
92+
# define TEMPLATE_TYPENAME class
93+
# endif
94+
#endif
95+
96+
#if PYCXX_ISO_CPP_LIB
97+
# define STR_STREAM <sstream>
98+
# define OSTRSTREAM ostringstream
99+
# define EXPLICIT_TYPENAME typename
100+
# define EXPLICIT_CLASS class
101+
# define TEMPLATE_TYPENAME typename
102+
#else
103+
# define STR_STREAM <strstream>
104+
# define OSTRSTREAM ostrstream
105+
# define EXPLICIT_TYPENAME
106+
# define EXPLICIT_CLASS
107+
# define TEMPLATE_TYPENAME class
108+
#endif
109+
110+
// before 2.5 Py_ssize_t was missing
111+
#ifndef PY_MAJOR_VERSION
112+
#error not defined PY_MAJOR_VERSION
113+
#endif
114+
#if PY_MAJOR_VERSION < 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5)
115+
typedef int Py_ssize_t;
116+
#endif
117+
118+
// hash_map container usage selection
119+
// 1) if PYCXX_USING_STD_MAP is defined PyCXX will be using std::map<> container
120+
// implementation only.
121+
// 2) if compilers are used other than MS Visual Studio (7.1+) or GCC 3.x
122+
// STANDARD_LIBRARY_HAS_HASH_MAP must be defined before compilation to
123+
// make PyCXX using hash_map container.
124+
#if !defined( PYCXX_USING_STD_MAP )
125+
#if defined( _MSC_VER ) || defined( __INTEL_COMPILER ) || defined ( __ICC ) || (defined( __GNUC__ ) && ( __GNUC__ > 3 ))
126+
# define PYCXX_USING_HASH_MAP
127+
#else
128+
# if defined( STANDARD_LIBRARY_HAS_HASH_MAP ) && !defined( PYCXX_USING_HASH_MAP )
129+
# define PYCXX_USING_HASH_MAP
130+
# endif
131+
#endif
132+
#endif
133+
134+
#endif // __PyCXX_config_hh__

CXX/Exception.hxx

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
//-----------------------------------------------------------------------------
2+
//
3+
// Copyright (c) 1998 - 2007, The Regents of the University of California
4+
// Produced at the Lawrence Livermore National Laboratory
5+
// All rights reserved.
6+
//
7+
// This file is part of PyCXX. For details,see http://cxx.sourceforge.net/. The
8+
// full copyright notice is contained in the file COPYRIGHT located at the root
9+
// of the PyCXX distribution.
10+
//
11+
// Redistribution and use in source and binary forms, with or without
12+
// modification, are permitted provided that the following conditions are met:
13+
//
14+
// - Redistributions of source code must retain the above copyright notice,
15+
// this list of conditions and the disclaimer below.
16+
// - Redistributions in binary form must reproduce the above copyright notice,
17+
// this list of conditions and the disclaimer (as noted below) in the
18+
// documentation and/or materials provided with the distribution.
19+
// - Neither the name of the UC/LLNL nor the names of its contributors may be
20+
// used to endorse or promote products derived from this software without
21+
// specific prior written permission.
22+
//
23+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26+
// ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF THE UNIVERSITY OF
27+
// CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR
28+
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32+
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33+
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
34+
// DAMAGE.
35+
//
36+
//-----------------------------------------------------------------------------
37+
38+
#ifndef __CXX_Exception_h
39+
#define __CXX_Exception_h
40+
41+
#include "CXX/WrapPython.h"
42+
#include "CXX/Version.hxx"
43+
#include "CXX/Config.hxx"
44+
#include "CXX/IndirectPythonInterface.hxx"
45+
46+
#include <string>
47+
#include <iostream>
48+
49+
// This mimics the Python structure, in order to minimize confusion
50+
namespace Py
51+
{
52+
class ExtensionExceptionType;
53+
54+
class Object;
55+
56+
class Exception
57+
{
58+
public:
59+
Exception( ExtensionExceptionType &exception, const std::string& reason );
60+
Exception( ExtensionExceptionType &exception, Object &reason );
61+
62+
explicit Exception ()
63+
{}
64+
65+
Exception (const std::string& reason)
66+
{
67+
PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
68+
}
69+
70+
Exception (PyObject* exception, const std::string& reason)
71+
{
72+
PyErr_SetString (exception, reason.c_str());
73+
}
74+
75+
Exception (PyObject* exception, Object &reason);
76+
77+
void clear() // clear the error
78+
// technically but not philosophically const
79+
{
80+
PyErr_Clear();
81+
}
82+
};
83+
84+
85+
// Abstract
86+
class StandardError: public Exception
87+
{
88+
protected:
89+
explicit StandardError()
90+
{}
91+
};
92+
93+
class LookupError: public StandardError
94+
{
95+
protected:
96+
explicit LookupError()
97+
{}
98+
};
99+
100+
class ArithmeticError: public StandardError
101+
{
102+
protected:
103+
explicit ArithmeticError()
104+
{}
105+
};
106+
107+
class EnvironmentError: public StandardError
108+
{
109+
protected:
110+
explicit EnvironmentError()
111+
{}
112+
};
113+
114+
// Concrete
115+
116+
class TypeError: public StandardError
117+
{
118+
public:
119+
TypeError (const std::string& reason)
120+
: StandardError()
121+
{
122+
PyErr_SetString (Py::_Exc_TypeError(),reason.c_str());
123+
}
124+
};
125+
126+
class IndexError: public LookupError
127+
{
128+
public:
129+
IndexError (const std::string& reason)
130+
: LookupError()
131+
{
132+
PyErr_SetString (Py::_Exc_IndexError(), reason.c_str());
133+
}
134+
};
135+
136+
class AttributeError: public StandardError
137+
{
138+
public:
139+
AttributeError (const std::string& reason)
140+
: StandardError()
141+
{
142+
PyErr_SetString (Py::_Exc_AttributeError(), reason.c_str());
143+
}
144+
};
145+
146+
class NameError: public StandardError
147+
{
148+
public:
149+
NameError (const std::string& reason)
150+
: StandardError()
151+
{
152+
PyErr_SetString (Py::_Exc_NameError(), reason.c_str());
153+
}
154+
};
155+
156+
class RuntimeError: public StandardError
157+
{
158+
public:
159+
RuntimeError (const std::string& reason)
160+
: StandardError()
161+
{
162+
PyErr_SetString (Py::_Exc_RuntimeError(), reason.c_str());
163+
}
164+
};
165+
166+
class SystemError: public StandardError
167+
{
168+
public:
169+
SystemError (const std::string& reason)
170+
: StandardError()
171+
{
172+
PyErr_SetString (Py::_Exc_SystemError(),reason.c_str());
173+
}
174+
};
175+
176+
class KeyError: public LookupError
177+
{
178+
public:
179+
KeyError (const std::string& reason)
180+
: LookupError()
181+
{
182+
PyErr_SetString (Py::_Exc_KeyError(),reason.c_str());
183+
}
184+
};
185+
186+
187+
class ValueError: public StandardError
188+
{
189+
public:
190+
ValueError (const std::string& reason)
191+
: StandardError()
192+
{
193+
PyErr_SetString (Py::_Exc_ValueError(), reason.c_str());
194+
}
195+
};
196+
197+
class OverflowError: public ArithmeticError
198+
{
199+
public:
200+
OverflowError (const std::string& reason)
201+
: ArithmeticError()
202+
{
203+
PyErr_SetString (Py::_Exc_OverflowError(), reason.c_str());
204+
}
205+
};
206+
207+
class ZeroDivisionError: public ArithmeticError
208+
{
209+
public:
210+
ZeroDivisionError (const std::string& reason)
211+
: ArithmeticError()
212+
{
213+
PyErr_SetString (Py::_Exc_ZeroDivisionError(), reason.c_str());
214+
}
215+
};
216+
217+
class FloatingPointError: public ArithmeticError
218+
{
219+
public:
220+
FloatingPointError (const std::string& reason)
221+
: ArithmeticError()
222+
{
223+
PyErr_SetString (Py::_Exc_FloatingPointError(), reason.c_str());
224+
}
225+
};
226+
227+
class MemoryError: public StandardError
228+
{
229+
public:
230+
MemoryError (const std::string& reason)
231+
: StandardError()
232+
{
233+
PyErr_SetString (Py::_Exc_MemoryError(), reason.c_str());
234+
}
235+
};
236+
237+
class SystemExit: public StandardError
238+
{
239+
public:
240+
SystemExit (const std::string& reason)
241+
: StandardError()
242+
{
243+
PyErr_SetString (Py::_Exc_SystemExit(),reason.c_str());
244+
}
245+
};
246+
247+
}// Py
248+
249+
#endif

0 commit comments

Comments
 (0)