当前位置: 首页>>代码示例>>C++>>正文


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

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


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


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