void load(const std::string& filename){ std::ios_base::openmode mode = std::ios::in; std::ifstream ifs(filename.c_str(), mode); if (ifs.fail()){ throw UnableToOpenFileException(); } boost::archive::text_iarchive ia(ifs); ia >> * dynamic_cast< std::map<std::string, std::string>* > (this); }
/** Constructor. * Independent of the FileOpenMethod files are created with * permissions 660 * @param filename the filename * @param method the method determines what is done if a file with the * specified name already exists */ File::File(const char *filename, FileOpenMethod method) { fd = -1; switch (method) { case OVERWRITE: fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); fn = strdup(filename); break; case APPEND: fd = open(filename, O_RDWR | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); fn = strdup(filename); break; case ADD_SUFFIX: { char *filename_ext = strdup(filename); int index = 0; while (File::exists(filename_ext)) { free(filename_ext); if ( asprintf(&filename_ext, "%s.%d", filename, ++index) == -1 ) { throw OutOfMemoryException("Could not allocate filename string"); } } fd = open(filename_ext, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); fn = filename_ext; } break; default: printf("%s [line %d]: Unkown method.\n", __FILE__, __LINE__); } if (-1 == fd) { throw UnableToOpenFileException(filename, errno); } fp = fdopen(fd, "r+"); }
void xncv::VideoSource::init(const std::string& file) { recorder = nullptr; isFile = !file.empty(); if (context.Init() != XN_STATUS_OK) throw std::runtime_error("Unable to init context"); if (isFile) { if (context.OpenFileRecording(file.c_str(), player) != XN_STATUS_OK) throw UnableToOpenFileException(file); if (context.FindExistingNode(XN_NODE_TYPE_IMAGE, imgGen) != XN_STATUS_OK) throw UnableToInitGenerator("Unable to init image generator."); if (context.FindExistingNode(XN_NODE_TYPE_DEPTH, depthGen) != XN_STATUS_OK) throw UnableToInitGenerator("Unable to depth generator."); return; } if (imgGen.Create(context) != XN_STATUS_OK) throw UnableToInitGenerator("Unable to init image generator."); if (depthGen.Create(context) != XN_STATUS_OK) throw UnableToInitGenerator("Unable to depth generator."); }