bool IndexEncoding::SolveOptimizedAdv3Once( const Vector<double> &vec_x_map, const SMatrix<double> &matPrecomputed, int num_dic_each_partition, short* prepresentation) const { int num_sub_centers = matPrecomputed.Rows() / num_dic_each_partition; bool is_changed = false; int idx_start_center = 0; for (int idx_sub_cluster = 0; idx_sub_cluster < num_dic_each_partition; idx_sub_cluster++) { int idx_end_center = idx_start_center + num_sub_centers; double best_value = DBL_MAX; short best_idx = -1; for (int idx_center = idx_start_center; idx_center < idx_end_center; idx_center++) { double s = 0; for (int idx_sub_cluster2 = 0; idx_sub_cluster2 < num_dic_each_partition; idx_sub_cluster2++) { if (idx_sub_cluster == idx_sub_cluster2) { s += matPrecomputed[idx_center][idx_center]; } else { int curr_idx = prepresentation[idx_sub_cluster2]; if (curr_idx != -1) { s += matPrecomputed[idx_center][curr_idx]; } } } s -= vec_x_map[idx_center]; if (s < best_value) { best_value = s; best_idx = idx_center; } } SMART_ASSERT(best_idx != -1).Exit(); if (prepresentation[idx_sub_cluster] != best_idx) { is_changed = true; prepresentation[idx_sub_cluster] = best_idx; } idx_start_center = idx_end_center; } return is_changed; }
template <typename INT> void Node_Set<INT>::load_nodes(const INT *node_map) const { if (numEntity > 0) { nodes = new INT[numEntity]; SMART_ASSERT(nodes != nullptr); nodeIndex = new INT[numEntity]; SMART_ASSERT(nodeIndex != nullptr); ex_get_set(fileId, EX_NODE_SET, id_, nodes, nullptr); if (node_map != nullptr) { for (size_t i = 0; i < numEntity; i++) { nodes[i] = 1 + node_map[nodes[i] - 1]; } } for (size_t i = 0; i < numEntity; i++) { nodeIndex[i] = i; } if (interface.nsmap_flag) index_qsort(nodes, nodeIndex, numEntity); } }
YCImageBackground::YCImageBackground(YCIUITag *host, YCTexture* texture) : YCIBackground(host) , myTexture(texture) , myDrawer(NULL) { SMART_ASSERT(texture != NULL); YCGraphic* graphic = (YCGraphic*)YCRegistry::get("graphic"); if (graphic == NULL) { throw YCException(2002, "YCImageBackground无法获取YCGraphic句柄!"); } myDrawer = graphic->createD3DSprite(); }
template <typename INT> std::string ExoII_Read<INT>::Load_Elmt_Block_Descriptions() const { SMART_ASSERT(Check_State()); if (!Open()) return "ERROR: Must open file before loading blocks!"; for (size_t b = 0; b < num_elmt_blocks; ++b) { eblocks[b].Load_Connectivity(); // eblocks[b].Load_Attributes(); } return ""; }
template <typename INT> std::string ExoII_Read<INT>::File_Name(const char *fname) { SMART_ASSERT(Check_State()); if (Open()) return "ERROR: File is already open!"; if (!fname || std::strlen(fname) == 0) return "ERROR: File name is empty!"; file_name = fname; return ""; }
// // 注释:查看一个文件的详细信息 // // op : file /pathInPack/xxx.png // YCIAbstractFile* YCLYCPackSystem::file(const char* packFile) { SMART_ASSERT(packFile != NULL); if (packFile == NULL || strlen(packFile) == 0) { throw YCPackException(1002, "YCLYCFileSystem::file无文件名参数"); } YCIAbstractFile* found = NULL; try { // 绝对路径 or 相对路径 YCIFileDirectory* position = (packFile[0] == '\\') ? NULL : myCurrent; std::vector<std::string> dirs; YCStringHelper::split(packFile, "\\", &dirs); for (unsigned int i = 0; i < dirs.size(); ++i) { const std::string& dir = dirs[i]; if (position == NULL) { for (Item_List_T* item = myPackFiles->begin(); item != myPackFiles->end(); item = myPackFiles->next(item)) { YCLYCFilePack* pack = (YCLYCFilePack*)myPackFiles->payload(item); if (stricmp(pack->getPackName(), dir.c_str()) == 0) { position = pack; } } if (position == NULL) { throw YCPackException(1002, "YCLYCFileSystem::file目录未找到", dir.c_str()); } } else { } } } catch (YCPackException& e) { LOG_ERROR("YCLYCFileSystem::file查找文件" << packFile << "出错:" << e.what()); } return found; }
template <typename INT> std::string ExoII_Read<INT>::Load_Nodal_Coordinates() { SMART_ASSERT(Check_State()); if (!Open()) return "WARNING: File not open!"; if (num_nodes) { size_t count = num_nodes * dimension; nodes = new double[count]; SMART_ASSERT(nodes != nullptr); double *x = nodes, *y = nodes, *z = nodes; if (dimension > 1) y = nodes + num_nodes; if (dimension > 2) z = nodes + (2 * num_nodes); int err = ex_get_coord(file_id, x, y, z); if (err < 0) { std::cout << "EXODIFF ERROR: Failed to get " << "nodal coordinates! Aborting..." << '\n'; exit(1); } else if (err > 0) { delete[] nodes; nodes = nullptr; std::ostringstream oss; oss << "EXODIFF WARNING: " << "Exodus issued warning \"" << err << "\" on call to ex_get_coord()!" << " I'm not going to keep what it gave me for coordinates."; return oss.str(); } } else return "WARNING: There are no nodes!"; return ""; }
Excn::ExodusFile::ExodusFile(int processor) : myProcessor_(processor) { SMART_ASSERT(processor < processorCount_)(processor)(processorCount_); SMART_ASSERT(fileids_.size() == (size_t)processorCount_); if (!keepOpen_ && processor != 0) { float version = 0.0; int cpu_word_size = cpuWordSize_; int io_word_size_var = ioWordSize_; int mode = EX_READ; mode |= mode64bit_; fileids_[processor] = ex_open(filenames_[processor].c_str(), mode, &cpu_word_size, &io_word_size_var, &version); if (fileids_[processor] < 0) { std::cerr << "Cannot open file '" << filenames_[processor] << "' - exiting" << '\n'; exit(1); } ex_set_max_name_length(fileids_[processor], maximumNameLength_); SMART_ASSERT(io_word_size_var == ioWordSize_); SMART_ASSERT(cpu_word_size == cpuWordSize_); } }
Excn::ExodusFile::ExodusFile(size_t which) : myLocation_(which) { SMART_ASSERT(which < filenames_.size())(which)(filenames_.size()); SMART_ASSERT(fileids_.size() == filenames_.size()); if (!keepOpen_ && which != 0) { float version = 0.0; int cpu_word_size = cpuWordSize_; int io_wrd_size = ioWordSize_; fileids_[which] = ex_open(filenames_[which].c_str(), EX_READ|exodusMode_, &cpu_word_size, &io_wrd_size, &version); if (fileids_[which] < 0) { std::cerr << "Cannot open file '" << filenames_[which] << "' - exiting" << std::endl; exit(1); } ex_set_max_name_length(fileids_[which], maximumNameLength_); SMART_ASSERT(io_wrd_size == ioWordSize_); SMART_ASSERT(cpu_word_size == cpuWordSize_); } }
// automatic packing, does simple data correctly, need not be overloaded for simple cases void Info::pack(PackedData& dp) const { // get the size of the structure (w/o VMT): unsigned infoSize = getInfoHandler().getByteSize() - sizeof(Info); Logger::debug3() << "Info: automatic packing of " << getInfoHandler().getClassType() << " with size=" << infoSize << std::endl; SMART_ASSERT( infoSize>=0 ); // cast the object as a char array and skip the VMT stuff (everythig in Info): const char* data = reinterpret_cast<const char*>(this) + sizeof(Info); // cast it as a char array // and now put it into dp: dp.add( infoSize ); dp.add_array(infoSize, data); }
template <typename INT> size_t Node_Set<INT>::Node_Id(size_t position) const { if (numEntity <= 0) { return 0; } else { // See if already loaded... if (!nodes) { load_nodes(); } SMART_ASSERT(position < numEntity); return nodes[nodeIndex[position]]; } }
// // 注释:初始化文件系统 // bool YCLYCPackSystem::initialize() { // 创建构建器 SMART_ASSERT(myFactory == NULL); if (myFactory != NULL) { throw YCPackException(1002, "YCLYCFileSystem::initialize重复初始化"); } myFactory = new YCLYCFactory(); myFactory->regist(new YCLYCFileBuilder1()); return true; }
// // 注释:打开一个压缩包文件 // // 内部函数,用于mount时读取,不对外提供op // bool YCLYCPackSystem::open(const char * packFile) { SMART_ASSERT(packFile != NULL); if (packFile == NULL) { throw YCPackException(1002, "YCLYCFileSystem::open打开文件为空"); } // 是否已加载 for (Item_List_T* item = myPackFiles->begin(); item != myPackFiles->end(); item = myPackFiles->next(item)) { YCIFilePack* thePack = (YCIFilePack*)myPackFiles->payload(item); if (stricmp(thePack->filename(), packFile) == 0) { return true; } } LYC_PACK_HEAD head; FILE* fd = fopen(packFile, "r"); SCOPE_GUARD(fd_guard, fclose(fd)); if (fd == NULL) { throw YCPackException(1002, "YCLYCFileSystem::open读取文件失败", packFile); } if (1 != fread(&head, sizeof(LYC_PACK_HEAD), 1, fd)) { throw YCPackException(1002, "YCLYCFileSystem::open读取全局文件头失败", packFile); } YCIPackFileBuilder* builder = myFactory->getBuilder(head.version); if (builder == NULL) { throw YCPackException(1002, "YCLYCFileSystem::filename获取构建器失败",packFile); } YCIFilePack* result = builder->loadPack(packFile); if (result == NULL) { throw YCPackException(1002, "YCLYCFileSystem::filename创建压缩包文件失败", packFile); } myPackFiles->append(result, NULL); return true; }
std::string Exo_Entity::Load_Attributes(int attr_index) { SMART_ASSERT(Check_State()); if (fileId < 0) return "exodiff: ERROR: Invalid file id!"; if (id_ == EX_INVALID_ID) return "exodiff: ERROR: Must initialize block parameters first!"; SMART_ASSERT(attr_index >= 0 && attr_index < numAttr); if (!attributes_[attr_index] && numEntity) { attributes_[attr_index] = new double[numEntity]; SMART_ASSERT(attributes_[attr_index] != nullptr); } if (numEntity) { int err = 0; err = ex_get_one_attr(fileId, exodus_type(), id_, attr_index + 1, attributes_[attr_index]); if (err < 0) { ERROR("Exo_Entity::Load_Attributes(): Call to exodus routine" << " returned error value! " << label() << " id = " << id_ << '\n' << "Aborting...\n"); exit(1); } else if (err > 0) { std::ostringstream oss; oss << "WARNING: Number " << err << " returned from call to exodus get attribute routine."; return oss.str(); } } else return std::string("WARNING: No items in this ") + label(); return ""; }
void Exo_Entity::get_truth_table() const { if (numVars > 0 && truth_ == nullptr) { truth_ = new int[numVars]; SMART_ASSERT(truth_ != nullptr); // initialize to true for the case of no objects in the block (some older // versions of ex_get_object_truth_vector do not set the values at all) for (int i = 0; i < numVars; ++i) truth_[i] = 1; int err = ex_get_object_truth_vector(fileId, exodus_type(), id_, numVars, truth_); if (err < 0) { ERROR("Exo_Entity::get_truth_table(): ex_get_object_truth_vector returned error.\n"); } } }
static void* umountPackFile(const char* path, const char* filename, void* customData) { SMART_ASSERT(customData != NULL); if (customData == NULL) { throw YCPackException(1002, "mountPackFile未设置YCLYCFileSystem句柄"); } char fullname[MAX_PATH] = {0}; sprintf(fullname, "%s\\%s", path, filename); YCLYCPackSystem* fileSystem = (YCLYCPackSystem*)customData; fileSystem->close(fullname); return NULL; }
int IndexEncoding::SolveOptimizedAdv3( const Vector<double> &vec_x_map, const SMatrix<double> &matPrecomputed, int num_dic_each_partition, short* prepresentation) const { int num = 0; if (m_isInitialize) { for (int i = 0; i < num_dic_each_partition; i++) { prepresentation[i] = -1; } } bool is_changed; ////VIPjjjkkk if (m_nNumberOfGroup == 1) { do { num++; is_changed = SolveOptimizedAdv3Once(vec_x_map, matPrecomputed, num_dic_each_partition, prepresentation); } while(is_changed); } else if (m_nNumberOfGroup == 2) { do { num++; is_changed = SolveOptimizedAdv3Twice( vec_x_map, matPrecomputed, num_dic_each_partition, prepresentation); }while(is_changed); } else { SMART_ASSERT(0).Exit(); } return num; }
void PyInfo::pack( PackedData& pd ) const { #ifdef SIMX_USE_PRIME SMART_ASSERT(false) ("PyInfo::pack() method must never get called when using SSF. Only PyRemoteInfo may be used"); #else //cout << "inside pack" << endl; //std::ostringstream os; // save data to archive //boost::archive::text_oarchive oa(os); // write class instance to archive // assert(false); //oa << fData; //fData.serialize(oa,1);) //assert(false); // archive and stream closed when destructors are called //boost::python::str py_string = boost::python::pickle::dumps(fData); // python::object pickler = python::import("cPickle"); // python::str ps = python::extract<python::str> // (pickler.attr("dumps")(fData)); // python::str ps = //python::extract<python::str> // extract<str>( theInfoManager().getPacker()(fData) ); //string s = python::extract<string>(ps); //pd.add(s); //pd.addAnything(fData); //boost::python::str ps = dumps(fData); //pd.add(ps); //PyGILState_STATE gstate; //gstate = PyGILState_Ensure(); //Py_INCREF(fData.ptr()); //assert(fData.ptr()); pd.add( //python::extract<python::str> //(theInfoManager().getPacker()(*fData))); python::extract<string> (theInfoManager().getPacker()(getData()))); //pd.add( fPickledData ); //pd.add(theInfoManager().getPacker()(fData)); //PyGILState_Release(gstate); //pd.add( theInfoManager().getPacker()(fData) ); #endif }
YCCSSNode::YCCSSNode(const char* sel) : myNodeImpl(new YCCSSNodeImpl()) , myPriority(-1) , mySelector(NULL) , myType(NODE_NORMAL) { SMART_ASSERT(sel != NULL); mySelector = new char[strlen(sel)+1]; memcpy(mySelector, sel, strlen(sel)); mySelector[strlen(sel)] = '\0'; // 节点类型 if (isPseudoType(NODE_HOVER)) myType = NODE_HOVER; else if (isPseudoType(NODE_CLICK)) myType = NODE_CLICK; else if (isPseudoType(NODE_DISABLE)) myType = NODE_DISABLE; }
unsigned int YCTextureIDUtil::encode(E_TEXTURE_TYPE type, const char* filename) { SMART_ASSERT(filename != NULL); if (type == TEXTURE_MAP) return encodeTilesMapId(filename); else if (type == TEXTURE_SHAREDMAP) return encodeSharedMapId(filename); else if (type == TEXTURE_OBSTACLE) return encodeObstacleId(filename); else if (type == TEXTURE_NPC) return encodeNPCId(filename); else if (type == TEXTURE_PLAYER) return encodePlayerId(filename); else if (type == TEXTURE_MONSTER) return encodeMonsterId(filename); else if (type == TEXTURE_EFFECT) return encodeEffectId(filename); else if (type == TEXTURE_UI) return encodeUIId(filename); else throw YCException(2002, "未知纹理编号!"); return 0; }
// // 函数:load(YCIModule* module) // // 目的:加载对应模块 // void load(YCIModule* module) { SMART_ASSERT(module != NULL); if (module == NULL) { throw YCException(2002, "YCModuleManager::load模块为空!"); } if (module->status() == YCIModule::INITED) { //module->preload(); module->load(); //module->postload(); } }
// // 函数:unload(YCIModule* module) // // 目的:卸载对应模块 // void YCModuleManager::unload(YCIModule* module) { SMART_ASSERT(module != NULL); if (module == NULL) { throw YCException(2002, "YCModuleManager::unload模块为空!"); } if (module->status() == YCIModule::ACTIVE) { //module->preunload(); module->unload(); //module->postunload(); } }
// // 注释:在压缩包中查找文件,pathInPack为查找路径 // 如果pathInPack为空,则在当前路径下查找 // 如果pathInPack 为绝对路径,则从根目录下查找 // 返回查找到的第一个文件,如果没有找到,返回NULL // // op : find 0001.png /ui/0/ <= 绝对路径 // find 0001.png <= 当前路径下 // YCIAbstractFile* YCLYCPackSystem::find(const char* packFile, const char* pathInPack) { SMART_ASSERT(packFile != NULL); if (packFile == NULL) { throw YCPackException(1002, "YCLYCFileSystem::find参数有误"); } char nextPath[MAX_PATH] = {0}; if (!YCPathWalker::isAbsolutePath(pathInPack) && myCurrent != NULL) { sprintf(nextPath, "%s\\%s", pathInPack, packFile); return myCurrent->get(nextPath); } YCPathWalker walker(pathInPack); int length; YCPathWalker::E_FILE_TYPE type; const char* first = walker.next(length, type); if (first == NULL || type == YCPathWalker::DISK) { throw YCPackException(1002, "YCLYCFileSystem::find包路径有误"); } YCIFileDirectory * position = NULL; for (Item_List_T* item = myPackFiles->begin(); item != myPackFiles->end() && !position; item = myPackFiles->next(item)) { YCLYCFilePack* exists = (YCLYCFilePack*)myPackFiles->payload(item); if (strnicmp(exists->getPackName(), first, length) == 0) { position = exists; } } if (NULL == position) { throw YCPackException(1002, "YCLYCFileSystem::find包文件不存在"); } sprintf(nextPath, "%s\\%s", walker.remain(), packFile); return position->get(nextPath); }
// // 注释:添加文件搜索路径 // bool YCLYCPackSystem::mount(const char* regulePath) { SMART_ASSERT(regulePath != NULL); if (regulePath == NULL) { throw YCPackException(1002, "YCLYCFileSystem::mount路径为空"); } if (!YCFileUtil::IsFileExist(regulePath)) { throw YCPackException(1002, "YCLYCFileSystem::mount路径不存在"); } std::string pathWithLYCFilter(regulePath); pathWithLYCFilter += LYC_FILE_EXTENSION; YCFileUtil::HandleFileInDir(pathWithLYCFilter.c_str(), mountPackFile, this); return true; }
template <typename INT> std::string ExoII_Read<INT>::Open_File(const char *fname) { SMART_ASSERT(Check_State()); if (Open()) return "ERROR: File already open!"; if (fname && std::strlen(fname) > 0) file_name = fname; else if (file_name == "") return "ERROR: No file name to open!"; int ws = 0, comp_ws = 8; float dum = 0.0; int mode = EX_READ; if (sizeof(INT) == 8) { mode |= EX_ALL_INT64_API; } int err = ex_open(file_name.c_str(), mode, &comp_ws, &ws, &dum); if (err < 0) { std::ostringstream oss; oss << "ERROR: Couldn't open file \"" << file_name << "\"."; // ExodusII library could not open file. See if a file (exodusII // or not) exists with the specified name. FILE *fid = fopen(file_name.c_str(), "r"); if (fid != nullptr) { oss << " File exists, but is not an exodusII file."; fclose(fid); } else { oss << " File does not exist."; } return oss.str(); } file_id = err; io_word_size = ws; Get_Init_Data(); return ""; }
// // 函数:download(const char* moduleName, int version) // // 目的:调用YCIModuleLoader阻塞下载Module // bool YCModuleManager::download(const char* moduleName, int version) { SMART_ASSERT(myModuleLoader != NULL); if (!exist(moduleName, version)) { if (!myModuleLoader->download(moduleName, version)) { return false; } YCIModule * module = compile(moduleName, version); if (module == NULL) { return false; } myModules->append(module, NULL); } return true; }
// // 函数:addObject(YCIMapObject* object) // // 目的:挂接对象到地图块 // void YCIMapTile::addObject(YCIMapObject* object) { SMART_ASSERT(object != NULL); if (object == NULL) { throw YCException(2002, "YCIMapTile::addObject挂接空对象到地图块"); } Item_List_T* item = myObjects->begin(); for (; item != myObjects->end(); item = myObjects->next(item)) { YCIMapObject* current = (YCIMapObject*)myObjects->payload(item); if (current->compareLayer(object) < 0) { break; } } myObjects->insert(object, item); }
// // 函数:removeListener(E_UITAG_EVENT event, const char* scripts) // // 目的:删除消息监听器 // void YCIComponent::addListener(E_UITAG_EVENT event, const char* scripts) { SMART_ASSERT(scripts != NULL); for (Item_List_T* item = myListeners->begin(); item != myListeners->end(); item = myListeners->next(item)) { YCListener_T *current = (YCListener_T*)myListeners->payload(item); if (current->event == event) { current->scripts = scripts; return; } } YCListener_T* listener = new YCListener_T(); listener->event = event; listener->scripts = scripts; myListeners->append(listener, NULL); }
// // 函数:append(void* payload, Item_List_T* position) // // 目的:在position节点后插入节点item // 如果position==NULL,插入失败 // // 返回值:插入成功返回True,否则返回False // bool YCDList::append(void* payload, Item_List_T* position) { SMART_ASSERT(payload != NULL); if (payload != NULL) { Item_List_T* item = new Item_List_T(); memset(item, 0, sizeof(Item_List_T)); item->payload = payload; if (position != NULL) { item->prev = position; if (position->next != NULL) { position->next->prev = item; } item->next = position->next; position->next = item; } else //尾部插入 { if (myTail == NULL) //第一个节点 { item->prev = myHead; myHead->next = item; } else { myTail->next = item; item->prev = myTail; } myTail = item; } length += 1; return true; } return false; }
void PyService::receive( shared_ptr<PyInfo> info ) { Logger::debug3() << "PyService.C: Service " << getName() << ": PyInfo received" << endl; //PyGILState_STATE gstate; //gstate = PyGILState_Ensure(); try { if ( info->fPickled ) // fPyObj.attr("recv")(info->fPickledData,true); { #ifdef SIMX_USE_PRIME SMART_ASSERT(false) ("Pickled PyInfo should never be used with SSF. Only PyRemoteInfo may be used"); #endif //info->fData = theInfoManager().getUnpacker()(info->fPickledData); info->setData( theInfoManager(). getUnpacker()( info->fPickledData)); //fPyObj.attr("recv")( theInfoManager().getUnpacker()( info->fPickledData )); } //else //fPyObj.attr("recv")(info->fData,false); //fPyObj.attr("recv")(*(info->fData)); //assert(info->getData()); //else fPyObj.attr("recv")(info->getData()); } catch(...) { Logger::error() << "PyService.C: Service " << getName() << ": error in handling incoming info" << endl; PyErr_Print(); PyErr_Clear(); } //PyGILState_Release(gstate); }