summaryrefslogtreecommitdiff
path: root/legacy/eobj
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2012-08-23 10:35:14 +0000
committerTom Hacohen <tom@stosb.com>2012-08-23 10:35:14 +0000
commit410488aabeed583ff96a648ed1de2a207d0cf49e (patch)
tree26c1905dcdc7bc5d78196ef68897aaebacfdc14e /legacy/eobj
parentad096efc9308bfd40f32e0a65a57d3ec9589b261 (diff)
Eo: Added eo_add_custom and support for passing ops to eo_add.
We can no do things like eo_add(CLASS, parent, age_set(7), score_set(100)), or pass different constructors to object creation by using eo_add_custom and passing the constructor. SVN revision: 75614
Diffstat (limited to 'legacy/eobj')
-rw-r--r--legacy/eobj/src/lib/Eo.h36
-rw-r--r--legacy/eobj/src/lib/eo.c36
-rw-r--r--legacy/eobj/src/tests/eo_suite/eo_test_general.c27
3 files changed, 89 insertions, 10 deletions
diff --git a/legacy/eobj/src/lib/Eo.h b/legacy/eobj/src/lib/Eo.h
index f9de616b2d..b6e10f3c36 100644
--- a/legacy/eobj/src/lib/Eo.h
+++ b/legacy/eobj/src/lib/Eo.h
@@ -553,12 +553,46 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line);
553/* @endcond */ 553/* @endcond */
554 554
555/** 555/**
556 * @def eo_add
557 * @brief Create a new object with the default constructor.
558 * @param klass the class of the object to create.
559 * @param parent the parent to set to the object.
560 * @param ... The ops to run.
561 * @return An handle to the new object on success, NULL otherwise.
562 */
563#define eo_add(klass, parent, ...) \
564 ({ \
565 (void) klass; \
566 eo_add_internal(klass, parent, eo_constructor(), ## __VA_ARGS__, EO_NOOP); \
567 })
568
569/**
570 * @def eo_add_custom
571 * @brief Create a new object with a custom constructor.
572 * @param klass the class of the object to create.
573 * @param parent the parent to set to the object.
574 * @param ... The ops to run. With the constructor being first.
575 * @return An handle to the new object on success, NULL otherwise.
576 */
577#define eo_add_custom(klass, parent, ...) \
578 ({ \
579 (void) klass; \
580 eo_add_internal(klass, parent, ## __VA_ARGS__, EO_NOOP); \
581 })
582
583/**
556 * @brief Create a new object. 584 * @brief Create a new object.
557 * @param klass the class of the object to create. 585 * @param klass the class of the object to create.
558 * @param parent the parent to set to the object. 586 * @param parent the parent to set to the object.
587 * @param ... The ops to run. With the constructor being first.
559 * @return An handle to the new object on success, NULL otherwise. 588 * @return An handle to the new object on success, NULL otherwise.
589 *
590 * Use the helper macros, don't pass the parameters manually.
591 * Use #eo_add or #eo_add_custom instead of this function.
592 *
593 * @see #eo_add
560 */ 594 */
561EAPI Eo *eo_add(const Eo_Class *klass, Eo *parent); 595EAPI Eo *eo_add_internal(const Eo_Class *klass, Eo *parent, ...);
562 596
563/** 597/**
564 * @brief Get the parent of an object 598 * @brief Get the parent of an object
diff --git a/legacy/eobj/src/lib/eo.c b/legacy/eobj/src/lib/eo.c
index 7d8f07f096..4d2a2f27d3 100644
--- a/legacy/eobj/src/lib/eo.c
+++ b/legacy/eobj/src/lib/eo.c
@@ -378,22 +378,19 @@ _eo_op_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, va_list *p_list)
378 return EINA_FALSE; 378 return EINA_FALSE;
379} 379}
380 380
381EAPI Eina_Bool 381static inline Eina_Bool
382eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...) 382_eo_dov_internal(Eo *obj, Eo_Op_Type op_type, va_list p_list)
383{ 383{
384 Eina_Bool prev_error; 384 Eina_Bool prev_error;
385 Eina_Bool ret = EINA_TRUE; 385 Eina_Bool ret = EINA_TRUE;
386 Eo_Op op = EO_NOOP; 386 Eo_Op op = EO_NOOP;
387 Eo_Kls_Itr prev_state; 387 Eo_Kls_Itr prev_state;
388 va_list p_list;
389 388
390 EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE); 389 EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
391 390
392 prev_error = obj->do_error; 391 prev_error = obj->do_error;
393 _eo_ref(obj); 392 _eo_ref(obj);
394 393
395 va_start(p_list, op_type);
396
397 op = va_arg(p_list, Eo_Op); 394 op = va_arg(p_list, Eo_Op);
398 while (op) 395 while (op)
399 { 396 {
@@ -409,8 +406,6 @@ eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...)
409 _eo_kls_itr_end(&obj->mro_itr, &prev_state); 406 _eo_kls_itr_end(&obj->mro_itr, &prev_state);
410 } 407 }
411 408
412 va_end(p_list);
413
414 _eo_unref(obj); 409 _eo_unref(obj);
415 410
416 if (obj->do_error) 411 if (obj->do_error)
@@ -422,6 +417,21 @@ eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...)
422} 417}
423 418
424EAPI Eina_Bool 419EAPI Eina_Bool
420eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...)
421{
422 Eina_Bool ret = EINA_TRUE;
423 va_list p_list;
424
425 va_start(p_list, op_type);
426
427 ret = _eo_dov_internal(obj, op_type, p_list);
428
429 va_end(p_list);
430
431 return ret;
432}
433
434EAPI Eina_Bool
425eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...) 435eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...)
426{ 436{
427 const Eo_Class *nklass; 437 const Eo_Class *nklass;
@@ -1095,7 +1105,7 @@ eo_parent_set(Eo *obj, const Eo *parent)
1095} 1105}
1096 1106
1097EAPI Eo * 1107EAPI Eo *
1098eo_add(const Eo_Class *klass, Eo *parent) 1108eo_add_internal(const Eo_Class *klass, Eo *parent, ...)
1099{ 1109{
1100 Eina_Bool do_err; 1110 Eina_Bool do_err;
1101 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL); 1111 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
@@ -1120,7 +1130,14 @@ eo_add(const Eo_Class *klass, Eo *parent)
1120 _eo_condtor_reset(obj); 1130 _eo_condtor_reset(obj);
1121 1131
1122 _eo_ref(obj); 1132 _eo_ref(obj);
1123 do_err = !eo_do(obj, eo_constructor()); 1133
1134 /* Run the relevant do stuff. */
1135 {
1136 va_list p_list;
1137 va_start(p_list, parent);
1138 do_err = !_eo_dov_internal(obj, EO_OP_TYPE_REGULAR, p_list);
1139 va_end(p_list);
1140 }
1124 1141
1125 if (EINA_UNLIKELY(do_err)) 1142 if (EINA_UNLIKELY(do_err))
1126 { 1143 {
@@ -1133,6 +1150,7 @@ eo_add(const Eo_Class *klass, Eo *parent)
1133 ERR("Object of class '%s' - Not all of the object constructors have been executed.", klass->desc->name); 1150 ERR("Object of class '%s' - Not all of the object constructors have been executed.", klass->desc->name);
1134 goto fail; 1151 goto fail;
1135 } 1152 }
1153
1136 _eo_unref(obj); 1154 _eo_unref(obj);
1137 1155
1138 return obj; 1156 return obj;
diff --git a/legacy/eobj/src/tests/eo_suite/eo_test_general.c b/legacy/eobj/src/tests/eo_suite/eo_test_general.c
index ac395d2b70..20ab4b5c29 100644
--- a/legacy/eobj/src/tests/eo_suite/eo_test_general.c
+++ b/legacy/eobj/src/tests/eo_suite/eo_test_general.c
@@ -695,6 +695,32 @@ START_TEST(eo_multiple_do)
695} 695}
696END_TEST 696END_TEST
697 697
698START_TEST(eo_add_do_and_custom)
699{
700 Simple_Public_Data *pd = NULL;
701 Eo *obj = NULL;
702 eo_init();
703
704 obj = eo_add_custom(SIMPLE_CLASS, NULL, eo_constructor());
705 fail_if(!obj);
706 eo_unref(obj);
707
708 obj = eo_add(SIMPLE_CLASS, NULL, simple_a_set(7));
709 fail_if(!obj);
710 pd = eo_data_get(obj, SIMPLE_CLASS);
711 fail_if(pd->a != 7);
712 eo_unref(obj);
713
714 obj = eo_add_custom(SIMPLE_CLASS, NULL, eo_constructor(), simple_a_set(7));
715 fail_if(!obj);
716 pd = eo_data_get(obj, SIMPLE_CLASS);
717 fail_if(pd->a != 7);
718 eo_unref(obj);
719
720 eo_shutdown();
721}
722END_TEST
723
698void eo_test_general(TCase *tc) 724void eo_test_general(TCase *tc)
699{ 725{
700 tcase_add_test(tc, eo_generic_data); 726 tcase_add_test(tc, eo_generic_data);
@@ -708,4 +734,5 @@ void eo_test_general(TCase *tc)
708 tcase_add_test(tc, eo_composite_tests); 734 tcase_add_test(tc, eo_composite_tests);
709 tcase_add_test(tc, eo_isa_tests); 735 tcase_add_test(tc, eo_isa_tests);
710 tcase_add_test(tc, eo_multiple_do); 736 tcase_add_test(tc, eo_multiple_do);
737 tcase_add_test(tc, eo_add_do_and_custom);
711} 738}