On Mon, Oct 30, 2017 at 5:07 AM, Amitesh Singh <[email protected]> wrote:
> +static Eina_Bool
> +_eina_value_type_tm_convert_to(const Eina_Value_Type *type, const
> Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
> +{
> + struct tm tmv = *(struct tm *)type_mem;
> + time_t t = mktime(&tmv);
> + struct timeval v = {t, 0};
> +
> + if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
> + convert == EINA_VALUE_TYPE_STRING)
> + {
> + const char *other_mem;
> + char buf[64];
> +
> + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tmv);
> + other_mem = buf; /* required due &buf == buf */
> + return eina_value_type_pset(convert, convert_mem, &other_mem);
> + }
> + else
> + return _eina_value_type_timeval_convert_to(type, convert, &v,
> convert_mem);
> +}
> +
> +static const Eina_Value_Type _EINA_VALUE_TYPE_TM = {
> + EINA_VALUE_TYPE_VERSION,
> + sizeof(struct tm),
> + "struct tm",
> + _eina_value_type_tm_setup,
> + _eina_value_type_tm_flush,
> + _eina_value_type_tm_copy,
> + _eina_value_type_tm_compare,
> + _eina_value_type_tm_convert_to,
> + NULL, //No convert from
why no string/stringshare convert to using strptime?
also, timeval conversion would be reasonable.
which reminds me: it's a good approach (although not required) to add
"back conversion" to these types... the logic will "convert a to b" if
not, then "convert b from a". So having both is always a good
approach.
> @@ -779,6 +793,7 @@ static inline int eina_value_compare(const Eina_Value *a,
> * @li EINA_VALUE_TYPE_TIMEVAL: struct timeval
> * @li EINA_VALUE_TYPE_BLOB: Eina_Value_Blob
> * @li EINA_VALUE_TYPE_STRUCT: Eina_Value_Struct
> + * @li EINA_VALUE_TYPE_TM: struct tm*
here it's not pointer, just the expanded struct.
logic is ease of use with "set", it's a "..." that maps to vset()
(va_args). For pointer set, it's pset(). get() and pget() are
basically the same.
think about printf (set) x scanf (get).
then review all other documentation you wrote, things that insert in
array/list/hash, etc... are like set().
--
Gustavo Sverzut Barbieri
--------------------------------------
Mobile: +55 (16) 99354-9890
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel