std::string ReadValueStr(std::string prompt /*= std::string()*/, std::istream& in /*= std::cin*/, std::ostream* out /*= &std::cout*/)
{
    if (out)
        (*out) << prompt;

    std::string input;
    bool success = false;

    while (!success)
    {
        std::getline(in, input);

        if (in.fail())
        {
            if (in.eof())
            {
                in.clear();
                throw EOFCharacterValue();
            }
            else
            {
                in.clear();
                if (out)
                    (*out) << "Invalid value. Please try again." << std::endl;
                else
                    throw InvalidValue("ReadValue: Invalid value found with no out stream.");
                continue;
            }
        }
        success = true;
    }

    return input;
}
Beispiel #2
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, double& value__)
 {
   if (std::sscanf(args__[index__].c_str(), "%lf", &value__) != 1)
   throw InvalidValue();
   return 1;
 }
Beispiel #3
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, unsigned& value__, const char* format__ = "%u")
 {
   if (std::sscanf(args__[index__].c_str(), format__, &value__) != 1)
   throw InvalidValue();
   return 1;
 }
Beispiel #4
0
void ArticleTagSearch::setTag(const std::string& _tag)
{
	if(_tag.empty() || std::find_if(_tag.begin(), _tag.end(),
			invalidChar()) != _tag.end()) 
		throw InvalidValue(gettext("invalid tag"));
	tag = _tag;
}
Beispiel #5
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, ZUnits& value__)
 {
   if (args__[index__] == "DEPTH") value__ = DEPTH;
   else if (args__[index__] == "ALTITUDE") value__ = ALTITUDE;
   else throw InvalidValue();
   return 1;
 }
Beispiel #6
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, TxErrorType& value__)
 {
   if (args__[index__] == "SUCCESS") value__ = TX_ERR_SUCCESS;
   else if (args__[index__] == "TX_RETRY_LIMIT") value__ = TX_ERR_TX_RETRY_LIMIT;
   else throw InvalidValue();
   return 1;
 }
Beispiel #7
0
      static AbstractCommand*
      createByName(const std::string& name)
      {
#define COMMAND(cmd_name) if (name == #cmd_name) return new cmd_name();
#include "Factory.def"

        throw InvalidValue();
      }
Beispiel #8
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, ParamName& value__)
 {
   if (args__[index__] == "NODE_ID") value__ = NODE_ID;
   else if (args__[index__] == "BROADCAST_ID") value__ = BROADCAST_ID;
   else if (args__[index__] == "TX_POWER") value__ = TX_POWER;
   else throw InvalidValue();
   return 1;
 }
Beispiel #9
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, SpeedUnits& value__)
 {
   if (args__[index__] == "METER_PS") value__ = METER_PS;
   else if (args__[index__] == "RPM") value__ = RPM;
   else if (args__[index__] == "PERCENTAGE") value__ = PERCENTAGE;
   else throw InvalidValue();
   return 1;
 }
Beispiel #10
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, FailureType& value__)
 {
   if (args__[index__] == "INVALID_VERSION") value__ = FAIL_INVALID_VERSION;
   else if (args__[index__] == "INVALID_REQUEST") value__ = FAIL_INVALID_REQUEST;
   else if (args__[index__] == "EXPIRED") value__ = FAIL_EXPIRED;
   else if (args__[index__] == "INTERNAL_ERROR") value__ = FAIL_INTERNAL_ERROR;
   else if (args__[index__] == "BUSY") value__ = FAIL_BUSY;
   else throw InvalidValue();
   return 1;
 }
Beispiel #11
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, Maneuver*& value__)
 {
   size_t index_cursor__ = index__;
   std::string name__;
   index_cursor__ += decodeType(args__, index_cursor__, name__);
   if (name__ == "Goto") value__ = new Goto();
   else if (name__ == "StationKeeping") value__ = new StationKeeping();
   else throw InvalidValue();
   index_cursor__ += value__->decodeArgs(args__, index_cursor__);
   return index_cursor__ - index__;
 }
Beispiel #12
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, ErrorType& value__)
 {
   if (args__[index__] == "INVALID_CRC") value__ = ERR_INVALID_CRC;
   else if (args__[index__] == "INVALID_FORMAT") value__ = ERR_INVALID_FORMAT;
   else if (args__[index__] == "INVALID_VERSION") value__ = ERR_INVALID_VERSION;
   else if (args__[index__] == "INVALID_REQUEST") value__ = ERR_INVALID_REQUEST;
   else if (args__[index__] == "INVALID_VALUE") value__ = ERR_INVALID_VALUE;
   else if (args__[index__] == "BUSY") value__ = ERR_BUSY;
   else throw InvalidValue();
   return 1;
 }
