• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ boost::any类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中boost::any的典型用法代码示例。如果您正苦于以下问题:C++ any类的具体用法?C++ any怎么用?C++ any使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了any类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: check_first_occurrence

 BOOST_PROGRAM_OPTIONS_DECL 
 void check_first_occurrence(const boost::any& value)
 {
     if (!value.empty())
         boost::throw_exception(
             multiple_occurrences("multiple_occurrences"));
 }
开发者ID:AndroidAppList,项目名称:Android-Supertux,代码行数:7,代码来源:value_semantic.cpp


示例2: validate

void validate(boost::any &v, std::vector<std::string> const &tokens, FallbackMap*, int)
{
    if(v.empty())
    {
        v = boost::any(FallbackMap());
    }

    FallbackMap *map = boost::any_cast<FallbackMap>(&v);

    for(std::vector<std::string>::const_iterator it=tokens.begin(); it != tokens.end(); ++it)
    {
        int sep = it->find(",");
        if(sep < 1 || sep == (int)it->length()-1)
#if (BOOST_VERSION < 104200)
            throw boost::program_options::validation_error("invalid value");
#else
            throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
#endif

        std::string key(it->substr(0,sep));
        std::string value(it->substr(sep+1));

        if(map->mMap.find(key) == map->mMap.end())
        {
            map->mMap.insert(std::make_pair (key,value));
        }
    }
}
开发者ID:Kafou1,项目名称:openmw,代码行数:28,代码来源:main.cpp


示例3: xparse

 void xparse(boost::any& v, std::vector<std::basic_string<charT> > const&) const
 {
     // if this is the first occurrence of the option, initialize it to the origin
     if (v.empty()) {
         v = boost::any(origin_);
     }
     ++boost::any_cast<T&>(v);
 }
开发者ID:fhoefling,项目名称:halmd,代码行数:8,代码来源:program_options.hpp


示例4: ConvertFromAnyImpl

typename std::enable_if<std::is_copy_constructible<T>::value && std::is_nothrow_destructible<T>::value, T>::type
ConvertFromAnyImpl(const boost::any& value)
{
    if(value.type() == typeid(T))
        return boost::any_cast<T>(value);
    else
        return T(); //TODO: Add a warning
}
开发者ID:MORTAL2000,项目名称:YAPG,代码行数:8,代码来源:LuaAnyConversions.hpp


示例5: setConfigurationSetting

void WTextEdit::setConfigurationSetting(const std::string& name, 
					const boost::any& value)
{
  if (!value.empty())
    configurationSettings_[name] = value;
  else
    configurationSettings_.erase(name);
}
开发者ID:caseymcc,项目名称:wt,代码行数:8,代码来源:WTextEdit.C


示例6: parse

 /// Every appearance of the option simply increments the value
 //
 /// There should never be any tokens.
 virtual void parse(boost::any& value_store,
                    const std::vector<std::string>& new_tokens,
                    bool /*utf8*/) const
 {
     assert(new_tokens.empty());
     if (value_store.empty()) value_store = T();
     boost::any_cast<T&>(value_store) += _interval;
 }
开发者ID:Mathias1000,项目名称:sqlassie,代码行数:11,代码来源:accumulator.hpp


示例7: set_value

    void table::set_value(const std::string& column_name,
        const boost::any& value)
    {
        // You can not insert a value without a row to put it in.
        assert(m_rows > 0);

        // You must create the column before you insert values
        assert(has_column(column_name));

        // You cannot insert values into a constant column
        assert(!is_constant(column_name));

        auto& c = m_columns.at(column_name);
        c->set_value(value);
        assert(value.empty() ||
               c->type_hash() == value.type().hash_code());
    }
开发者ID:GOPRO1955,项目名称:tables,代码行数:17,代码来源:table.cpp


示例8: parse

 /**
  * @brief Parse options
  *
  * Every appearance of the option simply increments the value
  * There should never be any tokens.
  */
 virtual void
 parse(boost::any& value_store,
       const std::vector<std::string>& new_tokens,
       bool utf8) const final
 {
   if (value_store.empty())
     value_store = T();
   boost::any_cast<T&>(value_store) += m_interval;
 }
