Пример #1
0
 bool signed_by( const address& a ) {
    if( !available_address_sigs ) {
       available_address_sigs = std::map<address,public_key_type>();
       provided_address_sigs = std::map<address,public_key_type>();
       for( auto& item : available_keys ) {
        (*available_address_sigs)[ address(pts_address(item, false, 56) ) ] = item;
        (*available_address_sigs)[ address(pts_address(item, true, 56) ) ] = item;
        (*available_address_sigs)[ address(pts_address(item, false, 0) ) ] = item;
        (*available_address_sigs)[ address(pts_address(item, true, 0) ) ] = item;
        (*available_address_sigs)[ address(item) ] = item;
       }
       for( auto& item : provided_signatures ) {
        (*provided_address_sigs)[ address(pts_address(item.first, false, 56) ) ] = item.first;
        (*provided_address_sigs)[ address(pts_address(item.first, true, 56) ) ] = item.first;
        (*provided_address_sigs)[ address(pts_address(item.first, false, 0) ) ] = item.first;
        (*provided_address_sigs)[ address(pts_address(item.first, true, 0) ) ] = item.first;
        (*provided_address_sigs)[ address(item.first) ] = item.first;
       }
    }
    auto itr = provided_address_sigs->find(a);
    if( itr == provided_address_sigs->end() )
    {
       auto aitr = available_address_sigs->find(a);
       if( aitr != available_address_sigs->end() ) {
          auto pk = available_keys.find(aitr->second);
          if( pk != available_keys.end() )
             return provided_signatures[aitr->second] = true;
          return false;
       }
    }
    return provided_signatures[itr->second] = true;
 }
Пример #2
0
void
ThreadedLoader::load_patch(bool                              merge,
                           const Glib::ustring&              document_uri,
                           optional<Path>                    engine_parent,
                           optional<Symbol>                  engine_symbol,
                           optional<GraphObject::Properties> engine_data)
{
	_mutex.lock();

	Ingen::Shared::World* world = App::instance().world();

	Glib::ustring engine_base = "";
	if (engine_parent) {
		if (merge)
			engine_base = engine_parent.get().str();
		else
			engine_base = engine_parent.get().base();
	}

	_events.push_back(
		sigc::hide_return(
			sigc::bind(sigc::mem_fun(world->parser().get(),
			                         &Ingen::Serialisation::Parser::parse_file),
			           App::instance().world(),
			           App::instance().world()->engine().get(),
			           document_uri,
			           engine_parent,
			           engine_symbol,
			           engine_data)));

	whip();

	_mutex.unlock();
}
Пример #3
0
/// Stores a file generated by a test case into the database as a BLOB.
///
/// \param name The name of the file to store in the database.  This needs to be
///     unique per test case.  The caller is free to decide what names to use
///     for which files.  For example, it might make sense to always call
///     __STDOUT__ the stdout of the test case so that it is easy to locate.
/// \param path The path to the file to be stored.
/// \param test_case_id The identifier of the test case this file belongs to.
///
/// \return The identifier of the stored file, or none if the file was empty.
///
/// \throw store::error If there are problems writing to the database.
optional< int64_t >
store::write_transaction::put_test_case_file(const std::string& name,
                                             const fs::path& path,
                                             const int64_t test_case_id)
{
    LD(F("Storing %s (%s) of test case %s") % name % path % test_case_id);
    try {
        const optional< int64_t > file_id = put_file(_pimpl->_db, path);
        if (!file_id) {
            LD("Not storing empty file");
            return none;
        }

        sqlite::statement stmt = _pimpl->_db.create_statement(
            "INSERT INTO test_case_files (test_case_id, file_name, file_id) "
            "VALUES (:test_case_id, :file_name, :file_id)");
        stmt.bind(":test_case_id", test_case_id);
        stmt.bind(":file_name", name);
        stmt.bind(":file_id", file_id.get());
        stmt.step_without_results();

        return optional< int64_t >(_pimpl->_db.last_insert_rowid());
    } catch (const sqlite::error& e) {
        throw error(e.what());
    }
}
Пример #4
0
void cowsay(Console & drawConsole, const string & name,
            const optional<string> & text,
            const optional<int> & xOffset,
            bool noSkip)
{
    const auto image = loadImage(name + ".bmp");

    ConsoleStuff console;

    if (text)
    {
        auto wordWidth = image.Width() / console.GetFontSize().X;
        if (text.get().size() < wordWidth)
        {
            wordWidth = text.get().size();
        }
        wordBubble(text.get(), (image.Width() / console.GetFontSize().X));
    }

    const int linesToSkip = noSkip ? 0
                                   : image.Height() / console.GetFontSize().Y;

    for (size_t n = 0; n < linesToSkip; ++ n) {
        std::cout << "\n";
    }

    auto textCoordinates = console.GetTextCoordinates();
    auto c = console.ToPixelCoordinates(
        {textCoordinates.X + xOffset.get_value_or(0),
         textCoordinates.Y - linesToSkip});

    drawCow(drawConsole, c, image);
}
Пример #5
0
int main()
{
    {
        const optional<X> opt; ((void)opt);
        ASSERT_NOT_NOEXCEPT(opt.value());
        ASSERT_SAME_TYPE(decltype(opt.value()), X const&);
    }
    {
        constexpr optional<X> opt(in_place);
        static_assert(opt.value().test() == 3, "");
    }
    {
        const optional<X> opt(in_place);
        assert(opt.value().test() == 3);
    }
#ifndef TEST_HAS_NO_EXCEPTIONS
    {
        const optional<X> opt;
        try
        {
            (void)opt.value();
            assert(false);
        }
        catch (const bad_optional_access&)
        {
        }
    }
#endif
}
void test_function_value_for()
{
  optional<T> o0;
  optional<T> o1(1);
  const optional<T> oC(2);
  
  try
  {
    T& v = o1.value();
    BOOST_TEST(v == 1);
  }
  catch(...)
  {
    BOOST_TEST(false);
  }
  
  try
  {
    T const& v = oC.value();
    BOOST_TEST(v == 2);
  }
  catch(...)
  {
    BOOST_TEST(false);
  }
  
  BOOST_TEST_THROWS(o0.value(), boost::bad_optional_access);
}
Пример #7
0
void
ThreadedLoader::load_graph(bool                       merge,
                           const Glib::ustring&       document_uri,
                           optional<Raul::Path>       engine_parent,
                           optional<Raul::Symbol>     engine_symbol,
                           optional<Node::Properties> engine_data)
{
	_mutex.lock();

	Ingen::World* world = _app.world();

	Glib::ustring engine_base = "";
	if (engine_parent) {
		if (merge)
			engine_base = engine_parent.get();
		else
			engine_base = engine_parent.get().base();
	}

	_events.push_back(
		sigc::hide_return(
			sigc::bind(sigc::mem_fun(world->parser().get(),
			                         &Ingen::Serialisation::Parser::parse_file),
			           _app.world(),
			           _app.world()->interface().get(),
			           document_uri,
			           engine_parent,
			           engine_symbol,
			           engine_data)));

	_mutex.unlock();
	_sem.post();
}
Пример #8
0
TEST(Optional, Constexpr)
{
	constexpr auto string = "abcdefgh";
	constexpr optional<int> a{32};
	constexpr optional<decltype(string)> b{string};
	constexpr optional<float> c{3.14f};
	constexpr optional<int> d{};
	
	EXPECT_THAT(*a, Eq(32));
	EXPECT_THAT(*b, Eq(string));
	EXPECT_THAT(*c, FloatEq(3.14f));
	EXPECT_FALSE(d);
	
	constexpr int i = *a;
	constexpr int j = a.value();
	
	EXPECT_THAT(i, Eq(*a));
	EXPECT_THAT(j, Eq(*a));
	
	struct Literal { };
	
	static_assert(std::is_literal_type<optional<int>>::value, "Type error");
	static_assert(std::is_literal_type<optional<float>>::value, "Type error");
	static_assert(std::is_literal_type<optional<Literal>>::value, "Type error");
}
Пример #9
0
static const abi_serializer& get_abi_serializer() {
   static optional<abi_serializer> _abi_serializer;
   if (!_abi_serializer) {
      _abi_serializer.emplace(eosio_contract_abi(abi_def()));
   }

   return *_abi_serializer;
}
Пример #10
0
void
CachePolicy::mergeAndOverride(const optional<CachePolicy>& rhs)
{
    if ( rhs.isSet() )
    {
        mergeAndOverride( rhs.get() );
    }
}
Пример #11
0
	bool operator==( const optional<T>& left, const optional<T>& right ) {
		if ( left && right ) {
			return left.value( ) == right.value( );
		}
		else if ( !left && !right ) {
			return true;
		}
		return false;
	}
Пример #12
0
 bool const operator==(optional const & other) const {
     if (!valid() && !other.valid()) {
         return true;
     }
     
     if (valid() ^ other.valid()) {
         return false;
     }
     
     return ((**this) == (*other));
 }
Пример #13
0
 Source_location(
     string              filename,
     optional<int>       linenumber          = {},
     optional<int>       character_position  = {},
     optional<string>    function_name       = {}
     ):
     m_filename{ move( filename ) },
     m_linenumber{ linenumber.value_or( -1 ) },
     m_character_position{ character_position.value_or( -1 ) },
     m_function_name{ move( function_name ).value_or( "" ) }
 {}
Пример #14
0
	// Вспомогательная функция для проверки работы команды command
	// Она принимает ожидаемый номер канала expectedChannel и expectedOutput
	void VerifyCommandHandling(const string& command, const optional<int> & expectedChannel, const string& expectedOutput)
	{
		// Предварительно очищаем содержимое выходного потока
		output = stringstream();
		input = stringstream();
		BOOST_CHECK(input << command);
		BOOST_CHECK(remoteControl.HandleCommand());
		BOOST_CHECK_EQUAL(tv.IsTurnedOn(), expectedChannel.is_initialized());
		BOOST_CHECK_EQUAL(tv.GetChannel(), expectedChannel.get_value_or(0));
		BOOST_CHECK(input.eof());
		BOOST_CHECK_EQUAL(output.str(), expectedOutput);
	}
Пример #15
0
    static void affect( value& v, optional< T > const& opt )
    {
      if( opt.is_none() )
	{
	  v = Val_int( 0 );
	}
      else
	{
	  v = caml_alloc_tuple(1);
	  field_affectation_management< T >::affect_field(v, 0, opt.get_value() );
	}
    }
Пример #16
0
		void swap(optional& other) {
			if (other.valid() && valid()) {
				swap(**this, *other);
			}
			else if (!other.valid() && !valid()) {
				return;
			}
			optional& source = other ? *this : other;
			optional& target = other ? other : *this;
			target.unchecked_place(std::move(*source));
			source.unchecked_destroy();
		}
void test_function_value_or_for()
{
  optional<T> oM0;
  const optional<T> oC0;
  optional<T> oM1(1);
  const optional<T> oC2(2);
  
  BOOST_TEST(oM0.value_or(5) == 5);
  BOOST_TEST(oC0.value_or(5) == 5);
  BOOST_TEST(oM1.value_or(5) == 1);
  BOOST_TEST(oC2.value_or(5) == 2);
}
Пример #18
0
void IndexSync::createMetadata(const optional<string>& keyPath, const bool unique)
	{
	this->keyPath = keyPath;
	this->unique = unique;

	auto_ptr<Implementation::Transaction> transaction = transactionFactory.createTransaction();

	metadata.putMetadata("unique", Data(&unique, sizeof(bool), Data::Boolean), true, *transaction);
	metadata.putMetadata("keyPath", keyPath.is_initialized() ? Data(keyPath.get()) : Data::getUndefinedData(), true, *transaction);
	
	transaction->commit();
	}
Пример #19
0
Map::Map( const MapOptions& options ) :
osg::Referenced      ( true ),
_mapOptions          ( options ),
_initMapOptions      ( options ),
_dataModelRevision   ( 0 )
{
    if (_mapOptions.cachePolicy().isSet() &&
        _mapOptions.cachePolicy()->usage() == CachePolicy::USAGE_CACHE_ONLY )
    {
        OE_INFO << LC << "CACHE-ONLY MODE activated from map" << std::endl;
    }

    // if the map was a cache policy set, make this the system-wide default, UNLESS
    // there ALREADY IS a registry default, in which case THAT will override THIS one.
    // (In other words, whichever one is set first wins. And of course, if the registry
    // has an override set, that will cancel out all of this.)
    const optional<CachePolicy> regCachePolicy = Registry::instance()->defaultCachePolicy();

    if ( _mapOptions.cachePolicy().isSet() )
    {
        if ( !regCachePolicy.isSet() )
        {
            Registry::instance()->setDefaultCachePolicy( *_mapOptions.cachePolicy() );
            OE_INFO << LC 
                << "Setting default cache policy from map ("
                << _mapOptions.cachePolicy()->usageString() << ")" << std::endl;
        }
        else
        {
            _mapOptions.cachePolicy() = *regCachePolicy;
            OE_INFO << LC
                << "Settings map caching policy to default ("
                << _mapOptions.cachePolicy()->usageString() << ")" << std::endl;
        }
    }
    else if ( regCachePolicy.isSet() )
    {
        _mapOptions.cachePolicy() = *regCachePolicy;
        OE_INFO << LC
            << "Settings map caching policy to default ("
            << _mapOptions.cachePolicy()->usageString() << ")" << std::endl;
    }

    // the map-side dbOptions object holds I/O information for all components.
    _dbOptions = osg::clone( Registry::instance()->getDefaultOptions() );

    // we do our own caching
    _dbOptions->setObjectCacheHint( osgDB::Options::CACHE_NONE );

    // store the IO information in the top-level DB Options:
    _mapOptions.cachePolicy()->apply( _dbOptions.get() );
    URIContext( _mapOptions.referrer() ).apply( _dbOptions.get() );
}
Пример #20
0
bool
operator==(
	optional<T> const &_a,
	optional<T> const &_b
)
{
	return
		_a && _b
		?
			*_a == *_b
		:
			_a.has_value() == _b.has_value();
}
Пример #21
0
	bool const operator < (optional const & other) const
	{
		// equally invalid - not smaller.
		if ((! valid()) && (! other.valid()))   { return false; }

		// I'm not valid, other must be, smaller.
		if (! valid())	{ return true; }

		// I'm valid, other is not valid, I'm larger
		if (! other.valid()) { return false; }

		return ((* * this) < (* other));
	}
