/** Function oyStruct_ObserverCopyModel * @memberof oyObserver_s * @brief copy a models observers to a different model * * The observers are copied from pattern with object type to a model with the * same object type. * * @param[in,out] model the model * @param[in] pattern the pattern to copy from * @param[in] flags 0x01 omit observer idendity check * @return 0 - good; >= 1 - error; < 0 issue * * @version Oyranos: 0.1.10 * @since 2009/11/02 (Oyranos: 0.1.10) * @date 2009/11/02 */ OYAPI int OYEXPORT oyStruct_ObserverCopyModel( oyStruct_s * model, oyStruct_s * pattern, uint32_t flags ) { oyObserver_s * obs = 0; int error = !model; oyStructList_s * observers = 0; int n,i; if( !model || !pattern ) return 0; observers = oyStruct_ObserverListGet_( pattern, OY_SIGNAL_OBSERVERS ); if(!error) { n = oyStructList_Count( observers ); for(i = 0; i < n; ++i) { obs = (oyObserver_s*) oyStructList_GetType( observers, i, oyOBJECT_OBSERVER_S ); if(obs && (!(flags & 0x01) || obs->model == pattern)) { if(oy_debug_signals) { WARNc5_S( "\n\tCopy %s: %s[%d]->%s[%d]", _("Signal"), oyStruct_GetText( obs->model, oyNAME_NAME, 1), oyObject_GetId( obs->model->oy_), oyStruct_GetText( obs->observer, oyNAME_NAME, 1), oyObject_GetId( obs->observer->oy_) ); } error = oyStruct_ObserverAdd( (oyStruct_s*)model, obs->observer, obs->user_data, obs->signal ); } else { if(obs) { WARNc5_S( "\n\tCopy: %s: %s[%d]->%s[%d]", _("found observer of wrong type"), oyStruct_GetText( obs->model, oyNAME_NAME, 1), oyObject_GetId( obs->model->oy_), oyStruct_GetText( obs->observer, oyNAME_NAME, 1), oyObject_GetId( obs->observer->oy_) ); } else { WARNc2_S( "\n\toyObservers_s %s ",_("found no observer"), oyStruct_TypeToText((oyStruct_s*)observers) ); } } } } return error; }
/** Function oyFilterNode_GetId * @memberof oyFilterNode_s * @brief Get the object Id * * @param[in] node filter node * @return the object Id * * @version Oyranos: 0.1.10 * @since 2009/02/25 (Oyranos: 0.1.10) * @date 2009/02/25 */ OYAPI int OYEXPORT oyFilterNode_GetId ( oyFilterNode_s * node ) { oyFilterNode_s * s = node; oyCheckType__m( oyOBJECT_FILTER_NODE_S, return -1 ) return oyObject_GetId( node->oy_ ); }
/** Function oyStruct_EnableSignalSend * @memberof oyObserver_s * @brief reenable sending a signal to all ovservers of a model * * @param[in] model the model * @return 0 - no handler found; 1 - error * < 0 error or issue * * @version Oyranos: 0.1.10 * @since 2010/04/07 (Oyranos: 0.1.10) * @date 2010/04/07 */ OYAPI int OYEXPORT oyStruct_EnableSignalSend ( oyStruct_s * model ) { oyObserver_s * obs = 0; int error = !model; oyOption_s * o = 0; oyStructList_s * observers = 0; int n,i; if(!error) o = oyOptions_Find( model->oy_->handles_, OY_SIGNAL_OBSERVERS, oyNAME_REGISTRATION ); if(!o) return 0; if(!error) { observers = (oyStructList_s*)oyOption_GetStruct( o, oyOBJECT_STRUCT_LIST_S ); n = oyStructList_Count( observers ); for(i = 0; i < n; ++i) { obs = (oyObserver_s*) oyStructList_GetType( observers, i, oyOBJECT_OBSERVER_S ); if(obs) --obs->disable_ref; if(obs && obs->disable_ref < 0) { oyOption_s_ * o_ = (oyOption_s_*)o; obs->disable_ref = 0; WARNcc3_S( model, "%s: %s[%d]", _("Already enabled"), oyStruct_GetText( (oyStruct_s*)obs, oyNAME_NAME, 1), oyObject_GetId( o_->value->oy_struct->oy_ ) ); } } } return error; }
/** Function oyFilterNode_SetContext_ * @memberof oyFilterNode_s * @brief Set module context in a filter * @internal * * The api4 data is passed to a interpolator specific transformer. The result * of this transformer will on request be cached by Oyranos as well. * * @param[in] node filter * @param[in,out] blob context to fill; expensive * @return error * * @version Oyranos: 0.9.6 * @date 2014/06/26 * @since 2008/11/02 (Oyranos: 0.1.8) */ int oyFilterNode_SetContext_( oyFilterNode_s_ * node, oyBlob_s_ * blob ) { int error = 0; oyFilterCore_s_ * core_ = node->core; if(error <= 0) { size_t size = 0; oyHash_s * hash4 = 0, /* public context provider */ * hash7 = 0; /* data processor part */ oyPointer ptr = 0; oyPointer_s * cmm_ptr4 = 0, * cmm_ptr7 = 0; /* Cache Search * 1. hash from input * 2. query for hash in cache * 3. check * 3a. eighter take cache entry * 3b. or ask CMM * 3b.1. update cache entry */ if(oy_debug && getenv("OY_DEBUG_WRITE")) { size = 0; ptr = oyFilterNode_TextToInfo_( node, &size, oyAllocateFunc_ ); if(ptr) oyWriteMemToFile_( "test_dbg_color.icc", ptr, size ); } /* 1. + 2. query in cache for api7 */ hash7 = oyFilterNode_GetHash_(node, 7); if(error <= 0) { /* select the module by option */ oyOption_s * ct = oyOptions_Find( node->core->options_, "////context", oyNAME_PATTERN ); const char * pattern = oyOption_GetValueString( ct, 0 ); if(pattern && !oyFilterRegistrationMatch( core_->registration_, pattern, 0 )) { oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*) node, OY_DBG_FORMAT_ "create core from pattern: %s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK) ); error = oyFilterNode_SetFromPattern_( node, 1, pattern ); if(error) { if(oyOption_GetFlags( ct ) & oyOPTIONATTRIBUTE_EDIT) { oyMessageFunc_p( oyMSG_WARN, (oyStruct_s*) node, OY_DBG_FORMAT_ "edited pattern not available: %d %s", OY_DBG_ARGS_, oyObject_GetId(ct->oy_), pattern ); error = 1; goto clean; } else error = 0; } else core_ = node->core; oyHash_Release( &hash7 ); hash7 = oyFilterNode_GetHash_(node, 7); } oyOption_Release( &ct ); ct = oyOptions_Find( node->core->options_, "////renderer", oyNAME_PATTERN ); pattern = oyOption_GetValueString( ct, 0 ); if(pattern && !oyFilterRegistrationMatch( node->api7_->registration, pattern, 0 )) { oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*) node, OY_DBG_FORMAT_ "create node from pattern: %s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK) ); error = oyFilterNode_SetFromPattern_( node, 0, pattern ); if(error) { if(oyOption_GetFlags( ct ) & oyOPTIONATTRIBUTE_EDIT) { error = 1; goto clean; } else error = 0; } else core_ = node->core; oyHash_Release( &hash7 ); hash7 = oyFilterNode_GetHash_(node, 7); } /* 3. check and 3.a take*/ cmm_ptr7 = (oyPointer_s*) oyHash_GetPointer( hash7, oyOBJECT_POINTER_S); if(!(cmm_ptr7 && oyPointer_GetPointer(cmm_ptr7)) || blob) { /* write the cmm4 context to memory */ if(blob) { if(oy_debug) error = oyOptions_SetFromString( &node->tags, "////verbose", "true", OY_CREATE_NEW ); /* oy_debug is used to obtain a complete data set */ ptr = oyFilterNode_ContextToMem_( node, &size, oyAllocateFunc_); oyBlob_SetFromData( (oyBlob_s*)blob, ptr, size, core_->api4_->context_type ); if(oy_debug) error = oyOptions_SetFromString( &node->tags, "////verbose", "false", 0 ); goto clean; } /* 2. query in cache for api4 */ hash4 = oyFilterNode_GetHash_(node, 4); cmm_ptr4 = (oyPointer_s*) oyHash_GetPointer( hash4, oyOBJECT_POINTER_S); if(!cmm_ptr4) { cmm_ptr4 = oyPointer_New(0); } if(!oyPointer_GetPointer(cmm_ptr4)) { size = 0; /* 3b. ask CMM */ ptr = oyFilterNode_ContextToMem_( node, &size, oyAllocateFunc_); if(!ptr || !size) { oyOption_s * ct = oyOptions_Find( core_->options_, "////context", oyNAME_PATTERN ); oyMessageFunc_p( oyMSG_DBG, (oyStruct_s*) node, OY_DBG_FORMAT_ "device link creation failed", OY_DBG_ARGS_); if(!(oyOption_GetFlags( ct ) & oyOPTIONATTRIBUTE_EDIT)) { char * pattern = oyFilterNode_GetFallback_( node, 1 ); oyMessageFunc_p( oyMSG_WARN, (oyStruct_s*) node, OY_DBG_FORMAT_ "create core from fallback: %s", OY_DBG_ARGS_, pattern ); error = oyFilterNode_SetFromPattern_( node, 1, pattern ); if(error) { error = 1; oyMessageFunc_p( oyMSG_ERROR, (oyStruct_s*) node, OY_DBG_FORMAT_ "no device link for caching\n%s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK)); goto clean; } else core_ = node->core; ptr = oyFilterNode_ContextToMem_( node, &size, oyAllocateFunc_ ); oyFree_m_( pattern ); } if(!ptr || !size) { oyMessageFunc_p( oyMSG_ERROR, (oyStruct_s*) node, OY_DBG_FORMAT_ "no device link for caching\n%s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node,oyNAME_NICK)); error = 1; oyPointer_Release( &cmm_ptr4 ); } else if(oy_debug) oyMessageFunc_p( oyMSG_WARN, (oyStruct_s*) node, OY_DBG_FORMAT_ "use fallback CMM\n%s", OY_DBG_ARGS_, oyFilterNode_GetText( (oyFilterNode_s*)node, oyNAME_NICK )); } if(!error) { /* 3b.1. update the hash as the CMM can change options */ hash4 = oyFilterNode_GetHash_( node, 4 ); oyPointer_Release( &cmm_ptr4 ); cmm_ptr4 = (oyPointer_s*) oyHash_GetPointer( hash4, oyOBJECT_POINTER_S); hash7 = oyFilterNode_GetHash_( node, 7 ); if(!cmm_ptr4) cmm_ptr4 = oyPointer_New(0); error = oyPointer_Set( cmm_ptr4, core_->api4_->id_, core_->api4_->context_type, ptr, "oyPointerRelease", oyPointerRelease); oyPointer_SetSize( cmm_ptr4, size ); /* 3b.2. update cmm4 cache entry */ error = oyHash_SetPointer( hash4, (oyStruct_s*) cmm_ptr4); } } if(error <= 0 && cmm_ptr4 && oyPointer_GetPointer(cmm_ptr4)) { if(node->backend_data && node->backend_data->release) node->backend_data->release( (oyStruct_s**)&node->backend_data); if( oyStrcmp_( node->api7_->context_type, core_->api4_->context_type ) != 0 ) { cmm_ptr7 = oyPointer_New(0); error = oyPointer_Set( cmm_ptr7, node->api7_->id_, node->api7_->context_type, 0, 0, 0); /* 3b.3. search for a convertor and convert */ oyPointer_ConvertData( cmm_ptr4, cmm_ptr7, (oyFilterNode_s*)node ); node->backend_data = cmm_ptr7; /* 3b.4. update cmm7 cache entry */ error = oyHash_SetPointer( hash7, (oyStruct_s*) cmm_ptr7); } else node->backend_data = oyPointer_Copy( cmm_ptr4, 0 ); } if(oy_debug && getenv("OY_DEBUG_WRITE")) { int id = oyFilterNode_GetId( (oyFilterNode_s*)node ); char * file_name = 0; oyAllocHelper_m_( file_name, char, 80, 0, return 1 ); sprintf( file_name, "dbg_color_dl-node[%d].icc", id ); if(ptr && size && node->backend_data) oyWriteMemToFile_( file_name, ptr, size ); oyFree_m_(file_name); } } else
/** @internal * Function oyFilterGraph_New_ * @memberof oyFilterGraph_s_ * @brief allocate a new oyFilterGraph_s_ object * * @version Oyranos: * @since 2010/04/26 (Oyranos: 0.1.10) * @date 2010/04/26 */ oyFilterGraph_s_ * oyFilterGraph_New_ ( oyObject_s object ) { /* ---- start of common object constructor ----- */ oyOBJECT_e type = oyOBJECT_FILTER_GRAPH_S; int error = 0; oyObject_s s_obj = oyObject_NewFrom( object ); oyFilterGraph_s_ * s = 0; if(s_obj) s = (oyFilterGraph_s_*)s_obj->allocateFunc_(sizeof(oyFilterGraph_s_)); else { WARNc_S(_("MEM Error.")); return NULL; } if(!s) { if(s_obj) oyObject_Release( &s_obj ); WARNc_S(_("MEM Error.")); return NULL; } error = !memset( s, 0, sizeof(oyFilterGraph_s_) ); if(error) WARNc_S( "memset failed" ); memcpy( s, &type, sizeof(oyOBJECT_e) ); s->copy = (oyStruct_Copy_f) oyFilterGraph_Copy; s->release = (oyStruct_Release_f) oyFilterGraph_Release; s->oy_ = s_obj; /* ---- start of custom FilterGraph constructor ----- */ error += !oyObject_SetParent( s_obj, oyOBJECT_FILTER_GRAPH_S, (oyPointer)s ); /* ---- end of custom FilterGraph constructor ------- */ /* ---- end of common object constructor ------- */ if(error) WARNc_S( "oyObject_SetParent failed" ); /* ---- start of custom FilterGraph constructor ----- */ error += oyFilterGraph_Init__Members( s ); /* ---- end of custom FilterGraph constructor ------- */ if(!oy_filtergraph_init_) { oy_filtergraph_init_ = 1; oyStruct_RegisterStaticMessageFunc( type, oyFilterGraph_StaticMessageFunc_ ); } if(error) WARNc1_S("%d", error); if(oy_debug_objects >= 0) oyObject_GetId( s->oy_ ); return s; }
/** Function oyFilterNode_Create * @memberof oyFilterNode_s * @brief Initialise a new filter node object properly * * @param registration the processing filter @ref registration string * @param filter the context filter * @param object the optional object * * @version Oyranos: 0.9.6 * @date 2014/07/01 * @since 2008/07/30 (Oyranos: 0.1.8) */ oyFilterNode_s * oyFilterNode_Create(const char * registration, oyFilterCore_s * filter, oyObject_s object ) { oyFilterNode_s_ * s = 0; int error = 0; oyAlloc_f allocateFunc_ = 0; oyFilterCore_s_ * filter_ = (oyFilterCore_s_*)filter; if(!filter) return (oyFilterNode_s*) s; s = (oyFilterNode_s_*) oyFilterNode_New( object ); error = !s; if(error <= 0) { allocateFunc_ = s->oy_->allocateFunc_; s->core = (oyFilterCore_s_*)oyFilterCore_Copy( filter, object ); if(!s->core) { WARNc2_S("Could not copy filter: %s %s", filter_->registration_, filter_->category_) error = 1; } if(error <= 0) s->api7_ = (oyCMMapi7_s_*) oyCMMsGetFilterApi_( registration, oyOBJECT_CMM_API7_S ); if(error <= 0 && !s->api7_) { WARNc2_S("Could not obtain filter api7 for: %s %s", filter_->registration_, filter_->category_) error = 1; } if(s->api7_) { s->plugs_n_ = s->api7_->plugs_n + s->api7_->plugs_last_add; if(s->api7_->plugs_last_add) --s->plugs_n_; s->sockets_n_ = s->api7_->sockets_n + s->api7_->sockets_last_add; if(s->api7_->sockets_last_add) --s->sockets_n_; } if(s->core) { int count = oyFilterNode_EdgeCount( (oyFilterNode_s*) s, 0, 0 ); size_t len; if(count < 0) count = 0; len = sizeof(oyFilterSocket_s*) * (count + 1); s->sockets = allocateFunc_( len ); memset( s->sockets, 0, len ); len = sizeof(oyFilterSocket_s*) * (oyFilterNode_EdgeCount( (oyFilterNode_s*) s, 1, 0 ) + 1); len = len?len:sizeof(oyFilterSocket_s*); s->plugs = allocateFunc_( len ); memset( s->plugs, 0, len ); s->relatives_ = allocateFunc_( oyStrlen_(filter_->category_) + 24 ); oySprintf_( s->relatives_, "%d: %s", oyObject_GetId(s->oy_), s->core->category_); } } if(error) oyFilterNode_Release( (oyFilterNode_s**) &s ); return (oyFilterNode_s*) s; }
/** Function oyFilterNode_Connect * @memberof oyFilterNode_s * @brief Connect two nodes by a edge * * @param input the node to provide a socket * @param socket_nick name of socket * @param output the node providing a plug * @param plug_nick name of plug * @param flags unused * @return error * * @version Oyranos: 0.1.10 * @since 2009/02/26 (Oyranos: 0.1.10) * @date 2009/02/26 */ int oyFilterNode_Connect ( oyFilterNode_s * input, const char * socket_nick, oyFilterNode_s * output, const char * plug_nick, int flags OY_UNUSED ) { oyFilterNode_s_ * s = (oyFilterNode_s_*)input; int error = !s; oyFilterPlug_s * out_plug = 0; oyFilterSocket_s * output_socket = 0, * in_socket = 0; int pos, out_pos; oyCheckType__m( oyOBJECT_FILTER_NODE_S, return 1 ) s = (oyFilterNode_s_*)output; oyCheckType__m( oyOBJECT_FILTER_NODE_S, return 1 ) if(error <= 0) { if(error <= 0 && (!s->core || !s->core->api4_)) { WARNcc2_S( s, "%s: %s", _("attempt to add a incomplete filter"), s->relatives_ ); error = 1; } if(error <= 0 && !oyFilterNode_EdgeCount( input, 0, OY_FILTEREDGE_FREE )) { WARNcc2_S( input, "%s: %s", "input node has no free socket", oyFilterCore_GetName( (oyFilterCore_s*)oyFilterNodePriv_m(input)->core, oyNAME_NAME) ); error = 1; } if(error <= 0) { if(socket_nick) pos = oyFilterNode_GetConnectorPos( input, 0, socket_nick, 0, 0 ); else pos = 0; if(pos >= 0) in_socket = oyFilterNode_GetSocket( input, pos ); if(plug_nick) out_pos = oyFilterNode_GetConnectorPos( output, 1, plug_nick, 0, OY_FILTEREDGE_FREE ); else out_pos = 0; if(out_pos >= 0) out_plug = oyFilterNode_GetPlug( output, out_pos ); if(!out_plug) { WARNcc3_S( output, "\n %s: \"%s\" %s", "Could not find plug for filter", oyFilterCore_GetName( (oyFilterCore_s*)oyFilterNodePriv_m(output)->core, oyNAME_NAME), socket_nick ); error = 1; } if(error <= 0) { if(oyFilterNode_ConnectorMatch( input, pos, out_plug )) output_socket = oyFilterNode_GetSocket( output, 0 ); else { WARNcc3_S( input, "\n %s: %s -> %s", "Filter connectors do not match", oyFilterNodePriv_m(input)->relatives_, oyFilterNodePriv_m(output)->relatives_ ); error = 1; } } if(error <= 0 && output_socket && !oyFilterSocketPriv_m(output_socket)->data && in_socket && oyFilterSocketPriv_m(in_socket)->data) { oyFilterSocketPriv_m(output_socket)->data = oyFilterSocketPriv_m(in_socket)->data->copy( oyFilterSocketPriv_m(in_socket)->data, 0 ); if(oy_debug_objects >= 0) oyObjectDebugMessage_( oyFilterSocketPriv_m(output_socket)->data->oy_, __func__, oyStructTypeToText(oyFilterSocketPriv_m(output_socket)->data->type_) ); } if(error <= 0) { oyFilterPlug_s_ * out_plug_ = (oyFilterPlug_s_*) out_plug; oyFilterSocket_s_* in_socket_ = (oyFilterSocket_s_*)in_socket; error = oyFilterPlug_ConnectIntoSocket( &out_plug, &in_socket ); if(error <= 0) { oyFilterNode_Release( (oyFilterNode_s**) &out_plug_->node ); out_plug_->node = (oyFilterNode_s_*) oyFilterNode_Copy( output, NULL ); oyFilterNode_Release( (oyFilterNode_s**) &in_socket_->node ); in_socket_->node = (oyFilterNode_s_*) oyFilterNode_Copy( input, NULL ); } } } else WARNcc2_S( input, "%s: %d", _("?? Nothing to add ??"), oyObject_GetId(input->oy_)); } oyFilterSocket_Release( &output_socket ); return error; }
/** Function oyStruct_ObserverSignal * @memberof oyObserver_s * @brief send a signal to all ovservers of a model * * @param[in] model the model * @param[in] signal_type the basic signal type to emit * @param[in,out] signal_data the advanced signal information * @return 0 - no handler found; 1 - handler found; * < 0 error or issue * * @version Oyranos: 0.1.10 * @since 2009/10/27 (Oyranos: 0.1.10) * @date 2009/10/27 */ OYAPI int OYEXPORT oyStruct_ObserverSignal ( oyStruct_s * model, oySIGNAL_e signal_type, oyStruct_s * signal_data ) { oyObserver_s * obs = 0; int error = !model, t_err = 0; oyOption_s * o = 0; oyStructList_s * observers = 0; int n,i, result = 0; if(oyToSignalBlock_m( oyObserverGetFlags() )) return 0; if(!error) o = oyOptions_Find( model->oy_->handles_, OY_SIGNAL_OBSERVERS, oyNAME_REGISTRATION ); if(!o) return 0; if(!error) { observers = (oyStructList_s*)oyOption_GetStruct( o, oyOBJECT_STRUCT_LIST_S); n = oyStructList_Count( observers ); for(i = 0; i < n; ++i) { obs = (oyObserver_s*) oyStructList_GetType( observers, i, oyOBJECT_OBSERVER_S ); if(obs) { if(obs->model == model) { if(oy_debug_signals) { WARNc6_S( "\n\t%s %s: %s[%d]->%s[%d]", _("Signal"), oySignalToString(signal_type), oyStruct_GetText( obs->model, oyNAME_NAME, 1), oyObject_GetId( obs->model->oy_), oyStruct_GetText( obs->observer, oyNAME_NAME, 1), oyObject_GetId( obs->observer->oy_) ); } t_err = oyObserver_SignalSend( obs, signal_type, signal_data ); if(t_err) { DBG_NUM7_S( "oyObserver_SignalSend() returned %d\n\t%s %s: %s[%d]->%s[%d]", t_err, _("Signal"), oySignalToString(signal_type), oyStruct_GetText( obs->model, oyNAME_NAME, 1), oyObject_GetId( obs->model->oy_), oyStruct_GetText( obs->observer, oyNAME_NAME, 1), oyObject_GetId( obs->observer->oy_) ); } ++result; } else { WARNc6_S( "\n\t%s %s: %s[%d]->%s[%d]",_("found observer of wrong type"), oySignalToString(signal_type), oyStruct_GetText( obs->model, oyNAME_NAME, 1), oyObject_GetId( obs->model->oy_), oyStruct_GetText( obs->observer, oyNAME_NAME, 1), oyObject_GetId( obs->observer->oy_) ); } } else WARNc3_S( "\n\t%s: oyObservers_s[%s]",_("found no observer"), oySignalToString(signal_type), oyStruct_TypeToText((oyStruct_s*)observers) ); } } if(result) return result; return error; }
/** * @internal * Function oyOption_GetValueText_ * @memberof oyOption_s * @brief get value as a text dump * * @param obj the option * @param allocateFunc user allocator * @return the text * * @version Oyranos: 0.1.9 * @since 2008/12/05 (Oyranos: 0.1.9) * @date 2009/08/17 */ char * oyOption_GetValueText_( oyOption_s_ * obj, oyAlloc_f allocateFunc ) { int error = !obj; char * erg = 0; oyValue_u * v = 0; oyStructList_s * oy_struct_list = 0; char * text = 0; char * save_locale = 0; if(error <= 0) v = obj->value; if(!allocateFunc) allocateFunc = oyAllocateFunc_; error = !v; save_locale = oyStringCopy_( setlocale(LC_NUMERIC, 0 ), oyAllocateFunc_ ); setlocale(LC_NUMERIC, "C"); if(error <= 0) { int n = 1, i = 0; char * tmp = oyAllocateFunc_(1024); const char * ct = 0; switch(obj->value_type) { case oyVAL_INT_LIST: n = v->int32_list[0]; break; case oyVAL_DOUBLE_LIST: n = (int)v->dbl_list[0]; break; case oyVAL_STRING_LIST: n = 0; while( v->string_list[n] ) ++n; break; case oyVAL_INT: case oyVAL_DOUBLE: case oyVAL_STRING: case oyVAL_STRUCT: n = 1; break; case oyVAL_NONE: case oyVAL_MAX: n = 0; break; } if(obj->value_type == oyVAL_STRUCT) { oy_struct_list = (oyStructList_s*) v->oy_struct; if(oy_struct_list) { if(oy_struct_list->type_ == oyOBJECT_STRUCT_LIST_S) n = oyStructList_Count( oy_struct_list ); } else WARNc2_S( "missed \"oy_struct\" member of \"%s\" [%d]", obj->registration, oyObject_GetId(obj->oy_) ); } for(i = 0; i < n; ++i) { if(obj->value_type == oyVAL_INT) oySprintf_(tmp, "%d", v->int32); if(obj->value_type == oyVAL_DOUBLE) oySprintf_(tmp, "%g", v->dbl); if(obj->value_type == oyVAL_INT_LIST) oySprintf_(tmp, "%d", v->int32_list[i+1]); if(obj->value_type == oyVAL_DOUBLE_LIST) oySprintf_(tmp, "%g", v->dbl_list[i+1]); if((obj->value_type == oyVAL_INT_LIST || obj->value_type == oyVAL_DOUBLE_LIST) && i) STRING_ADD( text, "," ); switch(obj->value_type) { case oyVAL_INT: case oyVAL_DOUBLE: case oyVAL_INT_LIST: case oyVAL_DOUBLE_LIST: STRING_ADD( text, tmp ); break; case oyVAL_STRING: STRING_ADD( text, v->string ); break; case oyVAL_STRING_LIST: STRING_ADD( text, v->string_list[i] ); break; case oyVAL_STRUCT: case oyVAL_NONE: case oyVAL_MAX: break; } if(obj->value_type == oyVAL_STRUCT) { oyStruct_s * oy_struct = 0; if(oy_struct_list && oy_struct_list->type_ == oyOBJECT_STRUCT_LIST_S) oy_struct = oyStructList_Get_( ( oyStructList_s_*)oy_struct_list, i ); else if(v->oy_struct) oy_struct = v->oy_struct; if(oy_struct) { ct = 0; /* get explicite name */ if(oy_struct->oy_) ct = oyObject_GetName( oy_struct->oy_, oyNAME_NICK ); if(!ct) /* fall back to oyCMMapi9_s object type lookup */ ct = oyStruct_GetText( oy_struct, oyNAME_NICK, 0 ); if(ct) STRING_ADD( text, ct ); if(!ct) /* fall back to plain struct type name, if known */ STRING_ADD ( text, oyStructTypeToText(oy_struct->type_) ); } } } if(text) erg = oyStringCopy_( text, allocateFunc ); oyFree_m_( tmp ); if(!text) { DBG_NUM2_S( "missed value in \"%s\" [%d]", obj->registration, oyObject_GetId(obj->oy_) ); } else oyFree_m_( text ); } setlocale(LC_NUMERIC, save_locale); oyFree_m_( save_locale ); return erg; }
/** @internal * Function oyOption_New_ * @memberof oyOption_s_ * @brief allocate a new oyOption_s_ object * * @version Oyranos: * @since 2010/04/26 (Oyranos: 0.1.10) * @date 2010/04/26 */ oyOption_s_ * oyOption_New_ ( oyObject_s object ) { /* ---- start of common object constructor ----- */ oyOBJECT_e type = oyOBJECT_OPTION_S; int error = 0; oyObject_s s_obj = oyObject_NewFrom( object ); oyOption_s_ * s = 0; if(s_obj) s = (oyOption_s_*)s_obj->allocateFunc_(sizeof(oyOption_s_)); if(!s || !s_obj) { WARNc_S(_("MEM Error.")); return NULL; } error = !memset( s, 0, sizeof(oyOption_s_) ); if(error) WARNc_S( "memset failed" ); memcpy( s, &type, sizeof(oyOBJECT_e) ); s->copy = (oyStruct_Copy_f) oyOption_Copy; s->release = (oyStruct_Release_f) oyOption_Release; s->oy_ = s_obj; /* ---- start of custom Option constructor ----- */ error += !oyObject_SetParent( s_obj, oyOBJECT_OPTION_S, (oyPointer)s ); /* ---- end of custom Option constructor ------- */ /* ---- end of common object constructor ------- */ if(error) WARNc_S( "oyObject_SetParent failed" ); /* ---- start of custom Option constructor ----- */ error += oyOption_Init__Members( s ); /* ---- end of custom Option constructor ------- */ if(!oy_option_init_) { oy_option_init_ = 1; oyStruct_RegisterStaticMessageFunc( type, oyOption_StaticMessageFunc_ ); } if(error) WARNc1_S("%d", error); if(oy_debug) oyObject_GetId( s->oy_ ); return s; }