本文整理汇总了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"));
}
示例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));
}
}
}
示例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);
}
示例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
}
示例5: setConfigurationSetting
void WTextEdit::setConfigurationSetting(const std::string& name,
const boost::any& value)
{
if (!value.empty())
configurationSettings_[name] = value;
else
configurationSettings_.erase(name);
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
}
示例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();
}
示例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);
}
示例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_);
}
示例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);
}
示例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");
}
示例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();
}