开发者ID:named-data-ndnSIM,项目名称:ndn-cxx,代码行数:15,代码来源:util.hpp


示例9: euclidianNormSquared

        inline
        double euclidianNormSquared( Iterator it, const Iterator end, int num_components, const boost::any& pinfo = boost::any() )
        {
            static_cast<void>(num_components); // Suppress warning in the serial case.
            static_cast<void>(pinfo); // Suppress warning in non-MPI case.
#if HAVE_MPI
            if ( pinfo.type() == typeid(ParallelISTLInformation) )
            {
                const ParallelISTLInformation& info =
                    boost::any_cast<const ParallelISTLInformation&>(pinfo);
                typedef typename Iterator::value_type Scalar;
                Scalar product = 0.0;
                int size_per_component = (end - it);
                size_per_component /= num_components; // two lines to supresse unused warning.
                assert((end - it) == num_components * size_per_component);

                if( num_components == 1 )
                {
                    auto component_container =
                        boost::make_iterator_range(it, end);
                    info.computeReduction(component_container,
                                           Opm::Reduction::makeInnerProductFunctor<double>(),
                                           product);
                }
                else
                {
                    auto& maskContainer = info.getOwnerMask();
                    auto mask = maskContainer.begin();
                    assert(static_cast<int>(maskContainer.size()) == size_per_component);

                    for(int cell = 0; cell < size_per_component; ++cell, ++mask)
                    {
                        Scalar cell_product = (*it) * (*it);
                        ++it;
                        for(int component=1; component < num_components;
                            ++component, ++it)
                        {
                            cell_product += (*it) * (*it);
                        }
                        product += cell_product * (*mask);
                    }
                }
                return info.communicator().sum(product);
            }
            else
#endif
            {
                double product = 0.0 ;
                for( ; it != end; ++it ) {
                    product += ( *it * *it );
                }
                return product;
            }
        }
开发者ID:blattms,项目名称:opm-simulators,代码行数:54,代码来源:BlackoilDetails.hpp


示例10:

 void 
 untyped_value::xparse(boost::any& value_store,
                       const std::vector<std::string>& new_tokens) const
 {
     if (!value_store.empty()) 
         boost::throw_exception(
             multiple_occurrences());
     if (new_tokens.size() > 1)
         boost::throw_exception(multiple_values());
     value_store = new_tokens.empty() ? std::string("") : new_tokens.front();
 }
开发者ID:AngryPowman,项目名称:vnoc,代码行数:11,代码来源:value_semantic.cpp


示例11: update

void Object::update(const std::string& name, const boost::any& value)
    throw (boost::bad_any_cast)
{
    check_field(name, value);
    if (!fields_[name].empty() && fields_[name].type() != value.type())
    {
        throw boost::bad_any_cast();
    }
    fields_[name] = value;
    ui_.push(id(), name, value);
}
开发者ID:etoestja,项目名称:UniSched,代码行数:11,代码来源:object.cpp


示例12: SetOption

 void NetTransportServer::SetOption(boost::any const& opt)
 {
     ::network::OptionsUser net_opt;
     if (opt.empty()) {
         net_opt.max_pack_size_ = 64 * 1024;
         return ;
     }
     net_opt = boost::any_cast<::network::OptionsUser const&>(opt);
     s_.SetSndTimeout(net_opt.sndtimeo_);
     s_.SetMaxPackSize(net_opt.max_pack_size_);
 }
开发者ID:bobbyzhu,项目名称:ucorf,代码行数:11,代码来源:net_transport.cpp


示例13: setData

 bool setData(const Wt::WModelIndex& index, const boost::any& value,
              int role=Wt::EditRole) {
     if (role == Wt::CheckStateRole && value.type() == typeid(bool)) {
         dbo::Transaction t(fApp->session());
         const CommentPtr& o = resultRow(index.row());
         o.modify()->set_deleted(boost::any_cast<bool>(value));
         t.commit();
         dataChanged().emit(index, this->index(index.row(), text_column));
         return true;
     }
     return BaseQM::setData(index, value, Wt::EditRole);
 }
