author | Michael Krelin <hacker@klever.net> | 2005-01-29 19:41:34 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-01-29 19:41:34 (UTC) |
commit | ee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e (patch) (unidiff) | |
tree | be8029ce4a68870d991651927a27df8ee9d89617 /include/konforka/basic_wrapper.h | |
parent | d851b00e16839d6ec14da3a5c442be62ca868bba (diff) | |
download | konforka-ee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e.zip konforka-ee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e.tar.gz konforka-ee7ac58694c16cdd922a6eeddbe1a2eba0da7b4e.tar.bz2 |
initial commit.0.0
Diffstat (limited to 'include/konforka/basic_wrapper.h') (more/less context) (show whitespace changes)
-rw-r--r-- | include/konforka/basic_wrapper.h | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/include/konforka/basic_wrapper.h b/include/konforka/basic_wrapper.h new file mode 100644 index 0000000..909f8b6 --- a/dev/null +++ b/include/konforka/basic_wrapper.h | |||
@@ -0,0 +1,118 @@ | |||
1 | #ifndef __KONFORKA_BASIC_WRAPPER_H | ||
2 | #define __KONFORKA_BASIC_WRAPPER_H | ||
3 | |||
4 | /** | ||
5 | * @file | ||
6 | * @brief The konforka::basic_wrapper class declaration. | ||
7 | */ | ||
8 | |||
9 | #include <konforka/exception.h> | ||
10 | |||
11 | namespace konforka { | ||
12 | |||
13 | /** | ||
14 | * @brief The basic wrapper class. | ||
15 | * | ||
16 | */ | ||
17 | template<typename T> | ||
18 | class basic_wrapper { | ||
19 | public: | ||
20 | /** | ||
21 | * The type of wrapped content. | ||
22 | */ | ||
23 | typedef T content_type; | ||
24 | |||
25 | /** | ||
26 | * The content wrapped into the instance. | ||
27 | */ | ||
28 | content_type opkele; | ||
29 | /** | ||
30 | * This boolean indicates whether the object has a content | ||
31 | * attached to it. | ||
32 | */ | ||
33 | bool bopkele; | ||
34 | |||
35 | /** | ||
36 | * Default constructors creates the object with no content | ||
37 | * associated with it. | ||
38 | */ | ||
39 | basic_wrapper() | ||
40 | : bopkele(false) { } | ||
41 | /** | ||
42 | * The constructor associates the content give with the object. | ||
43 | * @param o the content being attached to the object. | ||
44 | */ | ||
45 | basic_wrapper(content_type o) | ||
46 | : opkele(o), bopkele(true) { } | ||
47 | /** | ||
48 | * Virtual destructor doing nothing in this class. | ||
49 | */ | ||
50 | virtual ~basic_wrapper() { } | ||
51 | |||
52 | /** | ||
53 | * Attaches the given content to the object. | ||
54 | * @param o the content being attached to the object. | ||
55 | */ | ||
56 | void attach(content_type o) { | ||
57 | opkele = o; | ||
58 | bopkele = true; | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Test whether the object has content attached. | ||
63 | * @return naturally, returns true if yes. | ||
64 | */ | ||
65 | bool is() const { | ||
66 | return bopkele; | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | * Throws an exception in case the object lacks content | ||
71 | * attached. | ||
72 | */ | ||
73 | void ensure() const { | ||
74 | if(!is()) | ||
75 | throw konforka::exception(CODEPOINT,"no content attached"); | ||
76 | } | ||
77 | |||
78 | /** | ||
79 | * Get the content attached to the object. It would throw an | ||
80 | * exception if there is no content attached. | ||
81 | * @return reference to the content. | ||
82 | */ | ||
83 | virtual content_type& get_content() { | ||
84 | ensure(); | ||
85 | return opkele; | ||
86 | } | ||
87 | /** | ||
88 | * Get the content attached to the object. It would throw an | ||
89 | * exception if there is no content attached. | ||
90 | * @return const reference to the content. | ||
91 | */ | ||
92 | virtual const content_type& get_content() const { | ||
93 | ensure(); | ||
94 | return opkele; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * Casts the object to the reference to the content type, | ||
99 | * throwing an exception if there's no content associated with | ||
100 | * an object. | ||
101 | * @return reference to the content attached. | ||
102 | * @see get_content() | ||
103 | */ | ||
104 | operator const content_type&(void) const { return get_content(); } | ||
105 | /** | ||
106 | * Casts the object to the const reference to the content type, | ||
107 | * throwing an exception if there's no content associated with | ||
108 | * an object. | ||
109 | * @return reference to the content attached. | ||
110 | * @see get_content() | ||
111 | */ | ||
112 | operator content_type&(void) { return get_content(); } | ||
113 | }; | ||
114 | |||
115 | } | ||
116 | |||
117 | #endif /* __KONFORKA_BASIC_WRAPPER_H */ | ||
118 | /* vim:set ft=cpp: */ | ||