Пример #1
0
		i_setting::id_type do_register_setting(const string& aSettingCategory, const string& aSettingName, simple_variant::type_e aSettingType, const simple_variant& aDefaultValue = simple_variant(), bool aHidden = false)
		{
			setting_by_name_list::iterator iterCheck = iSettingsByName.find(setting_by_name_list::key_type(aSettingCategory, aSettingName));
			if (iterCheck != iSettingsByName.end())
				throw setting_already_registered();
			simple_variant currentValue = aDefaultValue;
			if (iStore.get() != 0)
			{
				xml::element::iterator xmlIterCategory = iStore->root().find(aSettingCategory.c_str());
				if (xmlIterCategory != iStore->root().end())
				{
					xml::element::iterator xmlIterSetting = xmlIterCategory->find(aSettingName.c_str());
					if (xmlIterSetting != xmlIterCategory->end())
					{
						if (aSettingType != i_simple_variant::CustomType)
							currentValue = from_string(xmlIterSetting->attribute_value("value"), aSettingType);
						else
						{
							string valueType = xmlIterSetting->attribute_value("type");
							string valueData = xmlIterSetting->attribute_value("value");
							currentValue = simple_variant(auto_ref<i_custom_type>(iCustomSettingTypeFactory->create(valueType, valueData)));
						}
					}
				}
			}
			setting_list::iterator iter = iSettings.insert(setting(*this, iNextSettingId++, aSettingCategory, aSettingName, aSettingType, currentValue, aHidden));
			iSettingsByName[std::pair<string, string>(aSettingCategory, aSettingName)] = iter->id();
			return iter->id();
		}
Пример #2
0
    /** Parses the input stream @p is for a word consisting of characters and
     * digits (<i>a-z, A-Z, 0-9</i>) and underscores (<i>_</i>).
     * The failbit of the stream is set if the word is not a valid identifier.
     */
    std::istream & parse(std::istream & is)
    {
        std::string word;
        char c;

        while ( is.peek() != std::char_traits< char >::eof())
        {
            is >> c;
            if ( isspace(c) && word.empty() )
            {
                continue;
            }
            if ( isalnum(c) || (c == '_') || c == '-' )
            {
                word += c;
            }
            else
            {
                is.unget();
                break;
            }
        }

        try
        {
            from_string( word );
        }
        catch (illegal_enum_value const&)
        {
            is.setstate(std::ios::failbit);
        }

        return is;
    }
