summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-08-23 18:28:06 -0300
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-08-23 18:32:13 -0300
commit103b1349167506f8c478612aa73fdc53d367e814 (patch)
tree57c74d8e716d45dbd37d98a26735bcbe2e06e235
parentf4b02d87d6601eaa524dd23f84313bc3069fc594 (diff)
eina_value_util: eina_value_X_get() helpers.
These helpers will validate the type prior to get its value, also enforcing the correct pointer is passed.
-rw-r--r--src/lib/eina/eina_inline_value_util.x306
1 files changed, 306 insertions, 0 deletions
diff --git a/src/lib/eina/eina_inline_value_util.x b/src/lib/eina/eina_inline_value_util.x
index 8a09f4cdea..3beca713fb 100644
--- a/src/lib/eina/eina_inline_value_util.x
+++ b/src/lib/eina/eina_inline_value_util.x
@@ -672,6 +672,312 @@ eina_value_error_init(Eina_Error err)
672} 672}
673 673
674/** 674/**
675 * @brief Check value type and get contents.
676 * @param v The value to check type and get contents.
677 * @param c Where to store the value contents.
678 * @return #EINA_TRUE if type matches and fetched contents,
679 * #EINA_FALSE on different type or failures.
680 * @since 1.21
681 */
682static inline Eina_Bool
683eina_value_uchar_get(const Eina_Value *v, unsigned char *c)
684{
685 EINA_SAFETY_ON_NULL_RETURN_VAL(c, EINA_FALSE);
686 *c = 0;
687 if (v && v->type == EINA_VALUE_TYPE_UCHAR)
688 return eina_value_get(v, c);
689 return EINA_FALSE;
690}
691
692/**
693 * @brief Check value type and get contents.
694 * @param v The value to check type and get contents.
695 * @param s Where to store the value contents.
696 * @return #EINA_TRUE if type matches and fetched contents,
697 * #EINA_FALSE on different type or failures.
698 * @since 1.21
699 */
700static inline Eina_Bool
701eina_value_ushort_get(const Eina_Value *v, unsigned short *s)
702{
703 EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
704 *s = 0;
705 if (v && v->type == EINA_VALUE_TYPE_USHORT)
706 return eina_value_get(v, s);
707 return EINA_FALSE;
708}
709
710/**
711 * @brief Check value type and get contents.
712 * @param v The value to check type and get contents.
713 * @param i Where to store the value contents.
714 * @return #EINA_TRUE if type matches and fetched contents,
715 * #EINA_FALSE on different type or failures.
716 * @since 1.21
717 */
718static inline Eina_Bool
719eina_value_uint_get(const Eina_Value *v, unsigned int *i)
720{
721 EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
722 *i = 0;
723 if (v && v->type == EINA_VALUE_TYPE_UINT)
724 return eina_value_get(v, i);
725 return EINA_FALSE;
726}
727
728/**
729 * @brief Check value type and get contents.
730 * @param v The value to check type and get contents.
731 * @param l Where to store the value contents.
732 * @return #EINA_TRUE if type matches and fetched contents,
733 * #EINA_FALSE on different type or failures.
734 * @since 1.21
735 */
736static inline Eina_Bool
737eina_value_ulong_get(const Eina_Value *v, unsigned long *l)
738{
739 EINA_SAFETY_ON_NULL_RETURN_VAL(l, EINA_FALSE);
740 *l = 0;
741 if (v && v->type == EINA_VALUE_TYPE_ULONG)
742 return eina_value_get(v, l);
743 return EINA_FALSE;
744}
745
746/**
747 * @brief Check value type and get contents.
748 * @param v The value to check type and get contents.
749 * @param i Where to store the value contents.
750 * @return #EINA_TRUE if type matches and fetched contents,
751 * #EINA_FALSE on different type or failures.
752 * @since 1.21
753 */
754static inline Eina_Bool
755eina_value_uint64_get(const Eina_Value *v, uint64_t *i)
756{
757 EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
758 *i = 0;
759 if (v && v->type == EINA_VALUE_TYPE_UINT64)
760 return eina_value_get(v, i);
761 return EINA_FALSE;
762}
763
764/**
765 * @brief Check value type and get contents.
766 * @param v The value to check type and get contents.
767 * @param c Where to store the value contents.
768 * @return #EINA_TRUE if type matches and fetched contents,
769 * #EINA_FALSE on different type or failures.
770 * @since 1.21
771 */
772static inline Eina_Bool
773eina_value_char_get(const Eina_Value *v, char *c)
774{
775 EINA_SAFETY_ON_NULL_RETURN_VAL(c, EINA_FALSE);
776 *c = 0;
777 if (v && v->type == EINA_VALUE_TYPE_CHAR)
778 return eina_value_get(v, c);
779 return EINA_FALSE;
780}
781
782/**
783 * @brief Check value type and get contents.
784 * @param v The value to check type and get contents.
785 * @param s Where to store the value contents.
786 * @return #EINA_TRUE if type matches and fetched contents,
787 * #EINA_FALSE on different type or failures.
788 * @since 1.21
789 */
790static inline Eina_Bool
791eina_value_short_get(const Eina_Value *v, short *s)
792{
793 EINA_SAFETY_ON_NULL_RETURN_VAL(s, EINA_FALSE);
794 *s = 0;
795 if (v && v->type == EINA_VALUE_TYPE_SHORT)
796 return eina_value_get(v, s);
797 return EINA_FALSE;
798}
799
800/**
801 * @brief Check value type and get contents.
802 * @param v The value to check type and get contents.
803 * @param i Where to store the value contents.
804 * @return #EINA_TRUE if type matches and fetched contents,
805 * #EINA_FALSE on different type or failures.
806 * @since 1.21
807 */
808static inline Eina_Bool
809eina_value_int_get(const Eina_Value *v, int *i)
810{
811 EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
812 *i = 0;
813 if (v && v->type == EINA_VALUE_TYPE_INT)
814 return eina_value_get(v, i);
815 return EINA_FALSE;
816}
817
818/**
819 * @brief Check value type and get contents.
820 * @param v The value to check type and get contents.
821 * @param l Where to store the value contents.
822 * @return #EINA_TRUE if type matches and fetched contents,
823 * #EINA_FALSE on different type or failures.
824 * @since 1.21
825 */
826static inline Eina_Bool
827eina_value_long_get(const Eina_Value *v, long *l)
828{
829 EINA_SAFETY_ON_NULL_RETURN_VAL(l, EINA_FALSE);
830 *l = 0;
831 if (v && v->type == EINA_VALUE_TYPE_LONG)
832 return eina_value_get(v, l);
833 return EINA_FALSE;
834}
835
836/**
837 * @brief Check value type and get contents.
838 * @param v The value to check type and get contents.
839 * @param i Where to store the value contents.
840 * @return #EINA_TRUE if type matches and fetched contents,
841 * #EINA_FALSE on different type or failures.
842 * @since 1.21
843 */
844static inline Eina_Bool
845eina_value_int64_get(const Eina_Value *v, int64_t *i)
846{
847 EINA_SAFETY_ON_NULL_RETURN_VAL(i, EINA_FALSE);
848 *i = 0;
849 if (v && v->type == EINA_VALUE_TYPE_INT64)
850 return eina_value_get(v, i);
851 return EINA_FALSE;
852}
853
854/**
855 * @brief Check value type and get contents.
856 * @param v The value to check type and get contents.
857 * @param f Where to store the value contents.
858 * @return #EINA_TRUE if type matches and fetched contents,
859 * #EINA_FALSE on different type or failures.
860 * @since 1.21
861 */
862static inline Eina_Bool
863eina_value_float_get(const Eina_Value *v, float *f)
864{
865 EINA_SAFETY_ON_NULL_RETURN_VAL(f, EINA_FALSE);
866 *f = 0.0f;
867 if (v && v->type == EINA_VALUE_TYPE_FLOAT)
868 return eina_value_get(v, f);
869 return EINA_FALSE;
870}
871
872/**
873 * @brief Check value type and get contents.
874 * @param v The value to check type and get contents.
875 * @param d Where to store the value contents.
876 * @return #EINA_TRUE if type matches and fetched contents,
877 * #EINA_FALSE on different type or failures.
878 * @since 1.21
879 */
880static inline Eina_Bool
881eina_value_double_get(const Eina_Value *v, double *d)
882{
883 EINA_SAFETY_ON_NULL_RETURN_VAL(d, EINA_FALSE);
884 *d = 0.0;
885 if (v && v->type == EINA_VALUE_TYPE_DOUBLE)
886 return eina_value_get(v, d);
887 return EINA_FALSE;
888}
889
890/**
891 * @brief Check value type and get contents.
892 * @param v The value to check type and get contents.
893 * @param b Where to store the value contents.
894 * @return #EINA_TRUE if type matches and fetched contents,
895 * #EINA_FALSE on different type or failures.
896 * @since 1.21
897 */
898static inline Eina_Bool
899eina_value_bool_get(const Eina_Value *v, Eina_Bool *b)
900{
901 EINA_SAFETY_ON_NULL_RETURN_VAL(b, EINA_FALSE);
902 *b = EINA_FALSE;
903 if (v && v->type == EINA_VALUE_TYPE_UCHAR)
904 return eina_value_get(v, b);
905 return EINA_FALSE;
906}
907
908/**
909 * @brief Check value type and get contents.
910 * @param v The value to check type and get contents.
911 * @param str Where to store the value contents.
912 * @return #EINA_TRUE if type matches and fetched contents,
913 * #EINA_FALSE on different type or failures.
914 * @since 1.21
915 */
916static inline Eina_Bool
917eina_value_string_get(const Eina_Value *v, const char **str)
918{
919 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
920 *str = NULL;
921 if (v && v->type == EINA_VALUE_TYPE_STRING)
922 return eina_value_get(v, str);
923 return EINA_FALSE;
924}
925
926/**
927 * @brief Check value type and get contents.
928 * @param v The value to check type and get contents.
929 * @param str Where to store the value contents.
930 * @return #EINA_TRUE if type matches and fetched contents,
931 * #EINA_FALSE on different type or failures.
932 * @since 1.21
933 */
934static inline Eina_Bool
935eina_value_stringshare_get(const Eina_Value *v, const char **str)
936{
937 EINA_SAFETY_ON_NULL_RETURN_VAL(str, EINA_FALSE);
938 *str = NULL;
939 if (v && v->type == EINA_VALUE_TYPE_STRINGSHARE)
940 return eina_value_get(v, str);
941 return EINA_FALSE;
942}
943
944/**
945 * @brief Check value type and get contents.
946 * @param v The value to check type and get contents.
947 * @param t Where to store the value contents.
948 * @return #EINA_TRUE if type matches and fetched contents,
949 * #EINA_FALSE on different type or failures.
950 * @since 1.21
951 */
952static inline Eina_Bool
953eina_value_time_get(const Eina_Value *v, time_t *t)
954{
955 EINA_SAFETY_ON_NULL_RETURN_VAL(t, EINA_FALSE);
956 *t = 0;
957 if (v && v->type == EINA_VALUE_TYPE_TIMESTAMP)
958 return eina_value_get(v, t);
959 return EINA_FALSE;
960}
961
962/**
963 * @brief Check value type and get contents.
964 * @param v The value to check type and get contents.
965 * @param err Where to store the value contents.
966 * @return #EINA_TRUE if type matches and fetched contents,
967 * #EINA_FALSE on different type or failures.
968 * @since 1.21
969 */
970static inline Eina_Bool
971eina_value_error_get(const Eina_Value *v, Eina_Error *err)
972{
973 EINA_SAFETY_ON_NULL_RETURN_VAL(err, EINA_FALSE);
974 *err = 0;
975 if (v && v->type == EINA_VALUE_TYPE_ERROR)
976 return eina_value_get(v, err);
977 return EINA_FALSE;
978}
979
980/**
675 * @brief Create a new #Eina_Value containing the passed parameter 981 * @brief Create a new #Eina_Value containing the passed parameter
676 * @param val The value to use 982 * @param val The value to use
677 * @return The #Eina_Value 983 * @return The #Eina_Value