//============================================================================== /// Get the unit with the given name. /// /// \param [in] name The name of the unit. /// /// \return A pointer to the unit, or NULL if not present. /// Unit *UnitSystem::GetUnit( const QString& name ) { QHash<QString,Unit*>::const_iterator it = m_units.find( NormalizeName( name ) ); return ( it != m_units.end() ) ? it.value() : NULL; }
//============================================================================== /// Get the dimension with the given name. /// /// \param [in] name The name of the dimension. /// /// \return The dimension, or NULL if not present. /// Dimension *UnitSystem::GetDimension( const QString& name ) { QHash<QString,Dimension*>::const_iterator it = m_dimensions.find( NormalizeName( name ) ); return ( it != m_dimensions.end() ) ? it.value() : NULL; }
void CountryCollection::WriteTags(const std::string& fileName) const { std::ofstream tagsFile(fileName); if (!tagsFile) throw std::runtime_error("Error creating tags file"); for (const auto& countryPair : countries) tagsFile << countryPair.first << " = " << "countries/" << NormalizeName(countryPair.second.GetName()) << ".txt\n"; }
//============================================================================== /// Add a new unit to the unit system. /// /// \param [in] name The unit name. /// \param [in] dim_p The unit dimension. /// /// \return The new unit. /// Unit *UnitSystem::NewUnit( const QString& name, Dimension *dim_p ) { assert( !GetUnit( name ) ); Unit *unit_p = new Unit( name, dim_p ); m_units.insert( NormalizeName( name ), unit_p ); return unit_p; }
void CountryCollection::WriteHistory(const std::string& path) const { for (const auto& countryPair : countries) { const auto& country = countryPair.second; std::ofstream historyFile(path + '\\' + country.GetTag() + " - " + NormalizeName(country.GetName()) + ".txt"); if (!historyFile) throw std::runtime_error("Error creating common history file for country " + country.GetName()); country.WriteHistory(historyFile); } }
void CountryCollection::WriteCommonInfo(const std::string& path) const { for (const auto& countryPair : countries) { const auto& country = countryPair.second; std::ofstream commonFile(path + '\\' + NormalizeName(country.GetName()) + ".txt"); if (!commonFile) throw std::runtime_error("Error creating common country file for country " + country.GetName()); country.WriteCommonInfo(commonFile); } }
//============================================================================== /// Add a new dimension to the unit system. /// /// \param [in] name The name of the dimension. /// \param [in] id The ID of the dimension. /// /// \return The dimension. /// Dimension *UnitSystem::NewDimension( const QString& name, const DimensionId& id ) { // \todo Throw exception. assert( !GetDimension( name ) ); assert( !GetDimension( id ) ); Dimension *dim_p = new Dimension( name, id ); m_dimensions.insert( NormalizeName( name ), dim_p ); return dim_p; }
bool TRI_ValidateArgsFunctionAql (TRI_aql_context_t* const context, const TRI_aql_function_t* const function, const TRI_aql_node_t* const parameters) { param_t allowed; const char* pattern; size_t i, n; bool eof = false; bool repeat = false; assert(function); assert(parameters); assert(parameters->_type == TRI_AQL_NODE_LIST); n = parameters->_members._length; // validate number of arguments if (n < function->_minArgs || n > function->_maxArgs) { // invalid number of arguments TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH, NormalizeName(function)); return false; } pattern = function->_argPattern; // validate argument types for (i = 0; i < n; ++i) { TRI_aql_node_t* parameter = (TRI_aql_node_t*) TRI_AQL_NODE_MEMBER(parameters, i); if (repeat) { // last argument is repeated ARG_CHECK } else { // last argument is not repeated bool parse = true; bool foundArg; allowed = InitParam(); foundArg = false; while (parse && ! eof) { char c = *pattern++; switch (c) { case '\0': parse = false; eof = true; if (foundArg) { ARG_CHECK } break; case '|': // optional marker if (foundArg) { parse = false; ARG_CHECK if (*pattern == '+') { repeat = true; eof = true; } } break; case ',': // next argument assert(foundArg); parse = false; ARG_CHECK break; case '+': // repeat last argument repeat = true; parse = false; eof = true; ARG_CHECK break; case '.': // any type except collections allowed._list = true; allowed._array = true; // break intentionally missing!! case 'p': // primitive types allowed._null = true; allowed._bool = true; allowed._number = true; allowed._string = true; foundArg = true; break; case 'z': // null allowed._null = true; foundArg = true; break; case 'b': // bool allowed._bool = true; foundArg = true; break; case 'n': // number allowed._number = true; foundArg = true; break; case 's': // string allowed._string = true; foundArg = true; break; case 'l': // list allowed._list = true; foundArg = true; break; case 'a': // array allowed._array = true; foundArg = true; break; case 'c': // collection name => list allowed._collection = true; foundArg = true; break; case 'h': // collection name => string allowed._collection = true; foundArg = true; break; case 'r': // regex allowed._regex = true; foundArg = true; break; } } } }