Пример #3
0
AVReceiver::AVReceiver(Params &p, int default_port, int _connection_type):
    ref_count(0),
    params(p),
    econ(NULL),
    timer_con(NULL),
    isConnected(false),
    volume_main(0),
    volume_zone2(0),
    volume_zone3(0),
    power_main(false),
    power_zone2(false),
    power_zone3(false),
    source_main(0),
    source_zone2(0),
    source_zone3(0),
    connection_type(_connection_type)
{
    cDebugDom("output") << params["id"];

    if (!params.Exists("visible")) params.Add("visible", "false");

    host = params["host"];
    port = default_port;

    if (params.Exists("port"))
        from_string(params["port"], port);

    ehandler_add = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_con_server_add, this);
    ehandler_del = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb)_con_server_del, this);
    ehandler_data = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb)_con_server_data, this);

    timerConnReconnect();
    timer_con = new EcoreTimer(AVR_RECONNECT, (sigc::slot<void>)sigc::mem_fun(*this, &AVReceiver::timerConnReconnect));
}
Пример #4
0
// gets the auto-assigned id of a template instantiation
int rl_get_template_id( const char *prod_name )
{
	std::string temp = prod_name;
	
	// has to be at least "rl*a*#" (where a is a single letter/number/etc)
	if ( temp.length() < 6 )
		return -1;
	
	// check first three letters are "rl*"
	if ( temp.compare( 0, 3, "rl*" ) )
		return -1;
	
	// find last * to isolate id
	std::string::size_type last_star = temp.find_last_of( '*' );
	if ( last_star == std::string::npos )
		return -1;
	
	// make sure there's something left after last_star
	if ( last_star == ( temp.length() - 1 ) )
		return -1;
	
	// make sure id is a valid natural number
	std::string id_str = temp.substr( last_star + 1 );
	if ( !is_whole_number( id_str ) )
		return -1;
	
	// convert id
	int id;
	from_string( id, id_str );
	return id;
}
Пример #5
0
int from_variant(variant node)
{
	if(node.is_string()) {
		return from_string(node.as_string());
	}
	return node.as_int(-1);
}
void AudioPlayer::get_volume_cb(AudioPlayerData data)
{
    int vol;
    from_string(data.svalue, vol);

    set_volume(data.ivalue + vol);
}
Пример #7
0
IOAVReceiver::IOAVReceiver(Params &p):
    IOBase(p, IOBase::IO_INOUT),
    zone(1)
{
    // Define IO documentation
    ioDoc->friendlyNameSet("AVReceiver");
    ioDoc->descriptionSet(_("AVReceiver object to control network amplifier"));
    ioDoc->paramAdd("host", _("IP address of the device"), IODoc::TYPE_STRING, true);
    ioDoc->paramAddInt("port", _("Port to use for connection"), 0, 65535, false);
    ioDoc->paramAddInt("zone", _("Zone of the amplifier (if supported)"), 0, 10, false);
    ioDoc->paramAdd("model", _("AVReceiver model. Supported: pioneer, denon, onkyo, marantz, yamaha"), IODoc::TYPE_STRING, true);

    ioDoc->actionAdd("power on", _("Switch receiver on"));
    ioDoc->actionAdd("power off", _("Switch receiver off"));
    ioDoc->actionAdd("volume 50", _("Set current volume"));
    ioDoc->actionAdd("source X", _("Change current input source"));
    ioDoc->actionAdd("custom XXXXXX", _("Send a custom command to receiver (if you know the protocol)"));

    get_params().Add("gui_type", "avreceiver");
    get_params().Add("visible", "false");
    if (get_params().Exists("zone"))
        from_string(get_param("zone"), zone);
    receiver = AVRManager::Instance().Create(p);

    if (zone == 1 && receiver)
        receiver->state_changed_1.connect(sigc::mem_fun(*this, &IOAVReceiver::statusChanged));
    if (zone == 2 && receiver)
        receiver->state_changed_2.connect(sigc::mem_fun(*this, &IOAVReceiver::statusChanged));
    if (zone == 3 && receiver)
        receiver->state_changed_3.connect(sigc::mem_fun(*this, &IOAVReceiver::statusChanged));
}
Пример #8
0
void AudioPlayer::audio_playlist_size_get_cb(bool success, vector<string> result, void *data)
{
    if (result.size() != 4) return;

    from_string(result[3], playlist_size);
    player_playlist_changed.emit();
}
 /// Create an address from an IPv4 address string in dotted decimal form,
 /// or from an IPv6 address in hexadecimal notation.
 static address from_string(const char* str)
 {
   asio::error_code ec;
   address addr = from_string(str, ec);
   asio::detail::throw_error(ec);
   return addr;
 }
Пример #10
0
bool IntPositive::set_default(const char* value)
{
    bool ok = from_string(value, default_);
    str_default_ = oskar_settings_utility_int_to_string(default_);
    if (ok)
        set_value(value);
    return ok;
}
Пример #11
0
/** \brief constructor of the ip_addr_t class from a string
 */
ip_addr_t::ip_addr_t(const std::string &ip_addr_str)		throw()
{
	if( from_string(ip_addr_str.c_str()) ){
		KLOG_DBG("ip_addr_t constructor cant parse " << ip_addr_str << " address. nullifying!");
		//DBGNET_ASSERT( 0 );
		nullify();
	}
}
Пример #12
0
    static int OnEvent(int code, netsnmp_session *sess, int reqid,
                       netsnmp_pdu *pdu, void *ctxt) {
        v8::HandleScope scope;
        std::auto_ptr<Callable> wrap(reinterpret_cast<Callable*>(ctxt));
        assert(0 != wrap.get());

        v8::TryCatch try_catch;
        v8::Handle<v8::Value> args[] = {
			v8::Undefined(), wrap->pdu_, Pdu::New(pdu) 
        };


        switch(code) {
        case NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE:
            args[0] = v8::Undefined();
            break;
        case NETSNMP_CALLBACK_OP_TIMED_OUT:
            args[0] = from_string("timeout", 7);
            break;
        case NETSNMP_CALLBACK_OP_SEND_FAILED:
            args[0] = from_string("send_error", 10);
            break;
        case NETSNMP_CALLBACK_OP_CONNECT:
            args[0] = from_string("connect", 7);
            break;
        case NETSNMP_CALLBACK_OP_DISCONNECT:
            args[0] = from_string("disconnect", 10);
            break;
        default:
            args[0] = from_string("unknown", 7);
            break;
        }

        // get process from global scope.
        v8::Local<v8::Object> global = v8::Context::GetCurrent()->Global();
        v8::Local<v8::Object> process = global->Get(process_symbol)->ToObject();

        wrap->cb_->CallAsFunction(process, 3, args);
        if (try_catch.HasCaught()) {
            node::FatalException(try_catch);
        }

        return 1;
    }
