DLNodeC * DLList_findByIndex(const DLListC * const self_p, const int index) { assert(index > -1); assert(self_p != NULL); int nodeIndex = 0; DLNodeC * node = self_p->head; nodeIndex = 1; while(nodeIndex <= index) { if (node != NULL) { node = node->next; } else { COM_ERROR("Loop to %d node of index %d reach end...", nodeIndex, index); node = NULL; break; } nodeIndex++; } if (node != NULL) { return node; } else { COM_ERROR("Can not find with index=%d...", index); return NULL; } }
// release mem value* Parser::get_value(const string opt) const { value *v = NULL; if(options.count(opt)) { map<string, option*>::const_iterator it = this->options.find(opt);//use return const_iterator option *p = it->second; if(p != NULL) { if(p->v == NULL) { p->v = new value; switch(p->dataType) { case BOOL: p->v->on = false; logger->log(DEBUG, "%s=<>false", it->first.c_str()); break; case STRING: p->v->str = NULL; logger->log(DEBUG, "%s<=>:%s", it->first.c_str(),p->v->str); //logger->log(INFO, "%s=>:%s", it->first.c_str(),p->v->str); break; default: COM_ERROR("type not supported..."); return NULL; } } v = p->v; } } else { COM_ERROR("%s does not exist for cmd:%s", opt.c_str(), this->cmd.c_str()); } return v; }
void sort_sort(const SortC * const self_p, NodeC * const node, const int length, const SortTypeU sortType) { switch (sortType) { case SELECT: sort_select(self_p, node, length); break; case BUBBLE: sort_bubble(self_p, node, length); break; default: COM_ERROR("Unknow sortType=%d", sortType); } }
SortC * sort_new(CompareFunP compareFun_p) { int i = 0; while(i < MAX_SORTS) { if (sort[i].isUsed == FALSE) { sort[i].compareFun_p = compareFun_p; sort[i].isUsed = TRUE; return &sort[i]; } i++; } COM_ERROR("NO ENOUGH SORT, MAX=%d", MAX_SORTS); return NULL; }
bool Parser::verif() const { logger->log(DEBUG, "verif starting"); bool ret = true; map<string, option*>::const_iterator it; option *p = NULL; for(it = this->options.begin(); it != this->options.end(); ++it) { p = it->second; //cout << "verif:" << p << "v:" << p->v << "mandatory:" << p->mandatory << endl; if(p == NULL || p->mandatory == true && p->v == NULL) { COM_ERROR("%s is mandatory, but not provided...", it->first.c_str()); ret = false; break; } } return ret; }
int tLuaCOM::call(lua_State* L, DISPID dispid, int invkind, FUNCDESC *pfuncdesc, tLuaObjList params) { tUtil::log_verbose("tLuaCOM.call", "about to call DISPID 0x%.8x", dispid); HRESULT hr = 0; unsigned int i = 0; UINT ArgErr = 0; // number of return values (required to interface with Lua) int num_retvals = 0; DISPPARAMS dispparams; VARIANTARG result; EXCEPINFO excepinfo; VariantInit(&result); // fills DISPPARAMS structure, converting lua arguments // to COM parameters typehandler->fillDispParams(L, dispparams, pfuncdesc, params, invkind); hr = pdisp->Invoke( dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT, invkind, &dispparams, &result, &excepinfo, &ArgErr); //hr = S_OK; if(SUCCEEDED(hr)) { try { // pushes first return value (if any) // if there is no type information, assumes that // all functions have return value if((pfuncdesc && pfuncdesc->elemdescFunc.tdesc.vt != VT_VOID) || !pfuncdesc) { // To ease programming, methods of untyped objects // always return values to Lua. If the COM method does // not return nothing, then LuaCOM pushes nil. // (This avoids confusion with out params) typehandler->com2lua(L, result); num_retvals++; } // pushes out values if(invkind & INVOKE_FUNC) num_retvals += typehandler->pushOutValues(L, dispparams, pfuncdesc); } catch(class tLuaCOMException& e) { UNUSED(e); typehandler->releaseVariants(&dispparams); VariantClear(&result); throw; } typehandler->releaseVariants(&dispparams); VariantClear(&result); return num_retvals; } else // Houve erro { // Limpa parametros typehandler->releaseVariants(&dispparams); if(hr == DISP_E_EXCEPTION) // excecoes { if(excepinfo.bstrDescription != NULL) COM_EXCEPTION(tUtil::bstr2string(excepinfo.bstrDescription)); else if(excepinfo.wCode != 0) COM_EXCEPTION(tUtil::GetErrorMessage(excepinfo.wCode)); else if(excepinfo.scode != 0) COM_EXCEPTION(tUtil::GetErrorMessage(excepinfo.scode)); else COM_EXCEPTION("Unknown exception"); } else // Erros comuns COM_ERROR(tUtil::GetErrorMessage(hr)); } }
bool Parser::parse(const int argc,char ** argv) { this->cmd = argv[0]; this->options[this->cmd] = NULL; reset_value(); for(int i = 1; i < argc; i++) { map<string, option*>::iterator it; option *p = NULL; for(it = this->options.begin(); it != this->options.end(); ++it) { // cout << "key:" << it->first << endl; if(it->first == argv[i]) { p = it->second; if(p->v != NULL) { continue; } value v; switch(p->dataType) { case BOOL: p->v = new value; p->v->on = true; logger->log(INFO, "%s=>true", it->first.c_str()); break; case STRING: p->v = new value; p->v->str = new char[strlen(argv[++i]) + 1]; strcpy(p->v->str, argv[i]); logger->log(INFO, "%s=>:%s", it->first.c_str(),p->v->str); break; default: COM_ERROR("type not supported..."); return false; } } } //option is not found if(NULL == p) { if(argv[i][0] == '-' || NULL != this->options[this->cmd]) { COM_ERROR("arg:%s is not exist in cmd %s", argv[i], this->cmd.c_str()); help(); return false; } else//asign input value { option * p = new option; if(p == NULL) { logger->log(DEBUG, "p is NULL"); } p->description = "input"; p->dataType = STRING; p->mandatory = true; p->v = new value; p->v->str = new char[strlen(argv[i]) + 1]; strcpy(p->v->str, argv[i]); this->options[this->cmd] = p; logger->log(INFO, "%s=>:%s", this->cmd.c_str(), p->v->str); } } } //http://blog.csdn.net/since20140504/article/details/38269283 if(verif() == false) { help(); return false; } value *v = this->get_value(this->cmd); return true; }