aboutsummaryrefslogtreecommitdiff
path: root/common/const-member/test.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-19 10:47:41 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-21 20:05:46 +0200
commitbceb06251cdb572850b2e6e4d15cfb2ac32da417 (patch)
tree2e6af635da493c51d5f19b81e2a5506db90353ca /common/const-member/test.hxx
parent2d10422daab4b63307f3c1d9a6c08ee2c1b7c72e (diff)
Add support for const data members
Const data members are automatically treated as readonly. New test: const-member.
Diffstat (limited to 'common/const-member/test.hxx')
-rw-r--r--common/const-member/test.hxx111
1 files changed, 111 insertions, 0 deletions
diff --git a/common/const-member/test.hxx b/common/const-member/test.hxx
new file mode 100644
index 0000000..c987cf8
--- /dev/null
+++ b/common/const-member/test.hxx
@@ -0,0 +1,111 @@
+// file : common/const-member/test.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <vector>
+#include <string>
+#include <memory> // std::auto_ptr
+
+#include <odb/core.hxx>
+
+// Const ids.
+//
+#pragma db object
+struct const_id
+{
+ const_id (unsigned long i): id (i) {}
+ const_id (): id (0) {}
+
+ #pragma db id
+ const unsigned long id;
+};
+
+#pragma db object
+struct const_auto_id
+{
+ const_auto_id (): id (0) {}
+
+ #pragma db id auto
+ const unsigned long id;
+};
+
+// Container.
+//
+#pragma db value
+struct container_value
+{
+ container_value (unsigned long x)
+ {
+ vec.push_back (x);
+ const_cast<std::vector<unsigned long>&> (cvec).push_back (x);
+ }
+
+ container_value () {}
+
+ std::vector<unsigned long> vec;
+ const std::vector<unsigned long> cvec;
+};
+
+#pragma db object
+struct container
+{
+ container (unsigned long i, unsigned long x)
+ : id (i), ccom (x)
+ {
+ const_cast<std::vector<unsigned long>&> (cvec).push_back (x);
+ }
+
+ container () {}
+
+ #pragma db id
+ unsigned long id;
+
+ const container_value ccom;
+ const std::vector<unsigned long> cvec;
+};
+
+// Wrapper.
+//
+#pragma db value
+struct wrapped_value
+{
+ wrapped_value (const std::string& s, unsigned long n)
+ : str (s), num (n)
+ {
+ vec.push_back (n);
+ }
+
+ wrapped_value () {}
+
+ const std::string str;
+ unsigned long num;
+ std::vector<unsigned long> vec;
+};
+
+#pragma db object
+struct wrapper
+{
+ wrapper (unsigned long i, const std::string& s, unsigned long n)
+ : id (i),
+ str (new std::string (s)),
+ com (new wrapped_value (s, n)),
+ vec (new std::vector<unsigned long>)
+ {
+ const_cast<std::vector<unsigned long>&> (*vec).push_back (n);
+ }
+
+ wrapper () {}
+
+ #pragma db id
+ unsigned long id;
+
+ const std::auto_ptr<const std::string> str;
+ const std::auto_ptr<const wrapped_value> com;
+ const std::auto_ptr< const std::vector<unsigned long> > vec;
+};
+
+#endif // TEST_HXX