Exemple #1
0
    inline
    void copy_file(const boost::filesystem::path& path_from,
                   const boost::filesystem::path& path_to)
    {
      // 4M bytes buffer...
      std::vector<char> buffer(4 * 1024 * 1024);

      int infile = 0;
      int outfile = 0;
      struct stat stat_from;

#if BOOST_FILESYSTEM_VERSION == 2
      const std::string file_from = path_from.native_file_string();
      const std::string file_to = path_to.native_file_string();
#else
      const std::string file_from = path_from.string();
      const std::string file_to = path_to.string();
#endif
      
      if (:: stat(file_from.c_str(), &stat_from) != 0
          || (infile = ::open(file_from.c_str(), O_RDONLY)) < 0
          || (outfile = ::open(file_to.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, stat_from.st_mode)) < 0) {

        if (infile >= 0) ::close(infile);
        throw std::runtime_error("copy file failed");
      }
      
      ssize_t sz = 0;
      ssize_t sz_read = 1;
      ssize_t sz_write = 0;
      
      while (sz_read > 0) {
        do
          sz_read = ::read(infile, &(*buffer.begin()), buffer.size());
        while (sz_read < 0 && errno == EINTR);

        if (sz_read <= 0) break;

        sz_write = 0;
        do {
          if ((sz = ::write(outfile, &(*(buffer.begin() + sz_write)), sz_read - sz_write)) < 0) {
            if (errno == EINTR)
              continue;
            else {
              sz_read = sz;
              break;
            }
          }
          sz_write += sz;
        } while (sz_write < sz_read);
      }
      if ( ::close( infile) < 0 ) sz_read = -1;
      if ( ::close( outfile) < 0 ) sz_read = -1;

      if ( sz_read < 0 )
        throw std::runtime_error("copy file failed");
    }
Exemple #2
0
 std::string system_error_prep(
   const std::string & who,
   const fs::path & path1,
   const fs::path & path2,
   int sys_err_code )
 {
   return who + ": \"" + path1.native_file_string()
     + "\", \"" + path2.native_file_string() + "\": "
     + system_message( sys_err_code );
 }
void fileview::open(const boost::filesystem::path& p)
{
   cow();
   std::ifstream is(p.native_file_string().c_str());
   if(!is)
   {
      std::string msg("Bad file name: ");
      msg += p.native_file_string();
      std::runtime_error e(msg);
      boost::throw_exception(e);
   }
   std::istreambuf_iterator<char> in(is);
   std::istreambuf_iterator<char> end;
   std::copy(in, end, std::back_inserter(pimpl->m_data));
}
Exemple #4
0
    sheet_tracker(const bfs::path& sheet_path,
                  const bfs::path& input_path) :
        callbacks_m(adobe::bind_to_sheet(sheet_m))
    {
        //  attach the VM to the sheet.
        sheet_m.machine_m.set_variable_lookup(boost::bind(&adobe::sheet_t::get, &sheet_m, _1));
    
        std::string     sheet_path_str(sheet_path.native_file_string());
        std::ifstream   sheet_stream(sheet_path_str.c_str());

        callbacks_m.add_cell_proc_m = 
            boost::bind(&sheet_tracker::add_cell_trap, boost::ref(*this), 
                        callbacks_m.add_cell_proc_m, _1, _2, _3, _4);
        callbacks_m.add_interface_proc_m =
            boost::bind(&sheet_tracker::add_interface_trap, boost::ref(*this), 
                        callbacks_m.add_interface_proc_m, _1, _2, _3, _4, _5, _6);

        if (!sheet_stream.is_open())
            std::cerr << "Could not open \"" << sheet_path_str << "\"!\n";

        // set up adam sheet
        adobe::parse(sheet_stream,
                     adobe::line_position_t("property model sheet"),
                     callbacks_m);

        sheet_m.set(parse_input_dictionary(input_path));

        sheet_m.update();
    }