开发者ID:starius,项目名称:facts,代码行数:12,代码来源:CommentsWidget.cpp


示例14: QM_FAIL

boost::python::object any_extract<boost::python::object>(boost::any const& self)  {
	if(self.empty()) return boost::python::object(); // None
	if(is_any_int(self)) {
		return boost::python::object(boost::any_cast<int>(self));
	}
	if(is_any_float(self)) {
		return boost::python::object(boost::any_cast<double>(self));
	}
	//if(self.type() == typeid(json)) {
	//	return boost::python::object(*boost::any_cast<json>(self));
	//}
	QM_FAIL("boost::any unknown value type");
}
开发者ID:algotrust,项目名称:qmlib,代码行数:13,代码来源:json_wrap.cpp


示例15: convertFromMsParam

    error convertFromMsParam(boost::any& itr, msParam_t *t) {
        if(std::string(t->type).compare(STR_MS_T) == 0) {
            if(itr.type() == typeid(std::string *)) {
                *(boost::any_cast<std::string *>(itr)) = std::string(reinterpret_cast<char*>( t->inOutStruct) );
            }
        } else if (t->type) {
            replMsParam(t, boost::any_cast<msParam_t*>(itr));
        } else {
            return ERROR(-1, "type was null, cannot convert type");
        }

        return SUCCESS();
    }
开发者ID:QuarkDoe,项目名称:irods,代码行数:13,代码来源:irods_re_plugin.cpp


示例16: dc6

// mid-range positive decimals (fixed-point)
void dc6()
{
	ct.colWidth = 8;
	ct.constraintType = CalpontSystemCatalog::NO_CONSTRAINT;
	ct.colDataType = CalpontSystemCatalog::BIGINT;
	ct.scale = 1;
	ct.precision = 18;
	bool pushWarning;

	data = "123456789012345.6";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(long long));
	int64_t bigintval = static_cast<int64_t>(any_cast<long long>(anyval));
	CPPUNIT_ASSERT(bigintval == 1234567890123456LL);

	ct.scale = 3;

	data = "1234567890123.456";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(long long));
	bigintval = static_cast<int64_t>(any_cast<long long>(anyval));
	CPPUNIT_ASSERT(bigintval == 1234567890123456LL);

	ct.scale = 4;

	data = "123456789012.3456";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(long long));
	bigintval = static_cast<int64_t>(any_cast<long long>(anyval));
	CPPUNIT_ASSERT(bigintval == 1234567890123456LL);

}
开发者ID:EPICPaaS,项目名称:infinidb,代码行数:39,代码来源:tdriver.cpp


示例17: dc10

// Double tests 15 digits of accuracy
void dc10()
{
	ct.colWidth = 8;
	ct.constraintType = CalpontSystemCatalog::NO_CONSTRAINT;
	ct.colDataType = CalpontSystemCatalog::DOUBLE;
	ct.scale = 0;
	ct.precision = 4;
	bool pushWarning;

	data = "0.123456789012345";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(double));
	double doubleval = any_cast<double>(anyval);
	CPPUNIT_ASSERT(inTolerance(doubleval, 0.123456789012345, 0.000000000000001));

	data = "123456.000000001";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(double));
	doubleval = any_cast<double>(anyval);
	CPPUNIT_ASSERT(inTolerance(doubleval, 123456.000000001, 0.000000001));

	data = "(123456.000000001)";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(double));
	doubleval = any_cast<double>(anyval);
	CPPUNIT_ASSERT(inTolerance(doubleval, 123456.000000001, 0.000000001));

	data = "6.02214179000000E+23";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(double));
	doubleval = any_cast<double>(anyval);
	CPPUNIT_ASSERT(inTolerance(doubleval, 6.02214179000000E+23, 0.00000000000001E+23));

	data = "1.60217653140000E-19";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(double));
	doubleval = any_cast<double>(anyval);
	CPPUNIT_ASSERT(inTolerance(doubleval, 1.60217653140000E-19, 0.00000000000001E-19));

	data = "3.14159265358979";

	anyval = converter.convertColumnData(ct, data, pushWarning, false);

	CPPUNIT_ASSERT(anyval.type() == typeid(double));
	doubleval = any_cast<double>(anyval);
	CPPUNIT_ASSERT(inTolerance(doubleval, 3.14159265358979, 0.00000000000001));

}
开发者ID:EPICPaaS,项目名称:infinidb,代码行数:59,代码来源:tdriver.cpp


