예제 #1
0
    void xparse(boost::any& value_store,
                const std::vector<std::string>& new_tokens) const
    {
        if(gPastLastOption)
        {
            throw(LLCLPLastOption("Don't parse no more!"));
        }

        // Error checks. Needed?
        if (!value_store.empty() && !is_composing())
        {
            throw(LLCLPError("Non composing value with multiple occurences."));
        }
        if (new_tokens.size() < min_tokens() || new_tokens.size() > max_tokens())
        {
            throw(LLCLPError("Illegal number of tokens specified."));
        }

        if(value_store.empty())
        {
            value_store = boost::any(LLCommandLineParser::token_vector_t());
        }
        LLCommandLineParser::token_vector_t* tv =
            boost::any_cast<LLCommandLineParser::token_vector_t>(&value_store);

        for(unsigned i = 0; i < new_tokens.size() && i < mMaxTokens; ++i)
        {
            tv->push_back(new_tokens[i]);
        }

        if(mLastOption)
        {
            gPastLastOption = true;
        }
    }
예제 #2
0
void
DBusIPCAPI_v1::CallbackWithStatusArg1_Helper(
    int status, const boost::any& value, DBusMessage *message
)
{
	DBusMessage *reply = dbus_message_new_method_return(message);
	DBusMessageIter iter;

	dbus_message_iter_init_append(reply, &iter);

	if (!status && value.empty()) {
		status = kWPANTUNDStatus_PropertyEmpty;
	}

	dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &status);

	if (value.empty()) {
		append_any_to_dbus_iter(&iter, std::string("<empty>"));
	} else {
		append_any_to_dbus_iter(&iter, value);
	}

	dbus_connection_send(mConnection, reply, NULL);
	dbus_message_unref(message);
	dbus_message_unref(reply);
}
예제 #3
0
파일: main.cpp 프로젝트: bentles/openmw
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);

    std::map<std::string,std::string>::iterator mapIt;
    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((mapIt = map->mMap.find(key)) == map->mMap.end())
        {
            map->mMap.insert(std::make_pair (key,value));
        }
    }
}
예제 #4
0
 BOOST_PROGRAM_OPTIONS_DECL 
 void check_first_occurrence(const boost::any& value)
 {
     if (!value.empty())
         boost::throw_exception(
             multiple_occurrences());
 }
예제 #5
0
void ItemAttribute::set(boost::any a)
{
	clear();
	if(a.empty())
		return;

	if(a.type() == typeid(std::string))
	{
		type = STRING;
		new(data) std::string(boost::any_cast<std::string>(a));
	}
	else if(a.type() == typeid(int32_t))
	{
		type = INTEGER;
		*reinterpret_cast<int32_t*>(&data) = boost::any_cast<int32_t>(a);
	}
	else if(a.type() == typeid(float))
	{
		type = FLOAT;
		*reinterpret_cast<float*>(&data) = boost::any_cast<float>(a);
	}
	else if(a.type() == typeid(bool))
	{
		type = BOOLEAN;
		*reinterpret_cast<bool*>(&data) = boost::any_cast<bool>(a);
	}
}
예제 #6
0
void validate(boost::any& v,
              const std::vector<std::basic_string<charT> >& s,
              std::vector<T>*,
              int)
{
    if (v.empty()) {
        v = boost::any(std::vector<T>());
    }
    std::vector<T>* tv = boost::any_cast< std::vector<T> >(&v);
    assert(NULL != tv);
    for (unsigned i = 0; i < s.size(); ++i)
    {
        try {
            /* We call validate so that if user provided
               a validator for class T, we use it even
               when parsing vector<T>.  */
            boost::any a;
            std::vector<std::basic_string<charT> > cv;
            cv.push_back(s[i]);
            validate(a, cv, (T*)0, 0);
            tv->push_back(boost::any_cast<T>(a));
        }
        catch(const bad_lexical_cast& /*e*/) {
            boost::throw_exception(invalid_option_value(s[i]));
        }
    }
}
예제 #7
0
  bool octtree_piece_rendata::exchange_field(const data_index_t &i,boost::any &v)
  {
    disc_rendata_ptr_t drd = disc_rds[i[1]];

    switch(i[0])
    {
    case 0:
      return s_exchange_data_ro(drd->cellid.to_string(),v);
    case 1:
      return s_exchange_data_ro((int)drd->index,v);
    case 2:
    case 3:
      {
        bool need_update = false;

        bool is_read     = v.empty();

        need_update =  s_exchange_data_rw(drd->show[i[0]%2],v);

        if(need_update && is_read == false )
          m_bNeedUpdateDiscRens = true;

        return need_update;
      }
    case 4:
    case 5:
      return s_exchange_data_rw(drd->color[i[0]%2],v);
    case 6:
    case 7:
      return s_exchange_action(random_color_assigner(drd,i[0]%2),v);

    };

    throw std::logic_error("invalid index");
  }