Exemple #5
0
adobe::dictionary_t parse_input_dictionary(const bfs::path& input_path)
{
    std::string              path_str(input_path.native_file_string());
    std::ifstream            input_stream(path_str.c_str());
    adobe::array_t           token_stream;
    adobe::virtual_machine_t vm;

    if (!adobe::expression_parser(input_stream,
                                  adobe::line_position_t("input_dictionary")).is_expression(token_stream))
        return adobe::dictionary_t();

    vm.evaluate(token_stream);

    const adobe::dictionary_t result(vm.back().cast<adobe::dictionary_t>());

    vm.pop_back();

    std::cout << "--" << std::endl
              << "Initializing sheet with the following input dictionary: "
              << adobe::begin_asl_cel << result << adobe::end_asl_cel
              << std::endl
              << "--" << std::endl;

    return result;
}
Exemple #6
0
 std::string other_error_prep(
   const std::string & who,
   const fs::path & path1,
   const std::string & message )
 {
   return who + ": \"" + path1.native_file_string() + "\": " + message;
 }
Exemple #7
0
xmlDocPtr XMLSubstitute::load( const ::boost::filesystem::path& xmlFile)
{
#if BOOST_FILESYSTEM_VERSION > 2
    xmlDocPtr doc = xmlParseFile(  xmlFile.string().c_str() );
#else
    xmlDocPtr doc = xmlParseFile(  xmlFile.native_file_string().c_str() );
#endif

    if ( ! m_dictionary.empty() ) // dictionary empty => classic xmlParseFile()
    {
        xmlNodePtr original = xmlDocGetRootElement(doc);
        // create the context for xpath
        xmlXPathContextPtr xpathCtx;
        xpathCtx = xmlXPathNewContext(doc);
        SLM_ASSERT("xpathCtx not instanced", xpathCtx);

        xmlChar *xpathExpr= BAD_CAST "//Substitutions";
        xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);

        if(xpathObj->nodesetval->nodeNr > 0)
        {
            // substitution node exists perform the translation
            SLM_ASSERT("XMLSubstitute::load manage only one xmlNode substitution", xpathObj->nodesetval->nodeNr == 1);
            xmlNodePtr substitutionRules = xpathObj->nodesetval->nodeTab[0];
            substitute(original, substitutionRules, m_dictionary);
        }
    }

    return doc;
}
Exemple #8
0
void create_parents( const fs::path &dpath )
{
  string     err( "create_parent(): " );
  fs::path       branch( dpath.branch_path() );
  string     who("create_parents");

  if( dpath.empty() ) {
    err.append( "cannot create an empty path." );

    throw CannotCreateParents( err );
  }
  else if( !exists(dpath) ) {
    if( branch.empty() ) create_directory( dpath );
    else if( !exists(branch) ) {
      create_parents( branch );
      create_directory( dpath );
    }
    else if( is_directory(branch) ) create_directory( dpath );
    else {
      err.append( branch.native_file_string() ); err.append( " is not a directory." );

      throw CannotCreateParents( err );
    }
  }
  else if( !is_directory(dpath) ) {
    err.append( dpath.native_file_string() ); err.append( " is not a directory." );

    throw CannotCreateParents( err );
  }

  return;
}
Exemple #9
0
    inline std::string native_file_string(boost::filesystem::path const& p)
    {
#if BOOST_FILESYSTEM_VERSION >= 3
        return p.string();
#else
        return p.native_file_string();
#endif
    }