Beispiel #13
0
 size_t
 decodeType(const std::vector<std::string>& args__, size_t index__, TxStatusType& value__)
 {
   if (args__[index__] == "RECEIVED") value__ = TX_STA_RECEIVED;
   else if (args__[index__] == "ERROR") value__ = TX_STA_ERROR;
   else if (args__[index__] == "QUEUED") value__ = TX_STA_QUEUED;
   else if (args__[index__] == "TX_START") value__ = TX_STA_TX_START;
   else if (args__[index__] == "TX_END") value__ = TX_STA_TX_END;
   else if (args__[index__] == "TRANSMITTED") value__ = TX_STA_TRANSMITTED;
   else if (args__[index__] == "DELIVERED") value__ = TX_STA_DELIVERED;
   else if (args__[index__] == "EXPIRED") value__ = TX_STA_EXPIRED;
   else if (args__[index__] == "CANCELED") value__ = TX_STA_CANCELED;
   else throw InvalidValue();
   return 1;
 }
Beispiel #14
0
qint32 ConfigManager<>::intAt(const QString& key) const
{
    QString hasKey = (*this)[key.toLower()];

    bool ok;
    int val = hasKey.toInt(&ok);

    if(!ok)
    {
        qDebug() << "[ConfigManager] Nieudana próba konwersji"
                 << _container[key] << "do qint32 dla klucza"
                 << key << ".";
        throw InvalidValue();
    }
    return val;
}
Beispiel #15
0
void ArticleTagSearch::genSearchString()
{
	if(tag.empty())
		throw InvalidValue(gettext("no tag defined for search"));

	search_string = "SELECT id FROM articles, tags WHERE tags.art_id = articles.id AND tags.tag = '"
			+ tag + "' AND read_level <= :Qread_level";
	if(cid)
		search_string += " AND cid = :Qcid";
	if(oid)
		search_string += " AND oid = :Qoid";
	search_string += " AND id > 0 ORDER BY " + order_col;
	if(order_asc)
		search_string += " ASC";
	else
		search_string += " DESC";
	if(limit)
		search_string += " LIMIT :Qlimit";
}
Beispiel #16
0
void Parser::ParseSight(char *msg)
{
	NetworkTest::instance().End("Sense", "Sight");

	mpObserver->SetLastSightRealTime(GetRealTimeParser()); // set the last sight time
	mpObserver->SetLatestSightTime(mpObserver->CurrentTime());

	msg = strstr(msg,"((");
	while ( msg != 0 ){ // 直到没有object为止
		msg += 2; // 跳过 ((
		ObjType obj = ParseObjType(msg); // 获得object的类型
		msg = strchr(msg,')');
		/**
 		 * (  MsgTpe Time  ((objname) objprop)  )
 		 *                          ^
 		 *                          |
 		 *                         msg
 		 */
		ObjProperty prop = ParseObjProperty(msg + 1);  // 获得object的属性

		switch ( obj.type ) {
		case OBJ_Marker:
		case OBJ_Marker_Behind:
			if ( obj.marker == FLAG_NONE ){
				if ( obj.type != OBJ_Marker_Behind ) {
					PARSE_ERROR("Should know the marker");
				}
				break;
			}
			if (InvalidValue(prop.dir_chg)) {
				mpObserver->SeeMarker(obj.marker, prop.dist, prop.dir);
			}
			else {                                          /* know direction*/
				mpObserver->SeeMarker(obj.marker, prop.dist, prop.dir, prop.dist_chg, prop.dir_chg);
			}
			break;
		case OBJ_Line:
			mpObserver->SeeLine(obj.line, prop.dist, prop.dir);
			break;
		case OBJ_Ball:
			if (InvalidValue(prop.dir_chg)) {                  /* high quality  */
				mpObserver->SeeBall(prop.dist, prop.dir);
			}
			else {                                          /* know direction*/
				mpObserver->SeeBall(prop.dist, prop.dir, prop.dist_chg, prop.dir_chg);
			}
			break;
		case OBJ_Player:
			if ( obj.side == '?'){                      /* Too far for team or num */
				if (InvalidValue(prop.dir_chg)) {         /* high quality  */
					mpObserver->SeePlayer(prop.dist, prop.dir);
				}
				else { /* know direction*/
					PARSE_ERROR("Shouldn't know dirChng when the player's far");
				}
			}
			else{ // 知道是哪边的
				if ( obj.num == 0 ){                  /* Too far for number     */
					if (InvalidValue(prop.dir_chg)) {   /* high quality  */
						mpObserver->SeePlayer(obj.side, prop.dist, prop.dir, prop.tackling, prop.kicked, prop.lying, prop.card_type);
					}
					else  {         /* know direction*/
						PARSE_ERROR("Shouldn't know dirChng when the team Member's far");
					}
				}
				else{                                   /* Know side AND number   */
					if (InvalidValue(prop.dir_chg)) {                  /* high quality  */
						mpObserver->SeePlayer(obj.side, obj.num, prop.dist, prop.dir, prop.pointing, prop.point_dir, prop.tackling, prop.kicked, prop.lying, prop.card_type);
					} else {                                          /* know direction*/
						mpObserver->SeePlayer(obj.side, obj.num, prop.dist, prop.dir, prop.dist_chg, prop.dir_chg,
								prop.body_dir, prop.head_dir, prop.pointing, prop.point_dir, prop.tackling, prop.kicked, prop.lying, prop.card_type);
					}
				}
			}
			break;
		default:
			break;
		}
		msg = strstr(msg,"(("); // 下一个object
	}
}
Beispiel #17
0
      //! Decode command in text form.
      //! @param[in] cmd command in text form.
      //! @return command object.
      static AbstractCommand*
      decode(const std::string& cmd)
      {
        // Validate CRC.
        if (AbstractCommand::getCRC(cmd) != AbstractCommand::computeCRC(cmd, cmd.size() - c_ssc_footer_size))
          throw InvalidChecksum();

        // Split command.
        std::vector<std::string> parts;
        DUNE::Utils::String::split(cmd, ",", parts);

        // Check minimum arguments.
        if (parts.size() < c_ssc_min_args)
          throw InvalidFormat("minimum arguments not present");

        // Extract prefix.
        if (parts[0] != c_ssc_prefix)
          throw InvalidFormat("invalid prefix");

        // Extract version.
        unsigned version = 0;
        if (std::sscanf(parts[AbstractCommand::OFFS_VERSION].c_str(), "%u", &version) != 1)
          throw InvalidVersion();

        // Extract flags.
        unsigned flags = 0;
        if (std::sscanf(parts[AbstractCommand::OFFS_FLAGS].c_str(), "%02X", &flags) != 1)
          throw InvalidFormat("invalid flags");

        // Extract TTL.
        unsigned ttl = 0;
        if (std::sscanf(parts[AbstractCommand::OFFS_TTL].c_str(), "%u", &ttl) != 1)
          throw InvalidFormat("invalid ttl");

        // Extract priority.
        unsigned priority = 0;
        if (std::sscanf(parts[AbstractCommand::OFFS_PRIORITY].c_str(), "%u", &priority) != 1)
          throw InvalidFormat("invalid priority");

        // Extract source.
        unsigned src = 0;
        if (std::sscanf(parts[AbstractCommand::OFFS_SRC].c_str(), "%u", &src) != 1)
          throw InvalidFormat("invalid source");

        // Extract number of destinations.
        unsigned dst_count = 0;
        if (std::sscanf(parts[AbstractCommand::OFFS_DST_COUNT].c_str(), "%u", &dst_count) != 1)
          throw InvalidFormat("invalid destination count");

        // Extract destinations.
        unsigned dst = 0;
        std::set<unsigned> dsts;
        for (unsigned i = 0; i < dst_count; ++i)
        {
          // FIXME: check size.
          if (std::sscanf(parts[AbstractCommand::OFFS_DST + i].c_str(), "%u", &dst) != 1)
            throw InvalidFormat("invalid destination");
          dsts.insert(dst);
        }

        // Command name.
        std::string name = parts[AbstractCommand::OFFS_DST + dst_count];
        AbstractCommand* cmd_obj = createByName(name);
        if (cmd_obj == NULL)
          throw InvalidValue();

        cmd_obj->setName(name);
        cmd_obj->setSource(src);
        cmd_obj->setDestinations(dsts);
        cmd_obj->setVersion(version);
        cmd_obj->setPriority(priority);
        cmd_obj->setTTL(ttl);
        cmd_obj->setFlags(flags);

        size_t args_start = AbstractCommand::OFFS_DST + dst_count + 1;
        cmd_obj->decodeArgs(parts, args_start);
        return cmd_obj;
      }
Beispiel #18
0
    // A conversion operator, will throw an exception if the object
    // is marked invalid
 operator T() const throw(InvalidValue)
 {
    if (!this->is_valid()) throw InvalidValue();
    return value;
 }