Пример #13
0
void AudioPlayer::audio_volume_get_cb(bool success, vector<string> result, void *data)
{
    if (result.size() != 3) return;

    vector<string> tmp;
    Utils::split(result[2], tmp, ":", 2);

    from_string(tmp[1], volume);
    player_volume_changed.emit();
}
Пример #14
0
 mpint( T value_,
     typename boost::enable_if<
     typename boost::is_integral<
     typename boost::remove_cv< T >::type
     >::type
     >::type* = NULL
     ) {
   MPINT_SAFE_CALL( mp_init( &value ) );
   mp_zero( &value );
   from_string( boost::lexical_cast< std::string >( value_ ), 10 );
 }
Пример #15
0
//=============================================================================
Uri::Uri(const ScriptRef* args)
  : m_port(0)
{
  DEBUG_COUNT_CONSTRUCTOR(Uri);

  const ScriptString* str = get_method_arg<ScriptString>(args,0,"value");
  if (str) {
    // Set from string
    from_string(str->get_string());
  }
}
Пример #16
0
	/**
	 * @param s URL string to be parsed into its components.
	 *
	 * @returns A @c url object corresponding to the specified string.
	 *
	 * @throws boost::system::system_error Thrown when the URL string is invalid.
	 */
	static url from_string(const char* s)
	{
		boost::system::error_code ec;
		url new_url(from_string(s, ec));
		if (ec)
		{
			boost::system::system_error ex(ec);
			boost::throw_exception(ex);
		}
		return new_url;
	}
Пример #17
0
bool timeInRange(string cTime, string startTime, string endTime) {
    int cHour, cMin, startHour, startMin, endHour, endMin;
    cHour = cMin = startHour = startMin = endHour = endMin = -1;
    vector<string> splits;
    splits = split(cTime, ':');
    if(splits.size() == 2) {
        if(!from_string(cHour, splits[0], std::dec))
            cHour = -1;
        if(!from_string(cMin, splits[1], std::dec))
            cMin = -1;
    }

    splits = split(startTime, ':');
    if(splits.size() == 2) {
        if(!from_string(startHour, splits[0], std::dec))
            startHour = -1;
        if(!from_string(startMin, splits[1], std::dec))
            startMin = -1;
    }

    splits = split(endTime, ':');
    if(splits.size() == 2) {
        if(!from_string(endHour, splits[0], std::dec))
            endHour = -1;
        if(!from_string(endMin, splits[1], std::dec))
            endMin = -1;
    }

    if(cHour != -1 && cMin != -1 && startHour != -1 && startMin != -1 && endHour != -1 && endMin != -1)
        return (timeInRange(cHour, cMin, startHour, startMin, endHour, endMin));
    return false;
}
Пример #18
0
/*
 * to deserialize a string to task result
 */
template <class T> vector<T> ReduceTask<T>::deserialize(string &s) {
	vector<T> elems;
	vector<string> vs;
	splitString(s, vs, REDUCE_TASK_DELIMITATION);

	for(unsigned int i=0; i<vs.size(); i++) {
		T t;
		from_string(t, vs[i]);
		elems.push_back(t);
	}
	return elems;

}
Пример #19
0
void AudioPlayer::audio_playlist_size_get_added_cb(bool success, vector<string> result, void *data)
{
    if (result.size() != 4) return;

    int nb_added = playlist_size;
    from_string(result[3], playlist_size);
    nb_added = playlist_size - nb_added;

    if (nb_added < 0)
        player_playlist_changed.emit();
    else
        player_playlist_tracks_added.emit(nb_added);
}
Пример #20
0
void AudioPlayer::audio_time_get_cb(bool success, vector<string> result, void *data)
{
    time_inprocess = false;

    if (result.size() != 3) return;

    vector<string> tmp;
    Utils::split(result[2], tmp, ":", 2);

    from_string(tmp[1], elapsed_time);
    params.Add("time", Utils::time2string_digit((long)elapsed_time));
    player_time_changed.emit();
}
Пример #21
0
TimeRange::TimeRange(string proto):
    shour("0"), smin("0"), ssec("0"),
    ehour("0"), emin("0"), esec("0")
{
    vector<string> tokens;
    split(proto, tokens, ":", 11);

    shour = tokens[1];
    smin = tokens[2];
    ssec = tokens[3];
    from_string(tokens[4], start_type);
    from_string(tokens[5], start_offset);
    if (start_offset < 0) start_offset = -1;
    if (start_offset >= 0) start_offset = 1;

    ehour = tokens[6];
    emin = tokens[7];
    esec = tokens[8];
    from_string(tokens[9], end_type);
    from_string(tokens[10], end_offset);
    if (end_offset < 0) end_offset = -1;
    if (end_offset >= 0) end_offset = 1;
}
Пример #22
0
T from_string(const std::string& what) {
    object o = from_string(what);
    const std::type_info& tinfo = typeid(T);
    if (tinfo == *(o.type())) {
        return std::move(get_ref<T>(o));
    }
    else {
        std::string error_msg = "expected type name ";
        error_msg += uniform_typeid(tinfo)->name();
        error_msg += " found ";
        error_msg += o.type()->name();
        throw std::logic_error(error_msg);
    }
}
Пример #23
0
    explicit
    dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s,
        typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0,
        typename std::basic_string<CharT, Traits, Alloc>::size_type n
            = (std::basic_string<CharT, Traits, Alloc>::npos),
        const Allocator& alloc = Allocator())
        : detail::dynamic_bitset_base<Block, Allocator>
            (std::min(n, s.size() - pos), alloc)