Пример #22
0
void SpacePage::addBullet(Vector pos, Vector dir, PlayerID owner)
{
    static optional<Gosu::Sample> s_Sample;
    if (!s_Sample) {
        s_Sample.reset(Gosu::Sample(L"sfx/phaser1.wav"));
    }
    s_Sample->play();
    Bullet b;
    b.pos = pos;
    b.dir = dir.normalized()*10;
    b.lifetime = 0;
    b.owner = owner;
    m_Bullets.push_back(b);
}
Пример #23
0
void other_thread()
{

  std::cout << __FILE__ << ":" << __LINE__ << boost::this_thread::get_id() << std::endl;
  optr = none;
  std::cout << __FILE__ << ":" << __LINE__ << boost::this_thread::get_id() << std::endl;
  optr = in_place();
  std::cout << __FILE__ << ":" << __LINE__ << boost::this_thread::get_id() << std::endl;
  BOOST_TEST(optr->get() == 0);
  this_thread::sleep(posix_time::seconds(5));
  BOOST_TEST(optr->get() == 0);
  std::cout << __FILE__ << ":" << __LINE__ << boost::this_thread::get_id() << std::endl;

}
Пример #24
0
int main()
{
    {
        constexpr optional<X> opt(X{});
        static_assert(opt->test() == 3, "");
    }
#ifdef _LIBCPP_DEBUG
    {
        optional<X> opt;
        assert(opt->test() == 3);
        assert(false);
    }
#endif  // _LIBCPP_DEBUG
}
Пример #25
0
LatLng Transform::getLatLng(optional<EdgeInsets> padding) const {
    if (padding && *padding) {
        return screenCoordinateToLatLng(padding->getCenter(state.width, state.height));
    } else {
        return state.getLatLng();
    }
}
inline void check_ref_value_const ( optional<T&> const& opt, T const& v, T const& z )
{
  BOOST_CHECK( *opt == v ) ;
  BOOST_CHECK( *opt != z ) ;
  BOOST_CHECK( opt.get() == v ) ;
  BOOST_CHECK( opt.get() != z ) ;
}
Пример #27
0
void wpi::write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style,
                     optional<size_t> Width) {
  const size_t kMaxWidth = 128u;

  size_t W = std::min(kMaxWidth, Width.value_or(0u));

  unsigned Nibbles = (64 - countLeadingZeros(N) + 3) / 4;
  bool Prefix = (Style == HexPrintStyle::PrefixLower ||
                 Style == HexPrintStyle::PrefixUpper);
  bool Upper =
      (Style == HexPrintStyle::Upper || Style == HexPrintStyle::PrefixUpper);
  unsigned PrefixChars = Prefix ? 2 : 0;
  unsigned NumChars =
      std::max(static_cast<unsigned>(W), std::max(1u, Nibbles) + PrefixChars);

  char NumberBuffer[kMaxWidth];
  ::memset(NumberBuffer, '0', wpi::array_lengthof(NumberBuffer));
  if (Prefix)
    NumberBuffer[1] = 'x';
  char *EndPtr = NumberBuffer + NumChars;
  char *CurPtr = EndPtr;
  while (N) {
    unsigned char x = static_cast<unsigned char>(N) % 16;
    *--CurPtr = hexdigit(x, !Upper);
    N /= 16;
  }

  S.write(NumberBuffer, NumChars);
}
Пример #28
0
/// Gets the path to the store directory.
///
/// Note that this function does not create the determined directory.  It is the
/// responsibility of the caller to do so.
///
/// \return Path to the directory holding all the database files.
fs::path
layout::query_store_dir(void)
{
    const optional< fs::path > home = utils::get_home();
    if (home) {
        const fs::path& home_path = home.get();
        if (home_path.is_absolute())
            return home_path / ".kyua/store";
        else
            return home_path.to_absolute() / ".kyua/store";
    } else {
        LW("HOME not defined; creating store database in current "
           "directory");
        return fs::current_path();
    }
}
 // for icons
 // Icons collision features are always SymbolPlacementType::Point, which means the collision feature
 // will be viewport-rotation-aligned even if the icon is map-rotation-aligned (e.g. `icon-rotation-alignment: map`
 // _or_ `symbol-placement: line`). We're relying on most icons being "close enough" to square that having
 // incorrect rotation alignment doesn't throw off collision detection too much.
 // See: https://github.com/mapbox/mapbox-gl-js/issues/4861
 CollisionFeature(const GeometryCoordinates& line,
                  const Anchor& anchor,
                  optional<PositionedIcon> shapedIcon,
                  const float boxScale,
                  const float padding,
                  const IndexedSubfeature& indexedFeature_,
                  const float rotate)
     : CollisionFeature(line, anchor,
                        (shapedIcon ? shapedIcon->top() : 0),
                        (shapedIcon ? shapedIcon->bottom() : 0),
                        (shapedIcon ? shapedIcon->left() : 0),
                        (shapedIcon ? shapedIcon->right() : 0),
                        boxScale,
                        padding,
                        style::SymbolPlacementType::Point,
                        indexedFeature_, 1, rotate) {}
Пример #30
0
ScreenCoordinate Transform::getScreenCoordinate(optional<EdgeInsets> padding) const {
    if (padding && *padding) {
        return padding->getCenter(state.width, state.height);
    } else {
        return { state.width / 2., state.height / 2. };
    }
}