Example #1
0
		virtual const std::string do_type() const throw ()
		{
			//
			// A real application should use OS facilities for this.  This
            // is a crude hack because sdl-viewer uses std::filebuf in
            // order to remain simple and portable.
			//
			using std::find;
			using std::string;
			using boost::algorithm::iequals;
			using boost::next;
			string media_type = "application/octet-stream";
			const string::const_reverse_iterator dot_pos =
				find(this->url_.rbegin(), this->url_.rend(), '.');
			if (dot_pos == this->url_.rend()
				|| next(dot_pos.base()) == this->url_.end()) {
				return media_type;
			}
			const string::const_iterator hash_pos =
				find(next(dot_pos.base()), this->url_.end(), '#');
			const string ext(dot_pos.base(), hash_pos);
			if (iequals(ext, "wrl")) {
                media_type = openvrml::vrml_media_type;
			} else if (iequals(ext, "x3dv")) {
                media_type = openvrml::x3d_vrml_media_type;
			} else if (iequals(ext, "png")) {
				media_type = "image/png";
			} else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) {
				media_type = "image/jpeg";
			}
			return media_type;
		}
Example #2
0
 virtual const std::string do_type() const throw ()
 {
     //
     // A real application should use OS facilities for this.  This
     // is a crude hack.
     //
     using std::find;
     using std::string;
     using boost::algorithm::iequals;
     using boost::next;
     string media_type = "application/octet-stream";
     const string::const_reverse_iterator dot_pos =
         find(this->url_.rbegin(), this->url_.rend(), '.');
     if (dot_pos == this->url_.rend()
             || next(dot_pos.base()) == this->url_.end()) {
         return media_type;
     }
     const string::const_iterator hash_pos =
         find(next(dot_pos.base()), this->url_.end(), '#');
     const string ext(dot_pos.base(), hash_pos);
     if (iequals(ext, "wrl")) {
         media_type = "model/vrml";
     } else if (iequals(ext, "x3dv")) {
         media_type = "model/x3d+vrml";
     } else if (iequals(ext, "png")) {
         media_type = "image/png";
     } else if (iequals(ext, "jpg") || iequals(ext, "jpeg")) {
         media_type = "image/jpeg";
     }
     return media_type;
 }
		void add_rule(Addr first, Addr last, int flags)
		{
			using boost::next;
			using boost::prior;

			TORRENT_ASSERT(!m_access_list.empty());
			TORRENT_ASSERT(first < last || first == last);
			
			typename range_t::iterator i = m_access_list.upper_bound(first);
			typename range_t::iterator j = m_access_list.upper_bound(last);

			if (i != m_access_list.begin()) --i;
			
			TORRENT_ASSERT(j != m_access_list.begin());
			TORRENT_ASSERT(j != i);
			
			int first_access = i->access;
			int last_access = prior(j)->access;

			if (i->start != first && first_access != flags)
			{
				i = m_access_list.insert(i, range(first, flags));
			}
			else if (i != m_access_list.begin() && prior(i)->access == flags)
			{
				--i;
				first_access = i->access;
			}
			TORRENT_ASSERT(!m_access_list.empty());
			TORRENT_ASSERT(i != m_access_list.end());

			if (i != j) m_access_list.erase(next(i), j);
			if (i->start == first)
			{
				// we can do this const-cast because we know that the new
				// start address will keep the set correctly ordered
				const_cast<Addr&>(i->start) = first;
				const_cast<int&>(i->access) = flags;
			}
			else if (first_access != flags)
			{
				m_access_list.insert(i, range(first, flags));
			}
			
			if ((j != m_access_list.end()
					&& minus_one(j->start) != last)
				|| (j == m_access_list.end()
					&& last != max_addr<Addr>()))
			{
				TORRENT_ASSERT(j == m_access_list.end() || last < minus_one(j->start));
				if (last_access != flags)
					j = m_access_list.insert(j, range(plus_one(last), last_access));
			}

			if (j != m_access_list.end() && j->access == flags) m_access_list.erase(j);
			TORRENT_ASSERT(!m_access_list.empty());
		}