/[ascend]/trunk/pygtk/set.h
ViewVC logotype

Contents of /trunk/pygtk/set.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download) (as text)
Mon Apr 24 02:23:08 2006 UTC (14 years, 1 month ago) by johnpye
File MIME type: text/x-chdr
File size: 1891 byte(s)
Removed 'interface' directory in trunk/pygtk/interface (moved everything up a level)
Made corresponding changes to SCons* and spec files.
1 #ifndef ASCXX_SET_H
2 #define ASCXX_SET_H
3
4 #include <iostream>
5 #include <stdexcept>
6
7 #include "symchar.h"
8
9 #include "config.h"
10 extern "C"{
11 #include "utilities/ascConfig.h"
12 #include "compiler/compiler.h"
13 #include "compiler/setinstval.h"
14 }
15
16 /**
17 This C++ template defines ASCXX_Set<long> and ASCXX_Set<SymChar>
18 which can hold instance-variable sets (struct set_t) (as opposed
19 to 'struct Set' which is different!).
20
21 It has to be a template because the element type is different,
22 so the element accessor functions are different.
23
24 In python, this class can be wrapped in a more elegant way, see
25 ascend.i for details.
26 */
27
28 class Empty{
29 // empty class for use in ASCXX_Set<Empty>
30 };
31
32 template<class T>
33 class ASCXX_Set{
34 private:
35 const struct set_t *s;
36 public:
37
38 ASCXX_Set(){
39 throw std::runtime_error("Can't create new ASCXX_Set objects");
40 }
41
42 ASCXX_Set(const struct set_t *s) : s(s){
43 if(!isCorrectType()){
44 throw std::runtime_error("Invalid set creation");
45 }
46 }
47
48 const bool isCorrectType() const;
49
50 unsigned long length() const{
51 return Cardinality(s);
52 }
53
54 const T operator[](const unsigned long &index) const;
55 inline const T at(const unsigned long &index) const{
56 return (*this)[index];
57 }
58 };
59
60 template<>
61 const bool ASCXX_Set<long>::isCorrectType() const;
62
63 template<>
64 const bool ASCXX_Set<SymChar>::isCorrectType() const;
65
66 template<>
67 const bool ASCXX_Set<void>::isCorrectType() const;
68
69 template<class T>
70 std::ostream& operator<< (std::ostream& os, const ASCXX_Set<T>& s){
71 os << "[ ";
72 bool first=true;
73 for(int i=1; i<= s.length(); ++i){
74 if(!first)os << ", ";
75 else first=false;
76 os << T(s[i]);
77 }
78 os << "]";
79 }
80
81 template<>
82 const long ASCXX_Set<long>::operator[](const unsigned long &i) const;
83
84 template<>
85 const SymChar ASCXX_Set<SymChar>::operator[](const unsigned long &i) const;
86
87 template<>
88 const Empty ASCXX_Set<Empty>::operator[](const unsigned long &i) const;
89
90 #endif

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22