void file::open( const boost::filesystem::path& p, const char* mode )
{
    close();
    m_path = p;
    m_file = fopen( p.native_file_string().c_str(), mode );
    if( !m_file )
        THROW_GPM_EXCEPTION( "Error opening file %1%: %2%", %p  %strerror(errno));
}
Exemple #11
0
bool Sound::load(fs::path const& filename)
{	
	//cerr << "Loading sound: " << filename.native_file_string() << endl;
	m_sound = FSOUND_Sample_Load( FSOUND_FREE, filename.native_file_string().c_str(), FSOUND_HW3D | FSOUND_FORCEMONO, 0, 0 );
	if ( m_sound )
	{
		return true;
	}
	return false;
}
Exemple #12
0
std::string read_file(const boost::filesystem::path &path) {
    FILE *in = fopen(path.native_file_string().c_str(), "rb");
    if (in == NULL)
        throw std::exception("Cannot open manifest file");
    std::string buffer;
    while (!feof(in)) {
        size_t begin = buffer.size();
        buffer.resize(begin + BLOCK_SIZE);
        size_t read = fread(&buffer[begin], sizeof(char), BLOCK_SIZE, in);
        if (ferror(in))
            throw std::exception("Error reading manifest file");
        buffer.resize(begin + read);
    }
    fclose(in);
    if (ferror(in))
        throw std::exception("Error closing manifest file");
    return buffer;
}
	void file::open(boost::filesystem::path const& p, open_mode m)
	{
		assert(p.is_complete());
		m_impl->open(p.native_file_string().c_str(), impl::open_flags(m.m_mask));
	}
void SaveImage( boost::filesystem::path path, cv::Mat image )
{
    cv::imwrite( path.native_file_string(), image );
}
void SaveOpticalFlowMap( boost::filesystem::path opticalFlowMapPath, cv::Mat opticalFlowMap )
{
    std::ofstream file( opticalFlowMapPath.native_file_string().c_str(), std::ios::binary );
    file.write( (char*)opticalFlowMap.data, opticalFlowMap.rows * opticalFlowMap.cols * sizeof( cv::Vec2f ) );
    file.close();
}
Exemple #16
0
bool SpriteSet::load(fs::path const& filename)
{	
	//cerr << "Loading sprite set: " << filename.native_file_string() << endl;
	
	BITMAP *tempBitmap = gfx.loadBitmap(filename.native_file_string().c_str(), 0, true);
	
	if (!tempBitmap)
		return false;
		
	LocalSetColorConversion cc(COLORCONV_NONE);
	LocalSetColorDepth cd(bitmap_color_depth(tempBitmap));

	if ( (tempBitmap->w > 1) && (tempBitmap->h > 1) )
	{
		int lastY = 1;
		int pivotY = -1;
		angleCount = 0;
		
		for (int y = 1; y < tempBitmap->h; ++y)
		{
			if( gfx.compareRGB(getpixel(tempBitmap,0,y),makecol(255,0,0)) ) // Red pixel marks the pivot of the sprite
			{
				pivotY = y-lastY;
			}
			else if( gfx.compareRGB(getpixel(tempBitmap,0,y), 0) || y == tempBitmap->h - 1 )
			{
				++angleCount;
				
				int lastX = 1;
				int pivotX = -1;
				frameCount = 0;
				
				for (int x = 1; x < tempBitmap->w; ++x)
				{
					// Pivot again but for X axis
					if( gfx.compareRGB(getpixel(tempBitmap,x,0), makecol(255,0,0)) )
					{
						pivotX = x-lastX;
					}
					else if(gfx.compareRGB(getpixel(tempBitmap,x,0), 0) || x == tempBitmap->w - 1 )
					{
						BITMAP* spriteFrame = create_bitmap(x-lastX+1, y-lastY+1);
						blit(tempBitmap, spriteFrame, lastX, lastY, 0, 0, spriteFrame->w, spriteFrame->h);
						//m_frames.back().push_back(new Sprite( spriteFrame, pivotX, pivotY ) );
						m_frames.push_back(new Sprite( spriteFrame, pivotX, pivotY ) );
						++frameCount;
						
						pivotX = -1;
						
						lastX = x + 1;
					}
				}

				pivotY = -1;
				lastY = y + 1;
			}
		}
			
		// Fill the other 180º with the sprites but mirrored.

	}

	destroy_bitmap(tempBitmap);
	
	m_angleFactor = (angleCount - 1) * 2;
	m_halfAngleDivisonSize = (1 << 15) / angleCount / 2;

	return true;
}