BOOST_PROGRAM_OPTIONS_DECL 
 void check_first_occurrence(const boost::any& value)
 {
     if (!value.empty())
         boost::throw_exception(
             multiple_occurrences("multiple_occurrences"));
 }
Example #2
0
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));
        }
    }
}
Example #3
0
 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);
 }
Example #4
0
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
}
Example #5
0
void WTextEdit::setConfigurationSetting(const std::string& name, 
					const boost::any& value)
{
  if (!value.empty())
    configurationSettings_[name] = value;
  else
    configurationSettings_.erase(name);
}
Example #6
0
 /// 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;
 }
Example #7
0
    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());
    }
Example #8
0
 /**
  * @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;
 }
Example #9
0
bool
IsotopeForm::getContents( boost::any& any ) const
{
	if ( any.type() != typeid( adcontrols::ProcessMethod* ) )
		return false;
	adcontrols::ProcessMethod* pm = boost::any_cast< adcontrols::ProcessMethod* >( any );
    pm->appendMethod( *pMethod_ );
    return true;
}
        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;
            }
        }
Example #11
0
 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();
 }
Example #12
0
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);
}
Example #13
0
 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_);
 }
Example #14
0
void pimpl<Thread>::join(const boost::any &id, shared_ptr<boost::thread> thread)
{
	if(thread == nullptr)
		return;

	// N.B.: la terminazione di un thread deve essere effettuata da un thread esterno altrimenti la join non terminerebbe mai...
	// Esendo legale la join di un thread non in esecuzione va verificato che l'id specificato sia valido
	OS_ASSERT(id.empty() || (PlatformManager::instance()->compareThreadsID(id, PlatformManager::instance()->getCurrentThreadID()) == false));

	thread->join();
}
Example #15
0
 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);
 }
Example #16
0
bool
IsotopeForm::setContents( boost::any& a )
{
    if ( a.type() != typeid( adcontrols::ProcessMethod ) )
        return false;
    adcontrols::ProcessMethod& pm = boost::any_cast< adcontrols::ProcessMethod& >(a);
    const adcontrols::IsotopeMethod* p = pm.find< adcontrols::IsotopeMethod >();
    if ( ! p )
        return false;
    *pMethod_ = *p;
    // update_data( *p );
    return true;
}
Example #17
0
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");
}
Example #18
0
    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();
    }
Example #19
0
// 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);

}
Example #20
0
// 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));

}
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;
}
Example #22
0
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);
}
Example #23
0
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);
    }
}
Example #24
0
    // serialization for boost::any
    void serialize(SF::Archive &ar, boost::any &a)
    {
        if (ar.isWrite())
        {
            std::string which = 
                SF::Registry::getSingleton().getTypeName(a.type());

            if (which.empty() && !a.empty())
            {
                RCF_THROW(RCF::Exception(RCF::_RcfError_AnyTypeNotRegistered(a.type().name())));
            }

            ar & which;

            if (!a.empty())
            {
                RCF_ASSERT(which.size() > 0);

                SF::Registry::getSingleton().getAnySerializer(which)
                    .serialize(ar, a);
            }
        }
        else
        {
            std::string which;
            ar & which;
            if (which.empty())
            {
                a = boost::any();
            }
            else
            {
                SF::Registry::getSingleton().getAnySerializer(which)
                    .serialize(ar, a);
            }
        }
    }
Example #25
0
static bool inRange(const T& value, const boost::any& min, const boost::any& max, T * pmin, T * pmax)
{
    bool rc = true;

    if(!min.empty()) {
        T vmin = boost::any_cast<T>(min);
        if(pmin)
            *pmin = vmin;

        if(value < vmin)
            rc = false;
    }

    if(!max.empty()) {
        T vmax = boost::any_cast<T>(max);
        if(pmax)
            *pmax = vmax;

        if(vmax < value)
            rc = false;
    }

    return rc;
}
Example #26
0
static std::string cast_and_decode<std::string>(boost::any &a,bool allow_null)
{
	if(allow_null && a.type() == typeid(void))
		return std::string();
	std::string s = boost::any_cast<std::string>(a);

	// Twitter *only* encodes < and >, so decode them
	size_t off;
	while( (off = s.find("&lt;")) != std::string::npos)
		s.replace(off,4,"<");
	while( (off = s.find("&gt;")) != std::string::npos)
		s.replace(off,4,">");

	return s;
}
Example #27
0
	/**
	 * @brief obtain the name of the file if the target type is an output file
	 * @return the file name
	 */
	inline std::string get_file_name() const
	{
		std::string result = "";
		try
		{
			if( m_target_id.type() == typeid( std::string ) )
				result = boost::any_cast< std::string >( m_target_id );
			else
				LOG_ERROR( "no file name specified" );
		}
		catch (boost::bad_any_cast& ex)
		{
			LOG_ERROR(ex.what());
		}
		return result;
	}
