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


C++ any::type方法代码示例

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


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

示例1: operator

 inline void operator()(boost::any& to_set, const boost::any& new_value)
 {
   if(new_value.type() == to_set.type())
   {
     to_set = new_value;
   }
   else
   {
     try
     {
       std::vector<Uint> int_vals = boost::any_cast< std::vector<Uint> >(new_value);
       const Uint nb_vals = int_vals.size();
       std::vector<int> result(nb_vals);
       for(Uint i = 0; i != nb_vals; ++i)
       {
         result[i] = static_cast<int>(int_vals[i]);
       }
       to_set = result;
     }
     catch(boost::bad_any_cast& e)
     {
       throw CastingFailed(FromHere(), std::string("Failed to cast object of type ") + new_value.type().name() + " to type std::vector<int>");
     }
   }
 }
开发者ID:BijanZarif,项目名称:coolfluid3,代码行数:25,代码来源:OptionArrayDetail.hpp

示例2: set

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);
	}
}
开发者ID:Luck-Oake,项目名称:therebornserver,代码行数:27,代码来源:itemattributes.cpp

示例3: is_a

        static bool is_a( const boost::any& a ) {
#if defined __GNUC__ 
            // See issue on boost.  https://svn.boost.org/trac/boost/ticket/754
            return std::strcmp( a.type().name(), typeid( T ).name() ) == 0;
#else
            return a.type() == typeid( T );
#endif
        }
开发者ID:hermixy,项目名称:qtplatz,代码行数:8,代码来源:is_type.hpp

示例4: getChildCount

UInt32 SceneTreeModel::getChildCount(const boost::any& parent) const
{
    if(parent.type() == typeid(Scene* const))
    {
        return SceneComponentsLast;
    }
    else if(parent.type() == typeid(UInt32))
    {
        UInt32 Value(boost::any_cast<UInt32>(parent));
        switch(Value)
        {
        case BasicComponent:              //Basic
        case BackgroundComponent:              //Background
        case CameraComponent:              //Camera
            return 0;
            break;
        case ForegroundsComponent:              //Foregrounds
            return getInternalRoot()->getPrimaryViewport()->getMFForegrounds()->size();
            break;
        case SceneObjectsComponent:              //Models
            return getInternalRoot()->getMFSceneObjects()->size();
            break;
        case LightsComponent:              //Lights
            {
                NodeRecPtr LightNode(getInternalRoot()->getPrimaryViewport()->getRoot());
                UInt32 NumLights(0);

                while(LightNode->getNChildren() > 0 &&
                      LightNode->getChild(0)->getCore()->getType().isDerivedFrom(Light::getClassType()))
                {
                    LightNode = LightNode->getChild(0);

                    ++NumLights;
                }
                return NumLights;
            }
            break;
        case DynamicsComponent:              //Dynamics
            return DynamicsComponentsLast - DynamicsComponentsFirst;
            break;
        case ScriptsComponent:              //Scripts
            return 0;
            break;
        case BehavioursComponent:              //Behaviours
            return 0;
            break;
        case AnimationsComponent:              //Animations
            return 0;
            break;
        }
    }
    else
    {
        return 0;
    }
}
开发者ID:djkabala,项目名称:KabalaEngine,代码行数:56,代码来源:KESceneTreeModel.cpp

示例5: support

bool Parameter::support(const boost::any& value) {
    if (value.type() == typeid(int)
            || value.type() == typeid(bool)
            || value.type() == typeid(double)
            || value.type() == typeid(string)) {
        return true;
    }

    return false;
}
开发者ID:zklvyy,项目名称:hikyuu,代码行数:10,代码来源:Parameter.cpp

示例6: setPathValue

void PropertyConstraintList::setPathValue(const ObjectIdentifier &path, const boost::any &value)
{
    const ObjectIdentifier::Component & c0 = path.getPropertyComponent(0);
    double dvalue;

    if (value.type() == typeid(double))
        dvalue = boost::any_cast<double>(value);
    else if (value.type() == typeid(Quantity))
        dvalue = (boost::any_cast<Quantity>(value)).getValue();
    else
        throw std::bad_cast();

    if (c0.isArray() && path.numSubComponents() == 1) {
        int index = c0.getIndex();

        if (c0.getIndex() >= _lValueList.size())
            throw Base::Exception("Array out of bounds");
        switch (_lValueList[index]->Type) {
        case Angle:
            dvalue = Base::toRadians<double>(dvalue);
            break;
        default:
            break;
        }
        aboutToSetValue();
        _lValueList[index]->setValue(dvalue);
        hasSetValue();
        return;
    }
    else if (c0.isSimple() && path.numSubComponents() == 2) {
        ObjectIdentifier::Component c1 = path.getPropertyComponent(1);

        for (std::vector<Constraint *>::const_iterator it = _lValueList.begin(); it != _lValueList.end(); ++it) {
            int index = it - _lValueList.begin();

            if ((*it)->Name == c1.getName()) {
                switch (_lValueList[index]->Type) {
                case Angle:
                    dvalue = Base::toRadians<double>(dvalue);
                    break;
                default:
                    break;
                }
                aboutToSetValue();
                _lValueList[index]->setValue(dvalue);
                hasSetValue();
                return;
            }
        }
    }
    throw Base::Exception("Invalid constraint");
}
开发者ID:lanigb,项目名称:FreeCAD,代码行数:52,代码来源:PropertyConstraintList.cpp

示例7: convertToMsParam

    error convertToMsParam(boost::any &itr, msParam_t *t) {
        if(itr.type() == typeid(std::string)) {
            fillStrInMsParam( t, const_cast<char*>( boost::any_cast<std::string>(itr).c_str() ));
        } else if(itr.type() == typeid(std::string *)) {
            fillStrInMsParam( t, const_cast<char*>( (*(boost::any_cast<std::string *>(itr))).c_str() ));
        } else if(itr.type() == typeid(msParam_t*)) {
            memset(t, 0, sizeof(*t));
            replMsParam(boost::any_cast<msParam_t*>(itr), t);
        } else {
            return ERROR(-1, "cannot convert parameter");
        }

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

示例8: dc9

// Float tests 6 digits of accuracy
void dc9()
{
	ct.colWidth = 4;
	ct.constraintType = CalpontSystemCatalog::NO_CONSTRAINT;
	ct.colDataType = CalpontSystemCatalog::FLOAT;
	ct.scale = 0;
	ct.precision = 4;
	bool pushWarning;

	data = "0.123456";

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

	CPPUNIT_ASSERT(anyval.type() == typeid(float));
	float floatval = any_cast<float>(anyval);
	CPPUNIT_ASSERT(inTolerance(floatval, 0.123456, 0.000001));

	data = "3456.01";

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

	CPPUNIT_ASSERT(anyval.type() == typeid(float));
	floatval = any_cast<float>(anyval);
	CPPUNIT_ASSERT(inTolerance(floatval, 3456.01, 0.01));

	data = "(3456.01)";

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

	CPPUNIT_ASSERT(anyval.type() == typeid(float));
	floatval = any_cast<float>(anyval);
	CPPUNIT_ASSERT(inTolerance(floatval, 3456.01, 0.01));

	data = "6.02214E+23";

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

	CPPUNIT_ASSERT(anyval.type() == typeid(float));
	floatval = any_cast<float>(anyval);
	CPPUNIT_ASSERT(inTolerance(floatval, 6.02214E+23, 0.00001E+23));

	data = "1.60217E-19";

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

	CPPUNIT_ASSERT(anyval.type() == typeid(float));
	floatval = any_cast<float>(anyval);
	CPPUNIT_ASSERT(inTolerance(floatval, 1.60217E-19, 0.00001E-19));

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

示例9: set

bool IniFile::set(const string& key, const boost::any& data)
{
  if (data.type() == typeid(string))
    return set(key, boost::any_cast<const string&>(data));
  if (data.type() == typeid(unsigned))
    return set(key, boost::any_cast<unsigned>(data));
  if (data.type() == typeid(int))
    return set(key, boost::any_cast<int>(data));
  if (data.type() == typeid(bool))
    return set(key, boost::any_cast<bool>(data));

  gLog.warning(tr("Internal Error: IniFile::set, key=%s, data.type=%s"),
      key.c_str(), data.type().name());
  return false;
}
开发者ID:jwakely,项目名称:licq,代码行数:15,代码来源:inifile.cpp

示例10: ProcessData

BOOL CStatFilePlugin::ProcessData( boost::any& anyData )
{
	if(anyData.type() == typeid(std::string))  
	{
		std::string strPath  = boost::any_cast<std::string>(anyData); 
		if(::GetFileAttributes(strPath.c_str())==-1)
		{
			std::cout<<"目录不存在"<<std::endl;
			return FALSE;
		}
        m_info.m_strPath = strPath;
		std::cout<<"现在正在统计的是:"<<m_info.m_strPath<<std::endl;
        std::cout<<"请等待!!!"<<std::endl;
        
		std::string	strTmpDir = m_info.m_strPath + TEXT("\\");
		// 统计文件数
		StatAllFileInFolder(strTmpDir);

        std::cout<<"文件夹数:"<<m_info.m_FolderNum<<std::endl;
		std::cout<<"文件数:"<<m_info.m_FileNum<<std::endl;

		CPluginFactory* pPluginFactory = CPluginFactory::Instance();
		IPluginObjPtr ptrOuttoFile = pPluginFactory->GetPlugin(_T("OutputFile.dll"));
		boost::any anyInfo = m_info;
		ptrOuttoFile->ProcessData(anyInfo);

		return TRUE;
	}
	return FALSE;
}
开发者ID:yybbest,项目名称:dev-utility-tools,代码行数:30,代码来源:StatFilePlugin.cpp

示例11: setData

bool ArnModelW::setData(const WModelIndex& index,
                                 const boost::any& value, int role)
{
    if (index.isValid()  &&  role == Wt::EditRole) {
        ArnNode*  node = nodeFromIndex( index);
        if (!node)  return false;

        if (node->isFolder()) {
            if (node->_valueChild) {
                if (node->_setMap) {
                    node->_valueChild->setValue( node->_setMap->key( toQString( boost::any_cast<WString>(value))));
                }
                else {
                    node->_valueChild->setValue( toQString( boost::any_cast<WString>(value)));
                }
                emitDataChangedI( index);
            }
        }
        else {
            if (value.type() == typeid(QVariant))
                node->setValue( boost::any_cast<QVariant>(value));
            else
                node->setValue( toQString( boost::any_cast<WString>(value)));
            emitDataChangedI( index);
        }
        return true;
    }
    return false;
}
开发者ID:micwik,项目名称:WebArnBrowser,代码行数:29,代码来源:ArnModel.cpp

示例12: get

bool IniFile::get(const string& key, boost::any& data) const
{
  if (data.type() == typeid(string))
    return get(key, boost::any_cast<string&>(data));
  if (data.type() == typeid(unsigned))
    return get(key, boost::any_cast<unsigned&>(data));
  if (data.type() == typeid(int))
    return get(key, boost::any_cast<int&>(data));
  if (data.type() == typeid(bool))
    return get(key, boost::any_cast<bool&>(data));

  // Unhandled data type
  gLog.warning(tr("Internal Error: IniFile::get, key=%s, data.type=%s"),
      key.c_str(), data.type().name());
  return false;
}
开发者ID:jwakely,项目名称:licq,代码行数:16,代码来源:inifile.cpp

示例13: setAsAnyImpl

 typename std::enable_if<std::is_copy_constructible<U>::value && std::is_nothrow_destructible<U>::value, void>::type setAsAnyImpl(C* object, const boost::any& value) const
 {
     if(value.type() == typeid(U))
         object->*m_member = boost::any_cast<U>(value);
     else
         std::cout << "Script trying to set a value as boost::any but with an invalid type !" << std::endl;
 }
开发者ID:MORTAL2000,项目名称:YAPG,代码行数:7,代码来源:AttributeMetadata.hpp

示例14: T

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

示例15: 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


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