File: str.h

package info (click to toggle)
python-scipy 0.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,464 kB
  • ctags: 79,406
  • sloc: python: 143,495; cpp: 89,357; fortran: 81,650; ansic: 79,778; makefile: 364; sh: 265
file content (62 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/******************************************** 
  copyright 1999 McMillan Enterprises, Inc.
  www.mcmillan-inc.com
  
  modified heavily for weave by eric jones
*********************************************/
#if !defined(STR_H_INCLUDED_)
#define STR_H_INCLUDED_

#include <string>
#include "object.h"
#include "sequence.h"

namespace py {

class str : public sequence
{
public:
  str() : sequence() {};
  str(const char* s)
    : sequence(PyString_FromString((char* )s)) { lose_ref(_obj); }
  str(const char* s, int sz)
    : sequence(PyString_FromStringAndSize((char* )s, sz)) {  lose_ref(_obj); }
  str(const str& other)
    : sequence(other) {};
  str(PyObject* obj)
    : sequence(obj) { _violentTypeCheck(); };
  str(const object& other)
    : sequence(other) { _violentTypeCheck(); };
  virtual ~str() {};

  virtual str& operator=(const str& other) {
    grab_ref(other);
    return *this;
  };
  str& operator=(const object& other) {
    grab_ref(other);
    _violentTypeCheck();
    return *this;
  };
  virtual void _violentTypeCheck() {
    if (!PyString_Check(_obj)) {
      grab_ref(0);
      fail(PyExc_TypeError, "Not a Python String");
    }
  };
  operator const char* () const {
    return PyString_AsString(_obj);
  };
  /*
  static str format(const str& fmt, tuple& args){
    PyObject * rslt =PyString_Format(fmt, args);
    if (rslt==0)
      fail(PyExc_RuntimeError, "string format failed");
    return lose_ref(rslt);
  };
  */
}; // class str

} // namespace

#endif // STR_H_INCLUDED_