aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-25 11:47:35 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-25 11:47:35 +0000
commit12338888a100ed2f325a1c8fe541c22340445074 (patch)
tree086cf7526e223b4186378b2c2d7df0ffc81371ff
parent9475ac6d1780238036d8aec6b3ac6e782203f99e (diff)
downloadpaludis-12338888a100ed2f325a1c8fe541c22340445074.tar.gz
paludis-12338888a100ed2f325a1c8fe541c22340445074.tar.xz
Add set method
-rw-r--r--paludis/smart_record.hh.m415
-rw-r--r--paludis/smart_record_TEST.cc10
2 files changed, 22 insertions, 3 deletions
diff --git a/paludis/smart_record.hh.m4 b/paludis/smart_record.hh.m4
index 4ebb1c6..bca1ed8 100644
--- a/paludis/smart_record.hh.m4
+++ b/paludis/smart_record.hh.m4
@@ -20,7 +20,7 @@ dnl vim: set ft=cpp et sw=4 sts=4 :
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
-define(`max_record_size', `5')
+define(`max_record_size', `8')
define(`forloop', `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
define(`_forloop', `$4`'ifelse($1, `$3', , `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
#endif
@@ -196,6 +196,13 @@ forloop(`idx', `0', max_record_size, `
{
return r._v`'idx`';
}
+
+ static void
+ do_set(RecordBase<Tag_, key_count_> & r,
+ const typename GetRecordKeyType<Tag_, `'idx`'>::Type & v)
+ {
+ r._v`'idx`' = v;
+ }
};
')
#endif
@@ -442,6 +449,12 @@ forloop(`idy', `0', decr(idx), `
{
return RecordKeyGetter<Tag_, `'idx`', k_>::do_get(*this);
}
+
+ template <typename Tag_::Keys k_>
+ void set(const typename GetRecordKeyType<Tag_, k_>::Type & v)
+ {
+ return RecordKeyGetter<Tag_, `'idx`', k_>::do_set(*this, v);
+ }
};
template<typename Tag_>
diff --git a/paludis/smart_record_TEST.cc b/paludis/smart_record_TEST.cc
index 3c1e45f..4ae5c34 100644
--- a/paludis/smart_record_TEST.cc
+++ b/paludis/smart_record_TEST.cc
@@ -68,12 +68,12 @@ namespace test_cases
void run()
{
- Person p1("blah", "first", 10);
+ const Person p1("blah", "first", 10);
TEST_CHECK_EQUAL(p1.get<firstname>(), "blah");
TEST_CHECK_EQUAL(p1.get<surname>(), "first");
TEST_CHECK_EQUAL(p1.get<age>(), 10);
- Person p2("blah", "second", 6);
+ const Person p2("blah", "second", 6);
TEST_CHECK_EQUAL(p2.get<firstname>(), "blah");
TEST_CHECK_EQUAL(p2.get<surname>(), "second");
TEST_CHECK_EQUAL(p2.get<age>(), 6);
@@ -84,6 +84,12 @@ namespace test_cases
TEST_CHECK( (p1 != p2));
TEST_CHECK(!(p1 >= p2));
TEST_CHECK(!(p1 > p2));
+
+ Person p3("foo", "bar", 1);
+ TEST_CHECK_EQUAL(p3.get<age>(), 1);
+ p3.set<age>(2);
+ TEST_CHECK_EQUAL(p3.get<age>(), 2);
}
} test_simple_record;
}
+