#endif
    {
        // Locate sub string
        assert(pos <= s.length());
        from_string(s, pos, std::min(n, s.size() - pos));
    }
Пример #24
0
	void SaveValue(DialogItemEx *Item, int RadioGroupIndex) override
	{
		{
			long long Value;
			if (from_string(Item->strData, Value))
			{
				*IntValue = Value;
				return;
			}
		}

		{
			unsigned long long Value;
			if (from_string(Item->strData, Value))
			{
				*IntValue = Value;
				return;
			}
		}

		// not changed
		// TODO: diagnostics
	}
Пример #25
0
/** Resolve the absolute path and use C++ file io to load the file.
 */
static char *default_import_callback(void *ctx, const char *base, const char *file, int *success)
{
    auto *vm = static_cast<JsonlangVm*>(ctx);

    if (std::strlen(file) == 0) {
        *success = 0;
        return from_string(vm, "The empty string is not a valid filename");
    }

    if (file[std::strlen(file) - 1] == '/') {
        *success = 0;
        return from_string(vm, "Attempted to import a directory");
    }

    std::string abs_path;
    // It is possible that file is an absolute path
    if (file[0] == '/')
        abs_path = file;
    else
        abs_path = std::string(base) + file;

    std::ifstream f;
    f.open(abs_path.c_str());
    if (!f.good()) {
        *success = 0;
        return from_string(vm, std::strerror(errno));
    }
    try {
        std::string input;
        input.assign(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>());
        *success = 1;
        return from_string(vm, input);
    } catch (const std::ios_base::failure &io_err) {
        *success = 0;
        return from_string(vm, io_err.what());
    }
}
Пример #26
0
void AudioPlayer::getInputSource_cb(bool success, vector<string> result, void *data)
{
    if (!success) return;

    amplifier_inputs.clear();
    for (unsigned int i = 4;i < result.size();i++)
    {
        vector<string> tok;
        int num;
        split(result[i], tok, ":", 2);
        from_string(tok[0], num);

        amplifier_inputs[num] = tok[1];
    }
}
Пример #27
0
		boost::gregorian::date DBResult::getDate( const std::string& name ) const
		{
			try
			{
				string text(getText(name));
				if(!text.empty())
				{
					return from_string(text);
				}
			}
			catch(...)
			{
			}
			return date(not_a_date_time);
		}
Пример #28
0
int main()
{
	list l = from_string("[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []", 0, 0);

	printf("Nested: ");
	show_list(l);
	printf("\n");

	list flat = flatten(l, 0);
	printf("Flattened: ");
	show_list(flat);

	/* delete_list(l); delete_list(flat); */
	return 0;
}
Пример #29
0
NEOIP_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//                    CTOR/DTOR
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

/** \brief constructor of the ip_addr_t class from a string
 */
ip_addr_t::ip_addr_t(const char *ip_addr_str)		throw()
{
	if( from_string(ip_addr_str) ){
		KLOG_DBG("ip_addr_t constructor cant parse " << ip_addr_str << " address. nullifying!");
		//DBGNET_ASSERT( 0 );
		nullify();
	}
}
void ActivityCameraListController::cameraSelectCallback(void *data, Evas_Object *edje_object, string emission, string source)
{
    if (emission.substr(0, 7) == "select,")
        emission = emission.erase(0, 7);
    int position;
    from_string(emission, position);

    if ((page * 4 + position - 1) >= (int)CalaosModel::Instance().getCamera()->cameras.size())
        return;

    list<Camera *>::iterator it = CalaosModel::Instance().getCamera()->cameras.begin();
    for (int j = 0;j < page * 4 + position - 1;j++)
        it++;

    ActivityCameraSelectController *controller = new ActivityCameraSelectController(*it, evas, parent);
    parentController->addSubController(controller);
}