void CLayers::DrawLayers(HDC m_hDC,CMapPosition*mp) { int Count=layers.GetSize(); for(int k=0;k<Count;k++) { CLayer*pLayer=layers.GetAt(k); CLayerPainterManager pManager(pLayer); pManager.Draw(m_hDC,mp); } }
/////////////////////////////////////////////////////////// // Clears the information list for the current thread /////////////////////////////////////////////////////////// void exceptionsManager::clearExceptionInfo() { ptr<exceptionsManager> pManager(getExceptionsManager()); lockObject lock(pManager.get()); tInfoMap::iterator findInformation = pManager->m_information.find(std::this_thread::get_id()); if(findInformation == pManager->m_information.end()) { return; } pManager->m_information.erase(findInformation); }
/////////////////////////////////////////////////////////// // Return the info objects for the specified thread /////////////////////////////////////////////////////////// void exceptionsManager::getExceptionInfo(tExceptionInfoList* pList) { ptr<exceptionsManager> pManager(getExceptionsManager()); lockObject lock(pManager.get()); tInfoMap::iterator findInformation = pManager->m_information.find(std::this_thread::get_id()); if(findInformation == pManager->m_information.end()) { return; } for(tExceptionInfoList::iterator scanInformation = findInformation->second.begin(); scanInformation != findInformation->second.end(); ++scanInformation) { pList->push_back(*scanInformation); } pManager->m_information.erase(findInformation); }
char *GetSequence(char *f_name) { for (std::vector<music_file>::iterator i = ::music_data.begin(); i != ::music_data.end(); i++) { // If the file has already been loaded, return the existing data if (strcmp(f_name, i->name) == 0) return (char *)i->data; } // File hasn't been loaded, do that now gm::ManagerPtr pManager(gm::getManager()); camoto::stream::input_file_sptr psMusic(new camoto::stream::input_file()); try { psMusic->open(f_name); } catch (const camoto::stream::open_error& e) { fprintf(stderr, "Error opening %s\n", f_name); return NULL; } gm::MusicTypePtr pMusicType(pManager->getMusicTypeByCode("cmf-creativelabs")); if (!pMusicType->isInstance(psMusic)) { printf("File %s is not in CMF format!\n", f_name); return NULL; } camoto::SuppData suppData; gm::MusicPtr pMusic(pMusicType->read(psMusic, suppData)); assert(pMusic); camoto::stream::string_sptr pss(new camoto::stream::string()); gm::MusicTypePtr pMusicOutType(pManager->getMusicTypeByCode("imf-idsoftware-type1")); pMusicOutType->write(pss, suppData, pMusic, gm::MusicType::Default); music_file cmf; strcpy(cmf.name, f_name); std::string imfdata = pss->str(); int len = imfdata.length(); cmf.data = new uint8_t[len]; memcpy(cmf.data, imfdata.data(), len); ::music_data.push_back(cmf); printf("Loaded CMF file %s\n", cmf.name); return (char *)cmf.data; }
/////////////////////////////////////////////////////////// // Add an info object to the current thread /////////////////////////////////////////////////////////// void exceptionsManager::addExceptionInfo(const exceptionInfo& info) { ptr<exceptionsManager> pManager(getExceptionsManager()); lockObject lock(pManager.get()); pManager->m_information[std::this_thread::get_id()].push_back(info); }
int main(int iArgC, char *cArgV[]) { #ifdef __GLIBCXX__ // Set a better exception handler std::set_terminate(__gnu_cxx::__verbose_terminate_handler); #endif // Disable stdin/printf/etc. sync for a speed boost std::ios_base::sync_with_stdio(false); // Declare the supported options. po::options_description poOptions("Options"); poOptions.add_options() ("type,t", po::value<std::string>(), "specify the output file format") ; po::options_description poHidden("Hidden parameters"); poHidden.add_options() ("in", ".png to read") ("out", "output palette filename") ("help", "produce help message") ; po::options_description poVisible(""); poVisible.add(poOptions); po::options_description poComplete("Parameters"); poComplete.add(poOptions).add(poHidden); po::variables_map mpArgs; std::string srcFile, dstFile; std::string strType; try { po::parsed_options pa = po::parse_command_line(iArgC, cArgV, poComplete); // Parse the global command line options for (std::vector<po::option>::iterator i = pa.options.begin(); i != pa.options.end(); i++) { if (i->string_key.empty()) { // If we've already got an archive filename, complain that a second one // was given (probably a typo.) if (!dstFile.empty()) { std::cerr << "Error: unexpected extra parameter (multiple output " "filenames given?!)" << std::endl; return 1; } assert(i->value.size() > 0); // can't have no values with no name! if (srcFile.empty()) srcFile = i->value[0]; else dstFile = i->value[0]; } else if (i->string_key.compare("help") == 0) { std::cout << "Copyright (C) 2010 Adam Nielsen <*****@*****.**>\n" "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to change and redistribute it under certain conditions;\n" "see <http://www.gnu.org/licenses/> for details.\n" "\n" "Utility to manipulate image palettes used by games.\n" "Build date " __DATE__ " " __TIME__ << "\n" "\n" "Usage: " PROGNAME " <input>.png -t <output-type> <output-filename>\n" << poVisible << "\n" << std::endl; return 0; } else if ( (i->string_key.compare("t") == 0) || (i->string_key.compare("type") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --type (-t) requires a parameter." << std::endl; return 1; } strType = i->value[0]; } } if (srcFile.empty()) { std::cerr << "Error: no input .png filename given" << std::endl; return 1; } if (dstFile.empty()) { std::cerr << "Error: no output filename given" << std::endl; return 1; } if (strType.empty()) { std::cerr << "Error: no output format type (-t) given" << std::endl; return 1; } // Get the format handler for this file format gg::ManagerPtr pManager(gg::getManager()); gg::ImageTypePtr palType(pManager->getImageTypeByCode(strType)); if (!palType) { std::cerr << "Unknown file type given to -t/--type: " << strType << std::endl; return 1; } std::cout << "Extracting palette from " << srcFile << " to " << dstFile << " as type " << strType << std::endl; png::image<png::index_pixel> png( srcFile, png::require_color_space<png::index_pixel>() ); stream::file_sptr outStream(new stream::file()); try { outStream->create(dstFile.c_str()); } catch (const stream::open_error& e) { std::cerr << PROGNAME ": Unable to create " << dstFile << ": " << e.what() << std::endl; return 2; } camoto::SuppData dummy; gg::ImagePtr palOut = palType->create(outStream, dummy); gg::PaletteTablePtr pal(new gg::PaletteTable()); png::palette pngPal = png.get_palette(); for (png::palette::iterator i = pngPal.begin(); i != pngPal.end(); i++) { gg::PaletteEntry p; p.red = i->red; p.green = i->green; p.blue = i->blue; pal->push_back(p); } palOut->setPalette(pal); } catch (const po::unknown_option& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return 1; } catch (const po::invalid_command_line_syntax& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return 1; } return 0; }
int main(int iArgC, char *cArgV[]) { // Set a better exception handler std::set_terminate( __gnu_cxx::__verbose_terminate_handler ); // Disable stdin/printf/etc. sync for a speed boost std::ios_base::sync_with_stdio(false); // Declare the supported options. po::options_description poActions("Actions"); poActions.add_options() ("list,l", "list contents of the address book") ("update,u", po::value<std::string>(), "select an address book entry to change by ID") ("add,a", po::value<std::string>(), "add a new address book entry and select it") ("set,s", po::value<std::string>(), "field:value parameter updates entry selected by earlier -u or -a") ; po::options_description poOptions("Options"); poOptions.add_options() ("type,t", po::value<std::string>(), "specify the MFD type (default is autodetect)") ("user,u", po::value<std::string>(), "username to log in as") ("pass,p", po::value<std::string>(), "password") ; po::options_description poHidden("Hidden parameters"); poHidden.add_options() ("host", "MFD hostname") ("help", "produce help message") ; po::options_description poVisible(""); poVisible.add(poActions).add(poOptions); po::options_description poComplete("Parameters"); poComplete.add(poActions).add(poOptions).add(poHidden); po::variables_map mpArgs; std::string host, user, pass, type; try { po::parsed_options pa = po::parse_command_line(iArgC, cArgV, poComplete); // Parse the global command line options for (std::vector<po::option>::iterator i = pa.options.begin(); i != pa.options.end(); i++) { if (i->string_key.empty()) { // If we've already got an archive filename, complain that a second one // was given (probably a typo.) if (!host.empty()) { std::cerr << "Error: unexpected extra parameter (multiple MFDs " "given?!)" << std::endl; return 1; } assert(i->value.size() > 0); // can't have no values with no name! host = i->value[0]; } else if (i->string_key.compare("help") == 0) { std::cout << "Copyright (C) 2010 Adam Nielsen <*****@*****.**>\n" "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to change and redistribute it under certain conditions;\n" "see <http://www.gnu.org/licenses/> for details.\n" "\n" "Utility to remotely configure multi-function devices (networked photocopiers.)\n" "Build date " __DATE__ " " __TIME__ << "\n" "\n" "Usage: mfdmgr <hostname> <action> [action...]\n" << poVisible << "\n" << std::endl; return RET_OK; } else if ( (i->string_key.compare("t") == 0) || (i->string_key.compare("type") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --type (-t) requires a parameter." << std::endl; return RET_BADARGS; } type = i->value[0]; } else if ( (i->string_key.compare("u") == 0) || (i->string_key.compare("user") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --user (-u) requires a parameter." << std::endl; return RET_BADARGS; } user = i->value[0]; } else if ( (i->string_key.compare("p") == 0) || (i->string_key.compare("pass") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --pass (-p) requires a parameter." << std::endl; return RET_BADARGS; } pass = i->value[0]; } } if (host.empty()) { std::cerr << "Error: no hostname given" << std::endl; return RET_BADARGS; } std::cout << "Opening " << host << " as type " << (type.empty() ? "<autodetect>" : type) << std::endl; // Get the format handler for this file format boost::shared_ptr<mfd::Manager> pManager(mfd::getManager()); mfd::DeviceTypePtr pDeviceType; if (type.empty()) { // Need to autodetect the file format. mfd::DeviceTypePtr pTestType; int i = 0; while ((pTestType = pManager->getDeviceType(i++))) { mfd::E_CERTAINTY cert = pTestType->isInstance(host); switch (cert) { case mfd::EC_DEFINITELY_NO: // Don't print anything (TODO: Maybe unless verbose?) break; case mfd::EC_DEFINITELY_YES: std::cout << "Device is definitely a " << pTestType->getFriendlyName() << " [" << pTestType->getDeviceCode() << "]" << std::endl; pDeviceType = pTestType; // Don't bother checking any other formats if we got a 100% match goto finishTesting; } } finishTesting: if (!pDeviceType) { std::cerr << "Unable to automatically determine the file type. Use " "the --type option to manually specify the file format." << std::endl; return RET_BE_MORE_SPECIFIC; } } else { mfd::DeviceTypePtr pTestType(pManager->getDeviceTypeByCode(type)); if (!pTestType) { std::cerr << "Unknown device type given to -t/--type: " << type << std::endl; return RET_BADARGS; } pDeviceType = pTestType; } assert(pDeviceType != NULL); // Connect to the device boost::shared_ptr<mfd::Device> pDevice(pDeviceType->open(host, user, pass)); assert(pDevice); int iRet = RET_OK; // ID of previously selected address book item std::string idABSelected; std::map<std::string, std::string> fieldSet; // TODO: enum for field type // Run through the actions on the command line for (std::vector<po::option>::iterator i = pa.options.begin(); i != pa.options.end(); i++) { if (i->string_key.compare("list") == 0) { boost::shared_ptr<mfd::AddressBook> ab = pDevice->getAddressBook(); if (!ab) { std::cerr << "This device type does not have an address book." << std::endl; iRet = RET_BADARGS; continue; } const mfd::AddressBook::VC_ENTRYID& entryIds = ab->getEntryIds(); for (mfd::AddressBook::VC_ENTRYID::const_iterator i = entryIds.begin(); i != entryIds.end(); i++ ) { std::cout << "id is " << *i << std::endl; } mfd::AddressBook::VC_FIELDLIST allEntries; ab->getEntries(entryIds, allEntries); for (mfd::AddressBook::VC_FIELDLIST::iterator i = allEntries.begin(); i != allEntries.end(); i++ ) { mfd::AddressBook::FieldList& fl = *i; for (mfd::AddressBook::FieldList::iterator j = fl.begin(); j != fl.end(); j++ ) { std::cout << j->first << "=" << j->second << "; "; } std::cout << std::endl; } } else if (i->string_key.compare("update") == 0) { idABSelected = i->value[0]; std::cout << "Selected ID " << idABSelected << " for update" << std::endl; fieldSet.clear(); // empty any fields previously set } else if (i->string_key.compare("set") == 0) { if (idABSelected.empty()) { std::cerr << "ERROR: You must use -u or -a before --set/-s" << std::endl; iRet = RET_BADARGS; break; } idABSelected = i->value[0]; std::string fieldName, fieldVal; bool bAltDest = split(i->value[0], ':', &fieldName, &fieldVal); if (!bAltDest) { std::cerr << "ERROR: --set/-s requires a parameter of the form " "field:value" << std::endl; iRet = RET_BADARGS; break; } std::cout << "Set field \"" << fieldName << "\" to \"" << fieldVal << "\"" << std::endl; // Ignore --type/-t } else if (i->string_key.compare("type") == 0) { } else if (i->string_key.compare("t") == 0) { } } // for (all command line elements) } catch (po::unknown_option& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return RET_BADARGS; } catch (po::invalid_command_line_syntax& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return RET_BADARGS; } catch (mfd::ECommFailure& e) { std::cerr << PROGNAME ": Communication failure (" << e.what() << ")" << std::endl; return RET_SHOWSTOPPER; } return RET_OK; }