예제 #8
0
파일: WTextEdit.C 프로젝트: caseymcc/wt
void WTextEdit::setConfigurationSetting(const std::string& name, 
					const boost::any& value)
{
  if (!value.empty())
    configurationSettings_[name] = value;
  else
    configurationSettings_.erase(name);
}
예제 #9
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;
 }
예제 #10
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);
 }
예제 #11
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;
 }
예제 #12
0
	bool ColumnBaseTyped<Type>::multiply(const boost::any& new_value){
		if(new_value.empty()) return false;
		if(typeid(Type)==new_value.type()){
			 Type value = boost::any_cast<Type>(new_value);
			 for(unsigned int i=0;i<this->size();i++){
					this->operator[](i)*=value;
			 }
			 return true;
		}
		return false;
	}
예제 #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_);
 }
예제 #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();
}
예제 #15
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();
 }
예제 #16
0
	bool ColumnBaseTyped<Type>::minus(const boost::any& new_value){
		//shared_pointer_namespace::shared_ptr<ColumnBaseTyped<Type> > typed_column = shared_pointer_namespace::static_pointer_cast<ColumnBaseTyped<Type> >(column);	
		if(new_value.empty()) return false;
		if(typeid(Type)==new_value.type()){
			 Type value = boost::any_cast<Type>(new_value);
			 for(unsigned int i=0;i<this->size();i++){
					this->operator[](i)-=value;
			 }
			 return true;
		}
		return false;
	}
예제 #17
0
	bool ColumnBaseTyped<Type>::add(const boost::any& new_value){
		if(new_value.empty()) return false;
		if(typeid(Type)==new_value.type()){
			 Type value = boost::any_cast<Type>(new_value);
			 //std::transform(myvec.begin(), myvec.end(), myvec.begin(),
          //bind2nd(std::plus<double>(), 1.0));
			 for(unsigned int i=0;i<this->size();i++){
					this->operator[](i)+=value;
			 }
			 return true;
		}
		return false;
	}
예제 #18
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");
}
예제 #19
0
	bool ColumnBaseTyped<Type>::division(const boost::any& new_value){
		if(new_value.empty()) return false;
		if(typeid(Type)==new_value.type()){
			 Type value = boost::any_cast<Type>(new_value);
			 //check that we do not devide by zero
			 if(value==0) return false;
			 for(unsigned int i=0;i<this->size();i++){
					this->operator[](i)/=value;
			 }
			 return true;
		}
		return false;
	}
예제 #20
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);
}
예제 #21
0
파일: table.cpp 프로젝트: GOPRO1955/tables
    void table::set_default_value(const std::string& column_name,
        const boost::any& value)
    {
        // You must create the column before you set the default value
        assert(has_column(column_name));

        // You cannot set the default value on a constant column
        assert(!is_constant(column_name));

        auto& c = m_columns.at(column_name);
        c->set_default_value(value);
        assert(value.empty() ||
               c->type_hash() == value.type().hash_code());
    }
예제 #22
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);
            }
        }
    }
예제 #23
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;
}
예제 #24
0
파일: table.cpp 프로젝트: GOPRO1955/tables
    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());
    }
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;
}
예제 #27
0
        // Function which validates additional tokens from the given option.
        static void 
        validate(boost::any &v, std::vector<std::string> const &tokens)
        {
            if (v.empty())
                v = boost::any(include_paths());

            include_paths *p = boost::any_cast<include_paths>(&v);
            BOOST_ASSERT(NULL != p);

        // Assume only one path per '-I' occurrence.
            std::string const& t = po::validators::get_single_string(tokens);
            if (t == "-") {
            // found -I- option, so switch behaviour
                p->seen_separator = true;
            } 
            else if (p->seen_separator) {
            // store this path as a system path
                p->syspaths.push_back(t); 
            } 
            else {
            // store this path as an user path
                p->paths.push_back(t);
            }            
        }
예제 #28
0
파일: ptr.hpp 프로젝트: IanPAOConnor/openmw
 const std::type_info& getType() const
 {
     assert (!mPtr.empty());
     return mPtr.type();
 }
예제 #29
0
파일: ptr.hpp 프로젝트: IanPAOConnor/openmw
 bool isEmpty() const
 {
     return mPtr.empty();
 }
예제 #30
0
 const_column::const_column(const boost::any& value, uint32_t rows)
     : m_value(value), m_rows(rows)
 {
     assert(!value.empty());
 }