DataItem* ComponentInterface:: dataitem( const std::string &aname) throw(COM_exception) { if ( !DataItem::is_digit(aname[0])) { Attr_map::iterator it = _attr_map.find( aname); if ( it == _attr_map.end()) return NULL; else return it->second; } else { std::string::size_type start = aname.find( '-'); if ( start == aname.npos) throw COM_exception( COM_ERR_INVALID_DATAITEM_NAME, append_frame (_name+"."+aname,ComponentInterface::dataitem)); Attr_map::iterator it = _attr_map.find( &aname[start+1]); if ( it != _attr_map.end()) { DataItem *att = it->second; if ( att->size_of_components()>1) { // Get the subcomponent int i = std::atoi( aname.c_str()); if ( i<=0 || i>att->size_of_components()) throw COM_exception( COM_ERR_INVALID_DATAITEM_NAME, append_frame (_name+"."+aname,ComponentInterface::dataitem)); return dataitem( att->id()+i); } } return NULL; } }
void ComponentInterface::set_size( const std::string &aname, int pid, int nitems, int ng) throw( COM_exception) { if ( Connectivity::is_element_name( aname)) { Pane_friend &pn = (Pane_friend&)pane(pid,true); Connectivity *con = pn.connectivity( aname,true); pn.set_size( con, nitems, ng); } else { DataItem *a = dataitem(aname); if ( a == NULL) throw COM_exception( COM_ERR_DATAITEM_NOTEXIST,append_frame (_name+"."+aname,ComponentInterface::set_size)); if ( a->is_windowed()) ((Pane_friend&)_dummy).set_size( a, nitems, ng); else if ( pid==0) { // Loop through the panes to set the sizes. for (Pane_map::iterator it=_pane_map.begin(), iend=_pane_map.end(); it != iend; ++it) { ((Pane_friend*)it->second)->set_size ( it->second->dataitem( a->id()), nitems, ng); } } else ((Pane_friend&)pane(pid,true)).set_size( a, nitems, ng); } }
int tcKernel::simulate( double start, double end, double step, int max_iter ) { // find all output variables and add to results vector m_start = start; m_end = end; m_step = step; m_dataIndex = 0; if ( end <= start || step <= 0 ) return -77; int nsteps = (int)( (end-start)/step ) + 1; size_t ndatasets = 0; for (size_t i=0;i<m_units.size();i++) { tcsvarinfo *vars = m_units[i].type->variables; int idx=0; while( vars[idx].var_type != TCS_INVALID ) { if (is_ssc_array_output(vars[idx].name) || m_storeAllParameters) ndatasets++; idx++; } } if ( ndatasets < 1 ) return -88; m_results.resize( ndatasets ); size_t idataset = 0; for (size_t i=0;i<m_units.size();i++) { tcsvarinfo *vars = m_units[i].type->variables; int idx = 0; while( vars[idx].var_type != TCS_INVALID ) { if (is_ssc_array_output(vars[idx].name) || m_storeAllParameters ) { dataset &d = m_results[ idataset++ ]; char buf[32]; sprintf(buf, "%d", i); d.u = &m_units[i]; d.uidx = (int)i; d.idx = idx; d.group = "Unit " + std::string(buf) + " (" + std::string(m_units[i].type->name) + ")";//: " + m_units[i].name; d.name = vars[idx].name; d.units = vars[idx].units; d.type = vars[idx].data_type; d.values.resize( nsteps, dataitem(0.0) ); } idx++; } } tcskernel::set_max_iterations(max_iter, true); return tcskernel::simulate( start, end, step ); }
void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode) { int count = pCocoNode[13].GetChildNum(); int length = 0; int num = 0; int size = 0; int extent = 0; int border = 0; std::string key0; stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray(pCocoLoader); document.SetArray(); rapidjson::Document::AllocatorType& allocator = document.GetAllocator(); for (int i0 = 0; i0 < count; ++i0) { rapidjson::Value vElemItem(rapidjson::kObjectType); border = pTriggersArray[i0].GetChildNum(); stExpCocoNode *pTriggerArray = pTriggersArray[i0].GetChildArray(pCocoLoader); for (int i1 = 0; i1 < border; ++i1) { std::string key1 = pTriggerArray[i1].GetName(pCocoLoader); const char *str1 = pTriggerArray[i1].GetValue(pCocoLoader); if (key1.compare("actions") == 0) { rapidjson::Value actionsItem(rapidjson::kArrayType); length = pTriggerArray[i1].GetChildNum(); stExpCocoNode *pActionsArray = pTriggerArray[i1].GetChildArray(pCocoLoader); for (int i2 = 0; i2 < length; ++i2) { rapidjson::Value action(rapidjson::kObjectType); num = pActionsArray[i2].GetChildNum(); stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray(pCocoLoader); for (int i3 = 0; i3 < num; ++i3) { std::string key2 = pActionArray[i3].GetName(pCocoLoader); const char *str2 = pActionArray[i3].GetValue(pCocoLoader); if (key2.compare("classname") == 0) { if (str2 != nullptr) { action.AddMember("classname", rapidjson::Value(str2,allocator), allocator); } } else if (key2.compare("dataitems") == 0) { rapidjson::Value dataitems(rapidjson::kArrayType); size = pActionArray[i3].GetChildNum(); stExpCocoNode *pDataItemsArray = pActionArray[i3].GetChildArray(pCocoLoader); for (int i4 = 0; i4 < size; ++i4) { rapidjson::Value dataitem(rapidjson::kObjectType); extent = pDataItemsArray[i4].GetChildNum(); stExpCocoNode *pDataItemArray = pDataItemsArray[i4].GetChildArray(pCocoLoader); for (int i5 = 0; i5 < extent; ++i5) { std::string key3 = pDataItemArray[i5].GetName(pCocoLoader); const char *str3 = pDataItemArray[i5].GetValue(pCocoLoader); if (key3.compare("key") == 0) { if (str3 != nullptr) { dataitem.AddMember("key", rapidjson::Value(str3,allocator), allocator); } } else { rapidjson::Type type = pDataItemArray[i5].GetType(pCocoLoader); if (type == rapidjson::kStringType) { dataitem.AddMember("value", rapidjson::Value(str3,allocator), allocator); } else { int nV = atoi(str3); float fV = utils::atof(str3); if (fabs(nV - fV) < 0.0000001) { dataitem.AddMember("value", nV, allocator); } else { dataitem.AddMember("value", fV, allocator); } } } } dataitems.PushBack(dataitem, allocator); } action.AddMember("dataitems", dataitems, allocator); } } actionsItem.PushBack(action, allocator); } vElemItem.AddMember("actions", actionsItem, allocator); } else if (key1.compare("conditions") == 0) { rapidjson::Value condsItem(rapidjson::kArrayType); length = pTriggerArray[i1].GetChildNum(); stExpCocoNode *pConditionsArray = pTriggerArray[i1].GetChildArray(pCocoLoader); for (int i6 = 0; i6 < length; ++i6) { rapidjson::Value cond(rapidjson::kObjectType); num = pConditionsArray[i6].GetChildNum(); stExpCocoNode *pConditionArray = pConditionsArray[i6].GetChildArray(pCocoLoader); for (int i7 = 0; i7 < num; ++i7) { std::string key4 = pConditionArray[i7].GetName(pCocoLoader); const char *str4 = pConditionArray[i7].GetValue(pCocoLoader); if (key4.compare("classname") == 0) { if (str4 != nullptr) { cond.AddMember("classname", rapidjson::Value(str4,allocator), allocator); } } else if (key4.compare("dataitems") == 0) { rapidjson::Value dataitems(rapidjson::kArrayType); size = pConditionArray[i7].GetChildNum(); stExpCocoNode *pDataItemsArray = pConditionArray[i7].GetChildArray(pCocoLoader); for (int i8 = 0; i8 < size; ++i8) { rapidjson::Value dataitem(rapidjson::kObjectType); extent = pDataItemsArray[i8].GetChildNum(); stExpCocoNode *pDataItemArray = pDataItemsArray[i8].GetChildArray(pCocoLoader); for (int i9 = 0; i9 < extent; ++i9) { std::string key5 = pDataItemArray[i9].GetName(pCocoLoader); const char *str5 = pDataItemArray[i9].GetValue(pCocoLoader); if (key5.compare("key") == 0) { if (str5 != nullptr) { dataitem.AddMember("key", rapidjson::Value(str5,allocator), allocator); } } else { rapidjson::Type type = pDataItemArray[i9].GetType(pCocoLoader); if (type == rapidjson::kStringType) { dataitem.AddMember("value", rapidjson::Value(str5,allocator), allocator); } else { int nV = atoi(str5); float fV = utils::atof(str5); if (fabs(nV - fV) < 0.0000001) { dataitem.AddMember("value", nV, allocator); } else { dataitem.AddMember("value", fV, allocator); } } } } dataitems.PushBack(dataitem, allocator); } cond.AddMember("dataitems", dataitems, allocator); } } condsItem.PushBack(cond, allocator); } vElemItem.AddMember("conditions", condsItem, allocator); } else if (key1.compare("events") == 0) { rapidjson::Value eventsItem(rapidjson::kArrayType); length = pTriggerArray[i1].GetChildNum(); stExpCocoNode *pEventsArray = pTriggerArray[i1].GetChildArray(pCocoLoader); for (int i10 = 0; i10 < length; ++i10) { rapidjson::Value event(rapidjson::kObjectType); stExpCocoNode *pEventArray = pEventsArray->GetChildArray(pCocoLoader); std::string key6 = pEventArray[0].GetName(pCocoLoader); const char *str6 = pEventArray[0].GetValue(pCocoLoader); if (key6.compare("id") == 0 && str6 != nullptr) { event.AddMember("id", atoi(str6), allocator); eventsItem.PushBack(event, allocator); } } vElemItem.AddMember("events", eventsItem, allocator); } else if (key1.compare("id") == 0) { if (str1 != nullptr) { vElemItem.AddMember("id", atoi(str1), allocator); } } } document.PushBack(vElemItem, allocator); } }