Example #28
0
    /*! @brief The type of the variable
     *
     * Returns a string containing the type of the variable. This may or may not be
     * human readable (Microsoft compilers will produce human readable outputs, GCC
     * compilers will not) but are guaranteed to be unique for unique types
     * @return the variable type as a string
     */
    std::string type(void) const {
    	const std::type_info& tp = data_.type();
		if (tp == typeid(uint8_t)) return TypeName<uint8_t>::toString();
		if (tp == typeid(int8_t))  return TypeName<int8_t>::toString();
		if (tp == typeid(uint16_t)) return TypeName<uint16_t>::toString();
		if (tp == typeid(int16_t)) return TypeName<int16_t>::toString();
		if (tp == typeid(int32_t)) return TypeName<int32_t>::toString();
		if (tp == typeid(float)) return TypeName<float>::toString();
		if (tp == typeid(double)) return TypeName<double>::toString();
		if (tp == typeid(cv::Mat)) return TypeName<cv::Mat>::toString();
		if (tp == typeid(MatlabIOContainer)) return TypeName<MatlabIOContainer>::toString();
		if (tp == typeid(std::vector<MatlabIOContainer>)) return TypeName<std::vector<MatlabIOContainer> >::toString();
		if (tp == typeid(std::vector<std::vector<MatlabIOContainer> >)) return TypeName<std::vector<std::vector<MatlabIOContainer> > >::toString();
		if (tp == typeid(std::vector<cv::Mat>)) return TypeName<std::vector<cv::Mat> >::toString();
		if (tp == typeid(void)) return TypeName<void>::toString();
		return std::string(tp.name());
	}
ComponentTransitPtr DefaultTableCellEditor::getTableCellEditorComponent(Table* const table, const boost::any& value, bool isSelected, UInt32 row, UInt32 column)
{
    if(value.empty()){
        return ComponentTransitPtr(NULL);
    }
    TextFieldRefPtr TheTextField = TextField::create();
    std::string tempString;
    try
    {
        tempString = lexical_cast(value);
    }
    catch (boost::bad_lexical_cast &)
    {
        //Could not convert to string
    }
    TheTextField->setText(tempString);
    TheTextField->setPreferredSize(Vec2f(100,30));
    TheTextField->setAlignment(Vec2f(0.5,0.5));
    TheTextField->selectAll();
    TheTextField->setCaretPosition(TheTextField->getText().size());
    ColorLayerRefPtr tempBackground;
    tempBackground = ColorLayer::create();

    TheTextField->setBackground(tempBackground);

    //if(isSelected){
    //	tempBackground->setColor(Color4f(0.4, 0.4, 1.0, 1.0));
    //}
    //else{
    tempBackground->setColor(Color4f(1.0, 1.0, 1.0, 1.0));
    //}

    LineBorderRefPtr tempBorder;

    tempBorder = LineBorder::create();
    tempBorder->setColor(Color4f(0.0, 0.0, 1.0, 1.0));

    TheTextField->setBorder(tempBorder);

    setDefaultStringEditor(TheTextField);
    _EditorActionConnection = getDefaultStringEditor()->connectActionPerformed(boost::bind(&DefaultTableCellEditor::handleEditorAction, this, _1));
    _EditorFocusLostConnection = getDefaultStringEditor()->connectFocusLost(boost::bind(&DefaultTableCellEditor::handleEditorFocusLost, this, _1));
    _EditorKeyPressedConnection = getDefaultStringEditor()->connectKeyPressed(boost::bind(&DefaultTableCellEditor::handleEditorKeyPressed, this, _1));
    return ComponentTransitPtr(getDefaultStringEditor());
}
std::string LogListComponentGenerator::getText(List* const Parent, const boost::any& Value, UInt32 Index, bool IsSelected, bool HasFocus) const
{
	if(Value.empty()){
		return std::string("");
	}

	std::string ValueString;
    try
    {
        ValueString = boost::any_cast<std::string>(Value);
    }
    catch (boost::bad_any_cast &ex)
    {
        //Could not convert to string
        SWARNING << "Bad any cast: " << ex.what() << std::endl;
    }
    return ValueString;
}