本文整理汇总了C++中FileHandler类的典型用法代码示例。如果您正苦于以下问题:C++ FileHandler类的具体用法?C++ FileHandler怎么用?C++ FileHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exit
void MatrixGraph::displayMatrix(MatrixGraph& mg)
{
IoHandler ioh;
string fileName = ioh.getString("무방향 그래프가 저장된 파일명을 입력하시오.(종료는 quit) : ");
if (fileName == "quit")
{
exit(1);
}
FileHandler fh;
fh.loadMatrixGraph(fileName, mg);
ioh.putString("입력된 그래프의 인접 행렬 표현");
ioh.putNewLine();
mg.printMatrix();
ioh.putNewLine();
mg.dfs();
ioh.putNewLine();
mg.bfs();
ioh.putNewLine();
}
示例2: main
int main()
{
sout << locker << "\n Console Receiver Demo "
<< "\n =======================\n" << unlocker;
try
{
EndPoint rep("127.0.0.1",8081);
//EndPoint sep("127.0.0.1",2049);
// MsgReceiver_Proc is your receiver's server message handling
// FileReceiver_Proc is your receiver's server file handling
Communicator rcvr(rep);
MsgHandler<MsgReceiver_Proc> rMsgHandler;
rMsgHandler.setCommunicator(&rcvr);
rcvr.attachMsgHandler(&rMsgHandler);
FileHandler<FileReceiver_Proc> rFileHandler;
rFileHandler.setFileDestination(".\\debug");
rFileHandler.setCommunicator(&rcvr);
rcvr.attachFileHandler(&rFileHandler);
rcvr.listen();
sout << "\n\n press key to exit: ";
sout.flush();
_getche();
sout << "\n\n";
rcvr.disconnect();
}
catch(std::exception& ex)
{
sout << locker << "\n " << ex.what() << "\n\n" << unlocker;
}
}
示例3: assert
int CacheManager::init() {
assert(m_initialised == false);
FileHandler *fh = System::instance()->getFileHandler();
assert(fh != NULL);
// Cache path name
std::string c_path = fh->getUserDataPath() + CACHE_PATH;
// Check if path exists
if (!fh->exists(c_path)) {
printf("Creating Cache Directory.\n");
fh->mkdir(c_path);
}
// Load cache data file
if (fh->exists(c_path + CACHE_FILE)) {
if (!m_cache.readFromFile(c_path + CACHE_FILE)) {
fprintf(stderr, "Error reading cache config file.\n");
}
}
m_initialised = true;
return 0;
}
示例4: GetCurrentProcesses
void ProcessHandler::WriteProcessesInfoToFile(char* pFilename)
{
std::vector<Process> processes = GetCurrentProcesses();
FileHandler fh;
fh.Open(pFilename, FileHandler::FILE_WRITE);
std::vector<Process>::iterator iter = processes.begin();
for (; iter != processes.end(); ++iter)
{
fh.Write(*iter);
}
fh.Close();
}
示例5: main_
ExitCodes main_(int, const char**) override
{
StringList in = getStringList_("in");
StringList out = getStringList_("out");
bool inplace = getFlag_("i");
// consistency checks
if (out.empty() && !inplace)
{
writeLog_("Cannot write output files, as neither -out nor -i are given. Use either of them, but not both!");
printUsage_();
return ILLEGAL_PARAMETERS;
}
if (out.size() > 0 && inplace)
{
writeLog_("Two incompatible arguments given (-out and -i). Use either of them, but not both!");
printUsage_();
return ILLEGAL_PARAMETERS;
}
if (!inplace && out.size() != in.size())
{
writeLog_("Output and input file list length must be equal!");
printUsage_();
return ILLEGAL_PARAMETERS;
}
// do the conversion!
FileHandler fh;
for (Size i = 0; i < in.size(); ++i)
{
FileTypes::Type f_type = fh.getType(in[i]);
if (f_type == FileTypes::INI) updateINI(in[i], inplace ? "" : out[i]);
else if (f_type == FileTypes::TOPPAS) updateTOPPAS(in[i], inplace ? "" : out[i]);
}
for (Size i = 0; i < tmp_files_.size(); ++i)
{
// clean up
File::remove(tmp_files_[i]);
}
if (failed_.size() > 0)
{
writeLog_("The following INI/TOPPAS files could not be updated:\n " + ListUtils::concatenate(failed_, "\n "));
return INPUT_FILE_CORRUPT;
}
return EXECUTION_OK;
}
示例6: locker
/*
* Create our database using the appropriate schema.
*/
bool DBHandler::dbCreateInstance()
{
QMutexLocker locker(&dbMutex);
int error = 0; // Number of SQL queries
QSqlQuery query(db);
if (db.isOpen())
{
qDebug() << "Creating Tables";
QString address_book_create = "CREATE TABLE address_book (id INTEGER PRIMARY KEY, nym_id TEXT, nym_display_name TEXT)";
// --------------------------------------------
QString default_nym_create = "CREATE TABLE default_nym (default_id INTEGER PRIMARY KEY, nym TEXT)";
QString default_server_create = "CREATE TABLE default_server (default_id INTEGER PRIMARY KEY, server TEXT)";
QString default_asset_create = "CREATE TABLE default_asset (default_id INTEGER PRIMARY KEY, asset TEXT)";
QString default_account_create = "CREATE TABLE default_account (default_id INTEGER PRIMARY KEY, account TEXT)";
QString settings = "CREATE TABLE settings (setting TEXT PRIMARY KEY, parameter1 TEXT)";
// --------------------------------------------
QString create_contact = "CREATE TABLE contact(contact_id INTEGER PRIMARY KEY, contact_display_name TEXT)";
QString create_nym = "CREATE TABLE nym(nym_id TEXT PRIMARY KEY, contact_id INTEGER, nym_display_name)";
QString create_server = "CREATE TABLE nym_server(nym_id TEXT, server_id TEXT, PRIMARY KEY(nym_id, server_id))";
QString create_account = "CREATE TABLE nym_account(account_id TEXT PRIMARY KEY, server_id TEXT, nym_id TEXT, asset_id TEXT, account_display_name TEXT)";
// --------------------------------------------
error += query.exec(address_book_create);
error += query.exec(default_nym_create);
error += query.exec(default_server_create);
error += query.exec(default_asset_create);
error += query.exec(default_account_create);
error += query.exec(settings);
// --------------------------------------------
error += query.exec(create_contact);
error += query.exec(create_nym);
error += query.exec(create_server);
error += query.exec(create_account);
// ------------------------------------------
if(error != 10) //every querie passed?
{
qDebug() << "dbCreateInstance Error: " << dbConnectErrorStr + " " + dbCreationStr;
FileHandler rm;
db.close();
rm.removeFile(QString(OTPaths::AppDataFolder().Get()) + dbFileNameStr);
// rm.removeFile(QCoreApplication::applicationDirPath() + dbFileNameStr);
}
else
qDebug() << "Database " + dbFileNameStr + " created.";
}
return error;
}
示例7: FileHandlerEventProc
static int
FileHandlerEventProc(
Tcl_Event *evPtr, /* Event to service. */
int flags) /* Flags that indicate what events to handle,
* such as TCL_FILE_EVENTS. */
{
FileHandler *filePtr;
FileHandlerEvent *fileEvPtr = (FileHandlerEvent *) evPtr;
int mask;
if (!(flags & TCL_FILE_EVENTS)) {
return 0;
}
/*
* Search through the file handlers to find the one whose handle matches
* the event. We do this rather than keeping a pointer to the file handler
* directly in the event, so that the handler can be deleted while the
* event is queued without leaving a dangling pointer.
*/
for (filePtr = notifier.firstFileHandlerPtr; filePtr != NULL;
filePtr = filePtr->nextPtr) {
if (filePtr->fd != fileEvPtr->fd) {
continue;
}
/*
* The code is tricky for two reasons:
* 1. The file handler's desired events could have changed since the
* time when the event was queued, so AND the ready mask with the
* desired mask.
* 2. The file could have been closed and re-opened since the time
* when the event was queued. This is why the ready mask is stored
* in the file handler rather than the queued event: it will be
* zeroed when a new file handler is created for the newly opened
* file.
*/
mask = filePtr->readyMask & filePtr->mask;
filePtr->readyMask = 0;
if (mask != 0) {
filePtr->proc(filePtr->clientData, mask);
}
break;
}
return 1;
}
示例8: SwitchToReadMode
void CameraHandler::SwitchToReadMode() {
delete m_camera;
cout << "Please enter the directory name of your recorded video: ";
char dirName[150];
cin >> dirName;
FileHandler* fileHandler = FileHandler::Init();
const char* videoSuperDirectoryName = "Video";
char fullPath[150];
fileHandler->GetPath(videoSuperDirectoryName, dirName, fullPath);
m_camera = new CameraFromFile(fullPath);
if (!m_camera->IsInitialized()) {
cout << "Failed initializing read from file." << endl;
delete fileHandler;
exit(1);
}
delete fileHandler;
}
示例9: if
/**
* Load shader from file.
*/
void ShaderTransformation::loadShader(const char* file){
#ifdef _PC_
if(shaderType == ShaderTransformation::st_Pixel)
shader.loadFromFile(file, sf::Shader::Fragment);
else if(shaderType == ShaderTransformation::st_Vertex)
shader.loadFromFile(file, sf::Shader::Vertex);
else{
FileHandler handler;
MemoryPool* fileData = handler.readFile(file);
const char* vertexShader = (const char*)fileData->getBuffer();
int i;
while(vertexShader[i] != 0)
i++;
const char* pixelShader = vertexShader + i + 1;
shader.loadFromMemory(vertexShader, pixelShader);
delete fileData;
}
#endif
}
示例10: Index
/*
* Constructor to load already existing index
*/
Index(char* indexName) {
fHandler = new FileHandler(indexName, 'o');
header = (char *) malloc(BLOCK_SIZE);
fHandler->readBlock(0, header);
Utils::copyBytes(rootAddress, header, NODE_OFFSET_SIZE);
root = new TreeNode();
loadNode(root, rootAddress);
payloadlen = Utils::getIntForBytes(&header[NODE_OFFSET_SIZE]);
keytype = Utils::getKeyTypeForBytes(
&header[NODE_OFFSET_SIZE + sizeof(payloadlen)]);
}
示例11: main
int main(){
string filename = "topology.txt";
string filename1 = "changes.txt";
string filename2 = "messages.txt";
FileHandler * h = new FileHandler();
h->parse(filename,"TOPO_FILE");
h->parse(filename1,"CHANGES_FILE");
h->parse(filename2,"MESSAGES_FILE");
int len = h->getNumInit();
int * row_one = h->getGraph(0);
printf("Number of rows: %d\n",len);
printf("First row: %d %d %d\n",row_one[0],row_one[1],row_one[2]);
printf("Changes file\n");
printf("Number of changes: %d\n",h->getNumChanges());
int * change_one = h->getChange(0);
printf("First change: %d %d %d\n",change_one[0],change_one[1],change_one[2]);
printf("Messages\n");
printf("Number of messages: %d\n",h->getNumMessages());
printf("First message: %s\n",h->getMessage(0).c_str());
free(h);
}
示例12: allocData
void
allocData()
{
assert(m_fileHandler.isOpen());
if(m_data.getData())
return;
policies::GetExtents< FileHandler > fileExtents(m_fileHandler);
typename Data::IdxType extents;
for(unsigned i=0; i<numDims; ++i)
extents[i] = fileExtents[i];
m_data.allocData(extents);
}
示例13: main
int main()
{
FileHandler* fh = FileHandler::GetInstance();
vector<Passenger*> passengers;
fh->ReadPassengers(passengers);
cout << "FIFO simulation start" << endl;
Simulator* simulator = Simulator::GetInstance();
Strategy* strategy = new FIFO();
vector<Passenger*> servedPassengers = simulator->Simulate(strategy, passengers);
simulator->GetEverageTicketingWaitingTime(servedPassengers);
fh->WritePassengers(servedPassengers, "result1.txt");
cout << "\nLTFO simulation start" << endl;
fh->ReadPassengers(passengers);
strategy = new LTFO();
servedPassengers = simulator->Simulate(strategy, passengers);
simulator->GetEverageTicketingWaitingTime(servedPassengers);
fh->WritePassengers(servedPassengers, "result2.txt");
return 0;
}
示例14: SoftKineticCamera
CameraHandler::CameraHandler()
{
inputData_depth = new CAMERA_DEPTH_TYPE[m_params.m_width*m_params.m_height];
inputData_rgb = new CAMERA_RGB_TYPE[m_params.m_width*m_params.m_height];
if(isFromCamera) {
char path[200] = {0};
FileHandler* fileHandler = FileHandler::Init();
fileHandler->GetPath("Video", "realTrial", path); // TODO: What is this real trial? You may want to get it from the user.
// TODO: THE SOFTKINETIC CONSTRUCTOR MUST CHECK THAT IT CAN READ FROM THE SERVER.
// OTHERWISE IT SHOULD RETURN FALSE.
if (FALSE
#ifdef BUILD_SOFTKINETIC
|| (m_camera = new SoftKineticCamera()) && m_camera->IsInitialized()
#endif
#ifdef BUILD_GIPCAM
|| (m_camera = new GIPCam()) && m_camera->IsInitialized()
#endif
#ifdef BUILD_PRIMESENSE
|| (m_camera = new PrimesenseCamera()) && m_camera->IsInitialized()
#endif
#ifdef BUILD_FROMFILE
|| (m_camera = new CameraFromFile(path)) && m_camera->IsInitialized()
#endif
)
{
m_params = *(m_camera->GetParameters());
}
else {
cout << "No camera found!" << endl;
exit(1); // TODO CHANGE
}
}
}
示例15: write
bool RADCompute::write(FileHandler &f, map<int, vector<vector<double> > > &linear_hist){
if(!f.is_open()) return false;
string err_msg = "";
bool aborted = false;
for(map<int, vector<vector<double> > >::iterator i = linear_hist.begin(); i != linear_hist.end(); ++i){
int class_label = i->first;
for(vector<vector<double> >::iterator j = i->second.begin(); j != i->second.end(); ++j){
int inst_idx = 0;
string inst_str = "";
for(vector<double>::iterator e = j->begin(); e != j->end(); ++e){
char buff[100];
sprintf(buff,"%d:%5.7f ",++inst_idx,*e);
inst_str += buff;
}
char *buff;
buff = (char *)malloc(sizeof(char)*(inst_str.size()+100));
sprintf(buff,"%d %s\n",class_label,inst_str.c_str());
inst_str = string(buff);
delete []buff;
bool worked = f << inst_str;
if(!worked){
aborted = true;
err_msg += "Failed to write: " + inst_str + " : to the file\n";
break;
}
}
if(aborted) break;
}
if(aborted){
cerr << err_msg << endl;
}
return !aborted;
}