示例18: if

bool ValueParameter::set_unsafe(const boost::any& v)
{
    bool change = true;
    if (!value_.empty()) {
        if (v.type() == typeid(int)) {
            change = boost::any_cast<int>(value_) != boost::any_cast<int>(v);
        } else if (v.type() == typeid(double)) {
            change = boost::any_cast<double>(value_) != boost::any_cast<double>(v);
        } else if (v.type() == typeid(bool)) {
            change = boost::any_cast<bool>(value_) != boost::any_cast<bool>(v);
        } else if (v.type() == typeid(std::string)) {
            change = boost::any_cast<std::string>(value_) != boost::any_cast<std::string>(v);
        } else if (v.type() == typeid(long)) {
            change = boost::any_cast<long>(value_) != boost::any_cast<long>(v);
        }
    }
    if (change) {
        value_ = v;
        return true;
    }

    return false;
}
开发者ID:cogsys-tuebingen,项目名称:csapex,代码行数:23,代码来源:value_parameter.cpp


示例19: validate

void validate(boost::any &v, const std::vector<std::string> &values,
              std::experimental::optional<T>*, int) {
  using namespace boost::program_options;
  using optional_t = std::experimental::optional<T>;

  if(v.empty())
    v = optional_t();
  auto *val = boost::any_cast<optional_t>(&v);
  assert(val);

  boost::any a;
  validate(a, values, static_cast<T*>(nullptr), 0);
  *val = boost::any_cast<T>(a);
}
开发者ID:jimporter,项目名称:muspelheim,代码行数:14,代码来源:driver.cpp


示例20: str

void SQLiteStorage::push(const Core::objid_t id, const std::string& name,
        const boost::any& value)
{
    if (loading_)
    {
        return;
    }
    std::string query;
    bool found = false;
    char *error = nullptr;
    query = str(boost::format ("SELECT * FROM %s WHERE object=%u AND name='%s';") %
        (typeid(const time_t) == value.type() ? "times" : "strings") % id % name);
    if (sqlite3_exec(connection_, query.c_str(),
        SQLiteStorage_push_select, &found, &error))
    {
        std::cerr << "SQLITE: push: " << error << std::endl;
        sqlite3_free(error);
        return;
    }

    query = str(boost::format ("%s %s %s %s %s%s%u%s%s") %
        (found ? "UPDATE " : "INSERT INTO ") %
        (typeid(const time_t) == value.type() ? "times" : "strings") %
        (found ? " SET value=" : "(value, object, name) VALUES(") %
        (typeid(const time_t) == value.type() ?
            boost::str(boost::format ("%s") % boost::any_cast<const time_t>(value)) :
            boost::str(boost::format ("'%s'") % boost::any_cast<const std::string&>(value))) %
        (found ? " WHERE object=" : ", ") % id %
        (found ? " AND name='" : ", '") % name %
        (found ? "';" : "');"));
    if (sqlite3_exec(connection_, query.c_str(), nullptr, nullptr,
        &error))
    {
        std::cerr << "SQLITE: push: " << error << std::endl;
        sqlite3_free(error);
    }
}
开发者ID:etoestja,项目名称:UniSched,代码行数:37,代码来源:sqlite.cpp



注:本文中的boost::any类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ boost::array类代码示例发布时间:2022-05-31
下一篇:
C++ boom::String类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap