bool isFieldContentDerivedFrom(const FieldType &TheFieldType, const FieldContainerType* TheFCType)
{
    if(TheFieldType.isPtrField())
    {
        std::string FieldPtrTypeName(TheFieldType.getContentType().getName());
        switch(TheFieldType.getClass())
        {
            case FieldType::PtrField:
            case FieldType::ParentPtrField:
            case FieldType::ChildPtrField:
                FieldPtrTypeName = FieldPtrTypeName.substr(0,FieldPtrTypeName.size()-3);
                break;
            default:
            case FieldType::ValueField:
                return false;
                break;
        }
        const FieldContainerType* PtrContentType = FieldContainerFactory::the()->findType(FieldPtrTypeName.c_str());
        
        return TheFCType->isDerivedFrom(*PtrContentType);
    }
    else
    {
        return false;
    }
    return false;
}
QOSGWidgetFactory::FieldEditorCF
QOSGWidgetFactory::getFieldEditor(const FieldType &fType,
                                  const Char8     *fName )
{
    UInt32 fTypeId = fType.getId(          );
    UInt64 index   = getIndex   (0, fTypeId);

    return getFieldEditor(index, fName, fType.getCardinality());
}
Example #3
0
void RichPara::Cat(Id field, const String& param, const RichPara::CharFormat& f)
{
	cacheid = 0;
	Part& p = part.Add();
	p.field = field;
	p.fieldparam = param;
	p.format = f;
	VectorMap<String, Value> dummy;
	FieldType *ft = fieldtype().Get(field, NULL);
	if(ft)
		p.fieldpart ^= ft->Evaluate(param, dummy, f);
}
Example #4
0
void FieldDefinition::addFieldType(const FieldType& fieldType)
{
    TypeMap::const_iterator it = m_name2TypeMap.find(fieldType.getName());
    if (it != m_name2TypeMap.end())
    {
        FIRTEX_THROW(IllegalArgumentException, _T("Field type duplicate: [%s]"), 
                     fieldType.getName().c_str());
    }
    FieldType* pFieldType = new FieldType(fieldType);
    m_types.push_back(pFieldType);
    m_name2TypeMap.insert(make_pair(pFieldType->getName(), pFieldType));
}
void Foam::solution::cachePrintMessage
(
    const char* message,
    const word& name,
    const FieldType& vf
)
{
    if (solution::debug)
    {
        Info<< "Cache: " << message << token::SPACE << name
            << ", originating from " << vf.name()
            << " event No. " << vf.eventNo()
            << endl;
    }
}
Example #6
0
bool RichPara::EvaluateFields(VectorMap<String, Value>& vars)
{
	bool b = false;
	for(int i = 0; i < GetCount(); i++) {
		Part& p = part[i];
		if(p.field) {
			FieldType *f = fieldtype().Get(p.field, NULL);
			if(f) {
				p.fieldpart ^= f->Evaluate(p.fieldparam, vars, p.format);
				b = true;
			}
		}
	}
	return b;
}
    HDINLINE void operator()(ThreadParams* params)
    {
#ifndef __CUDA_ARCH__
        DataConnector &dc = Environment<>::get().DataConnector();
        ThreadParams *tp = params;

        /* load field without copying data to host */
        FieldType* field = &(dc.getData<FieldType > (FieldType::getName(), true));

        /* load from HDF5 */
        RestartFieldLoader::loadField(
                field->getGridBuffer(),
                (uint32_t)FieldType::numComponents,
                FieldType::getName(),
                tp);

        dc.releaseData(FieldType::getName());
#endif
    }
void
QOSGWidgetFactory::registerFieldEditor(const FieldType     &fType,
                                       const Char8         *fName,
                                             FieldEditorCF  cFunc )
{
    UInt32 fTypeId  = fType.getId(          );
    UInt64 index    = getIndex   (0, fTypeId);

    registerFieldEditor(index, fName, cFunc);
}
Example #9
0
void check_stop_condition(FieldType field, std::vector<std::string> &earlier_hashes, bool &done, int &repeats_to_do) {
	std::string hash = field.field_hash();
	for(int i = 0; i < earlier_hashes.size(); ++i) {
		if(earlier_hashes[i] == hash) {
			done = true;
			repeats_to_do = 10;
			break;
		}
	}
	earlier_hashes.push_back(hash);
}
Example #10
0
void FieldDefinition::configure(Configurator& conf)
{
    if (conf.getMode() == Configurator::TO_CONF)
    {
        Configurator ftRootConf;
        for (TypeVector::iterator it = m_types.begin(); it != m_types.end(); ++it)
        { 
            Configurator ftConf;
            (*it)->configure(ftConf);
            ftRootConf.configure(_T("field_type"), ftConf.getMap());
        }      
        conf.configure(_T("type_define"), ftRootConf.getMap());
    }
    else 
    {
        Configurator::Iterator it = conf.findConf(_T("type_define"));
        if (it.hasNext())
        {
            Configurator::ConfMap rootConfMap = 
                AnyCast<Configurator::ConfMap>(it.next().second);
            Configurator rootConf(rootConfMap);
            Configurator::Iterator it2 = rootConf.iterator();
            while (it2.hasNext())
            {
                Configurator::KeyValuePair kv = it2.next();
                if (kv.first == _T("field_type"))
                {
                    FieldType* pType = new FieldType;
                    Configurator::ConfMap ftMap = AnyCast<Configurator::ConfMap>(
                        kv.second);
                    Configurator ftConf(ftMap);
                    pType->configure(ftConf);
                    addFieldType(*pType);
                }
            }
            
        }
    }
}
void Foam::functionObjects::fieldCoordinateSystemTransform::transformField
(
    const FieldType& field
)
{
    word transFieldName(transformFieldName(field.name()));

    store
    (
        transFieldName,
        Foam::transform(dimensionedTensor(coordSys_.R().R()), field)
    );
}
void FCPtrFieldEditor::initMethod(InitPhase ePhase)
{
    Inherited::initMethod(ePhase);

    if(ePhase == TypeObject::FactoryPost)
    {
        //Fill in all of the editable types
        UInt32 NumTypes(TypeFactory::the()->getNumTypes());
        FieldType* type;
        for(UInt32 i(0) ; i<NumTypes; ++i)
        {
            type = dynamic_cast<FieldType*>(TypeFactory::the()->findType(i));
            if(type != NULL &&
               (type->getClass() == FieldType::PtrField ||
               type->getClass() == FieldType::ChildPtrField))
            {
                _EditableTypes.push_back(&type->getContentType());
                FieldEditorFactory::the()->setEditorType(&type->getContentType(), &getClassType(),
                                                         "FieldContainerPtr");
            }
        }
    }
}
Example #13
0
void Deserializer::logNextBytesAs(CustomType *type,
                                  int depth,
                                  Schema& schema,
                                  std::ostream &os,
                                  string contextName)
{
    margin(os, 4 * depth);
    os << contextName << ": " << type->getName() << " = " << std::endl;
    for (auto &f: type->getFields())
    {
        FieldType ft = f.getFieldType();
        TypeID fieldTypeID = ft.getTypeID();

        // query schema for actual type description from TypeID
        Type* fieldType = schema.getTypeByID(fieldTypeID);

        if (!fieldType)
        {
            os << "[Error] Found field with TypeID=" << fieldTypeID
               << " but this TypeID is not present in given schema (file position: "
               << istream.tellg() << ")" << std::endl;
            return;
        }

        uint32 offset = 0;
        uint32 count = 1;
        if (ft.isRepeated())
        {
            Deserializer &d = *this;
            if (ft.getRepeat() == FieldType::REPEAT_16)
            {
                uint16 aux;
                d >> aux;
                count = aux;
            }
            else if (ft.getRepeat() == FieldType::REPEAT_32)
Example #14
0
 string fullName() const { return field->fullName(); }   
Example #15
0
 LITESQL_String fullName() const { return field->fullName(); }   
Example #16
0
 LITESQL_String name() const { return field->name(); }
Example #17
0
void ClassCompiler::CodeGenValidator(const std::string& name, const std::string& klass, const std::vector<Rule>& rules, const std::string& field, const FieldType& fieldType, ValidatorType validatorType)
{
	m_Impl << "static void TIValidate" << name << "(const intrusive_ptr<ObjectImpl<" << klass << "> >& object, ";

	if (validatorType != ValidatorField)
		m_Impl << "const String& key, ";

	m_Impl << fieldType.GetArgumentType() << " value, std::vector<String>& location, const ValidationUtils& utils)" << std::endl
	       << "{" << std::endl;

	if (validatorType == ValidatorField) {
		bool required = false;

		for (std::vector<Rule>::size_type i = 0; i < rules.size(); i++) {
			const Rule& rule = rules[i];

			if ((rule.Attributes & RARequired) && rule.Pattern == field) {
				required = true;
				break;
			}
		}

		if (fieldType.GetRealType() != "int" && fieldType.GetRealType() != "double") {
			if (fieldType.GetRealType() == "Value" || fieldType.GetRealType() == "String")
				m_Impl << "\t" << "if (value.IsEmpty())" << std::endl;
			else
				m_Impl << "\t" << "if (!value)" << std::endl;

			if (required)
				m_Impl << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast<DynamicObject *>(this), location, \"This attribute must not be empty.\"));" << std::endl;
			else
				m_Impl << "\t\t" << "return;" << std::endl;

			m_Impl << std::endl;
		}
	}

	if (validatorType != ValidatorField)
		m_Impl << "\t" << "bool known_attribute = false;" << std::endl;

	bool type_check = false;

	for (std::vector<Rule>::size_type i = 0; i < rules.size(); i++) {
		const Rule& rule = rules[i];

		if (rule.Attributes & RARequired)
			continue;

		if (validatorType == ValidatorField && rule.Pattern != field)
			continue;

		m_Impl << "\t" << "do {" << std::endl;

		if (validatorType != ValidatorField) {
			if (rule.Pattern != "*") {
				if (rule.Pattern.find_first_of("*?") != std::string::npos)
					m_Impl << "\t\t" << "if (!Utility::Match(\"" << rule.Pattern << "\", key))" << std::endl;
				else
					m_Impl << "\t\t" << "if (key != \"" << rule.Pattern << "\")" << std::endl;

				m_Impl << "\t\t\t" << "break;" << std::endl;
			}

			m_Impl << "\t\t" << "known_attribute = true;" << std::endl;
		}

		if (rule.IsName) {
			m_Impl << "\t\t" << "if (value.IsScalar()) {" << std::endl
			       << "\t\t\t" << "if (utils.ValidateName(\"" << rule.Type << "\", value))" << std::endl
			       << "\t\t\t\t" << "return;" << std::endl
			       << "\t\t\t" << "else" << std::endl
			       << "\t\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast<DynamicObject>(object), location, \"Object '\" + value + \"' of type '" << rule.Type << "' does not exist.\"));" << std::endl
			       << "\t\t" << "}" << std::endl;
		}

		if (fieldType.GetRealType() == "Value") {
			if (rule.Type == "String")
				m_Impl << "\t\t" << "if (value.IsEmpty() || value.IsScalar())" << std::endl
				       << "\t\t\t" << "return;" << std::endl;
			else if (rule.Type == "Number") {
				m_Impl << "\t\t" << "try {" << std::endl
				       << "\t\t\t" << "Convert::ToDouble(value);" << std::endl
				       << "\t\t\t" << "return;" << std::endl
				       << "\t\t" << "} catch (...) { }" << std::endl;
			}
		}

		if (rule.Type == "Dictionary" || rule.Type == "Array" || rule.Type == "Function") {
			if (fieldType.GetRealType() == "Value") {
				m_Impl << "\t\t" << "if (value.IsObjectType<" << rule.Type << ">()) {" << std::endl;
				type_check = true;
			} else if (fieldType.GetRealType() != rule.Type + "::Ptr") {
				m_Impl << "\t\t" << "if (dynamic_pointer_cast<" << rule.Type << ">(value)) {" << std::endl;
				type_check = true;
			}

			if (!rule.Rules.empty()) {
				bool indent = false;

				if (rule.Type == "Dictionary") {
					if (type_check)
						m_Impl << "\t\t\t" << "Dictionary::Ptr dict = value;" << std::endl;
					else
						m_Impl << "\t\t" << "const Dictionary::Ptr& dict = value;" << std::endl;

					m_Impl << (type_check ? "\t" : "") << "\t\t" << "ObjectLock olock(dict);" << std::endl
					       << (type_check ? "\t" : "") << "\t\t" << "BOOST_FOREACH(const Dictionary::Pair& kv, dict) {" << std::endl
					       << (type_check ? "\t" : "") << "\t\t\t" << "const String& akey = kv.first;" << std::endl
					       << (type_check ? "\t" : "") << "\t\t\t" << "const Value& avalue = kv.second;" << std::endl;
					indent = true;
				} else if (rule.Type == "Array") {
					if (type_check)
						m_Impl << "\t\t\t" << "Array::Ptr arr = value;" << std::endl;
					else
						m_Impl << "\t\t" << "const Array::Ptr& arr = value;" << std::endl;

					m_Impl << (type_check ? "\t" : "") << "\t\t" << "Array::SizeType anum = 0;" << std::endl
					       << (type_check ? "\t" : "") << "\t\t" << "ObjectLock olock(arr);" << std::endl
					       << (type_check ? "\t" : "") << "\t\t" << "BOOST_FOREACH(const Value& avalue, arr) {" << std::endl
					       << (type_check ? "\t" : "") << "\t\t\t" << "String akey = Convert::ToString(anum);" << std::endl;
					indent = true;
				} else {
					m_Impl << (type_check ? "\t" : "") << "\t\t" << "String akey = \"\";" << std::endl
					       << (type_check ? "\t" : "") << "\t\t" << "const Value& avalue = value;" << std::endl;
				}

				std::string subvalidator_prefix;

				if (validatorType == ValidatorField)
					subvalidator_prefix = klass;
				else
					subvalidator_prefix = name;

				m_Impl << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "location.push_back(akey);" << std::endl
				       << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "TIValidate" << subvalidator_prefix << "_" << i << "(object, akey, avalue, location, utils);" << std::endl;

				if (rule.Type == "Array")
					m_Impl << (type_check ? "\t" : "") << "\t\t\t" << "anum++;" << std::endl;

				if (rule.Type == "Dictionary" || rule.Type == "Array")
					m_Impl << (type_check ? "\t" : "") << "\t\t" << "}" << std::endl;

				for (std::vector<Rule>::size_type i = 0; i < rule.Rules.size(); i++) {
					const Rule& srule = rule.Rules[i];

					if ((srule.Attributes & RARequired) == 0)
						continue;

					if (rule.Type == "Dictionary") {
						m_Impl << (type_check ? "\t" : "") << "\t\t" << "if (dict.Get(\"" << srule.Pattern << "\").IsEmpty())" << std::endl
						       << (type_check ? "\t" : "") << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast<DynamicObject *>(this), location, \"Required dictionary item '" << srule.Pattern << "' is not set.\"));" << std::endl;
					} else if (rule.Type == "Array") {
						int index = -1;
						std::stringstream idxbuf;
						idxbuf << srule.Pattern;
						idxbuf >> index;

						if (index == -1) {
							std::cerr << "Invalid index for 'required' keyword: " << srule.Pattern;
							std::exit(1);
						}

						m_Impl << (type_check ? "\t" : "") << "\t\t" << "if (arr.GetLength() < " << (index + 1) << ")" << std::endl
						       << (type_check ? "\t" : "") << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast<DynamicObject *>(this), location, \"Required index '" << index << "' is not set.\"));" << std::endl;
					}
				}

				m_Impl << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "location.pop_back();" << std::endl;
			}

			m_Impl << (type_check ? "\t" : "") << "\t\t" << "return;" << std::endl;

			if (fieldType.GetRealType() == "Value" || fieldType.GetRealType() != rule.Type + "::Ptr")
				m_Impl << "\t\t" << "}" << std::endl;
		}
Example #18
0
 LITESQL_String type() const { return field->type(); }
Example #19
0
 LITESQL_String table() const { return field->table(); }
Example #20
0
 string table() const { return field->table(); }
Example #21
0
 string type() const { return field->type(); }
void FieldConnectorFactoryBase::registerConnector(
    const FieldType           &oSrcType,
    const FieldType           &oDstType,
    BasicFieldConnector *pSrcToDst,
    BasicFieldConnector *pDstToSrc)
{
    // src -> dst
    {
        EntryMapConstIt srcIt = mConnectorMap.find(oSrcType.getId());

        if(srcIt != mConnectorMap.end())
        {
            ConnectorMapConstIt dstIt =
                srcIt->second->find(oDstType.getId());

            if(dstIt != srcIt->second->end())
            {
                fprintf(stderr,
                        "error conversion already registered for %s -> %s\n",
                        oSrcType.getCName(),
                        oDstType.getCName());

                delete pSrcToDst;
            }
            else
            {
                (*(srcIt->second))[oDstType.getId()] = pSrcToDst;
            }
        }
        else
        {
            ConnectorMap *tmpMap = new ConnectorMap;

            (*tmpMap)[oDstType.getId()] = pSrcToDst;

            mConnectorMap[oSrcType.getId()] = tmpMap;
        }
    }

    // src -> dst
    {
        EntryMapConstIt dstIt = mConnectorMap.find(oDstType.getId());

        if(dstIt != mConnectorMap.end())
        {
            ConnectorMapConstIt srcIt =
                dstIt->second->find(oSrcType.getId());

            if(srcIt != dstIt->second->end())
            {
                fprintf(stderr,
                        "error conversion already registered for %s -> %s\n",
                        oDstType.getCName(),
                        oSrcType.getCName());

                delete pDstToSrc;
            }
            else
            {
                (*(dstIt->second))[oSrcType.getId()] = pDstToSrc;
            }
        }
        else
        {
            ConnectorMap *tmpMap = new ConnectorMap;

            (*tmpMap)[oSrcType.getId()] = pDstToSrc;

            mConnectorMap[oDstType.getId()] = tmpMap;
        }
    }
}
Example #23
0
 bool operator==(const FieldType & fd) const {
     return fd.fullName() == fullName();
 }
Example #24
0
 string name() const { return field->name(); }
void FieldContainerFactory::writeSingleTypeFCD(      std::ostream       &out, 
                                               const FieldContainerType *t  )
{
    FieldContainerType *parent = t->getParent();

    out << "<FieldContainer"                          << std::endl;
    out << "\tname=\""       << t->getCName() << "\"" << std::endl;

    if(parent != NULL)
        out << "\tparent=\"" << parent->getCName() << "\"" << std::endl;
    
    out << "\tlibrary=\""
        << "???"
        << "\"" 
        << std::endl;
    out << "\tstructure=\"" 
        << ( t->isAbstract()?"abstract":"concrete" ) 
        << "\""
        << std::endl;

    // look for pointerfield types
           std::string s;
           Int32       pt        = 0;
    static const Char8 *pftypes[] = {"none", "single", "multi", "both"};

    s  = "SF";
    s += t->getCName();
    s += "Ptr";

    if(FieldFactory::the().getFieldType(s.c_str()) != NULL)
    {
        pt |= 1;
    }

    s  = "MF";
    s += t->getCName();
    s += "Ptr";
    
    if(FieldFactory::the().getFieldType(s.c_str()) != NULL)
    {
        pt |= 2;
    }

    out << "\tpointerfieldtypes=\"" << pftypes[pt] << "\"" << std::endl;
    out << ">"                                             << std::endl;

    // Print the fields in this FC, ignore the parents' fields
    // !!! This should start at 0, FIX ME

    for(UInt32 i  = parent ? parent->getNumFieldDescs() + 1 : 1;
               i <= t->getNumFieldDescs();
               i++)
    {
        const FieldDescription *f  = t->getFieldDescription(i);
              FieldType        *ft = NULL;

        ft = FieldFactory::the().getFieldType(f->getTypeId());

        out << "\t<Field"                             << std::endl;
        out << "\t\tname=\"" << f->getCName() << "\"" << std::endl;

        // Filter the SF/MF from the type
        const Char8 *c = ft->getCName();

        if (! strncmp(c, "SF", 2) || ! strncmp(c, "MF", 2))
        {
            c += 2;
        }

        out << "\t\ttype=\"" << c << "\"" << std::endl;

        out << "\t\tcardinality=\""
            << (ft->getCardinality() ? "multi" : "single")
            << "\"" << std::endl;

        out << "\t\tvisibility=\"" 
            << (f->isInternal() ? "internal" : "external")
            << "\"" 
            << std::endl;
        
        out << "\t>"        << std::endl;
        out << "\t</Field>" << std::endl;
    }

    out << "</FieldContainer>" << std::endl;
}