/**
       Parses a stream of the form 

       # Comment
       key1 = value1
       key2 = value2

       \param[in] configuration Stream with configuration data. Typically as
                  read from a configuration file.
    */
    void ConfigurationParser::ParseStream(std::wistream& configuration)
    {
        SCXCoreLib::SCXLogHandle log = SCXLogHandleFactory::GetLogHandle(L"scx.core.providers.runasprovider.configparser");

        std::vector<std::wstring> lines;
        SCXStream::NLFs nlfs;
        SCXStream::ReadAllLines(configuration, lines, nlfs);
        SCX_LOGTRACE(log, StrAppend(L"Number of lines in configuration: ", lines.size()));

        for (std::vector<std::wstring>::const_iterator it = lines.begin();
             it != lines.end(); it++)
        {
            std::wstring line = StrTrim(*it);
            SCX_LOGTRACE(log, StrAppend(L"Parsing line: ", line));
            if (line.length() == 0 ||
                line.substr(0,1) == L"#") //comment
            {
                continue;
            }
            std::vector<std::wstring> parts;
            StrTokenize(line, parts, L"=");
            if (parts.size() == 2)
            {
                iterator iter = lower_bound(parts[0]);
                if ((end() != iter) && !(key_comp()(parts[0], iter->first)))
                {
                    iter->second = parts[1];
                }
                else
                {
                    insert(iter, std::pair<const std::wstring, std::wstring>(parts[0], parts[1]));
                }
            }
        }
    }
Ejemplo n.º 2
0
Archivo: map.hpp Proyecto: zoid/ztl
	inline Value&				operator[](const key_type& _k) {
		iterator i = this->lower_bound(_k);

		if (i == end() || key_comp()(_k, (*i).first))
			i = insert(i, value_type(_k, Value()));
		
		return (*i).second;
	}
void
exit_handler_intel_x64::unittest_1009_containers_set() const
{
    auto myset = std::set<int>({0, 1, 2, 3});
    auto myset2 = std::set<int>({0, 1, 2, 3});

    auto total = 0;
    for (auto iter = myset.begin(); iter != myset.end(); iter++)
        total += *iter;

    auto rtotal = 0;
    for (auto iter = myset.rbegin(); iter != myset.rend(); iter++)
        rtotal += *iter;

    auto ctotal = 0;
    for (auto iter = myset.cbegin(); iter != myset.cend(); iter++)
        ctotal += *iter;

    auto crtotal = 0;
    for (auto iter = myset.crbegin(); iter != myset.crend(); iter++)
        crtotal += *iter;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(myset.size() == 4);
    expect_true(myset.max_size() >= 4);
    expect_false(myset.empty());

    myset.insert(myset.begin(), 0);
    myset.erase(myset.begin());
    myset = myset2;

    myset.swap(myset2);
    myset.swap(myset2);

    myset.emplace();
    myset.emplace_hint(myset.begin());
    myset = myset2;

    myset.key_comp();
    myset.value_comp();

    expect_true(myset.find(0) != myset.end());
    expect_true(myset.count(0) == 1);
    expect_true(myset.lower_bound(0) != myset.end());
    expect_true(myset.upper_bound(0) != myset.end());
    myset.equal_range(0);

    myset.get_allocator();
    myset.clear();
}
Ejemplo n.º 4
0
/** sort_hosts:
 ** Sorts #hosts# based on common prefix match and key distance from #Key#
 */
void sort_hosts (void *logs, ChimeraHost ** hosts, Key key, int size)
{
    int i, j;
    ChimeraHost *tmp;
    Key dif1;
    Key dif2;
    int pmatch1 = 0;
    int pmatch2 = 0;


    for (i = 0; i < size; i++)
	{
	    for (j = i + 1; j < size; j++)
		{
		    if (hosts[i] != NULL && hosts[j] != NULL)
			{
			    pmatch1 = key_index (logs, key, hosts[i]->key);
			    pmatch2 = key_index (logs, key, hosts[j]->key);
			    if (pmatch2 > pmatch1)
				{
				    tmp = hosts[i];
				    hosts[i] = hosts[j];
				    hosts[j] = tmp;
				}
			    else if (pmatch1 == pmatch2)
				{

				    key_distance (logs, &dif1, &hosts[i]->key,
						  &key);
				    key_distance (logs, &dif2, &hosts[j]->key,
						  &key);
				    if (key_comp (&dif2, &dif1) < 0)
					{
					    tmp = hosts[i];
					    hosts[i] = hosts[j];
					    hosts[j] = tmp;
					}
				}
			}

		}
	}
}
Ejemplo n.º 5
0
/** find_closest_key:
 ** finds the closest node in the array of #hosts# to #key# and put that in min.
 */
ChimeraHost *find_closest_key (void *state, ChimeraHost ** hosts, Key key,
			       int size)
{

    int i, j;
    Key dif;
    Key mindif;
    ChimeraHost *min, *tmp;
    ChimeraState *chs = (ChimeraState *) state;

    if (size == 0)
	{
	    min = NULL;
	    return;
	}

    else
	{
	    min = hosts[0];
	    key_distance (chs->log, &mindif, &hosts[0]->key, &key);
	}

    for (i = 0; i < size; i++)
	{

	    if (hosts[i] != NULL)
		{
		    key_distance (chs->log, &dif, &hosts[i]->key, &key);

		    if (key_comp (&dif, &mindif) < 0)
			{
			    min = hosts[i];
			    key_assign (&mindif, dif);
			}
		}
	}
    tmp = host_get (chs, min->name, min->port);
    return (min);
}
Ejemplo n.º 6
0
/** sort_hosts_key:
 ** Sorts #hosts# based on their key distance from #Key#, closest node first
 */
void sort_hosts_key (void *logs, ChimeraHost ** hosts, Key key, int size)
{
    int i, j;
    ChimeraHost *tmp;
    Key dif1;
    Key dif2;
    for (i = 0; i < size; i++)
	{
	    for (j = i + 1; j < size; j++)
		{
		    if (hosts[i] != NULL && hosts[j] != NULL)
			{
			    key_distance (logs, &dif1, &hosts[i]->key, &key);
			    key_distance (logs, &dif2, &hosts[j]->key, &key);
			    if (key_comp (&dif2, &dif1) < 0)
				{
				    tmp = hosts[i];
				    hosts[i] = hosts[j];
				    hosts[j] = tmp;
				}
			}
		}
	}
}
void
exit_handler_intel_x64::unittest_100A_containers_map() const
{
    auto mymap = std::map<int, int>();
    auto mymap2 = std::map<int, int>();

    mymap2[0] = 0;
    mymap2[1] = 1;
    mymap2[2] = 2;
    mymap2[3] = 3;

    mymap = mymap2;

    auto total = 0;
    for (auto iter = mymap.begin(); iter != mymap.end(); iter++)
        total += iter->second;

    auto rtotal = 0;
    for (auto iter = mymap.rbegin(); iter != mymap.rend(); iter++)
        rtotal += iter->second;

    auto ctotal = 0;
    for (auto iter = mymap.cbegin(); iter != mymap.cend(); iter++)
        ctotal += iter->second;

    auto crtotal = 0;
    for (auto iter = mymap.crbegin(); iter != mymap.crend(); iter++)
        crtotal += iter->second;

    expect_true(total == 6);
    expect_true(rtotal == 6);
    expect_true(ctotal == 6);
    expect_true(crtotal == 6);

    expect_true(mymap.size() == 4);
    expect_true(mymap.max_size() >= 4);
    expect_false(mymap.empty());

    expect_true(mymap.at(0) == 0);
    expect_true(mymap.at(3) == 3);

    mymap.insert(std::pair<int, int>(4, 4));
    mymap.erase(4);
    mymap = mymap2;

    mymap.swap(mymap2);
    mymap.swap(mymap2);

    mymap.emplace();
    mymap.emplace_hint(mymap.begin(), std::pair<int, int>(4, 4));
    mymap = mymap2;

    mymap.key_comp();
    mymap.value_comp();

    expect_true(mymap.find(0) != mymap.end());
    expect_true(mymap.count(0) == 1);
    expect_true(mymap.lower_bound(0) != mymap.end());
    expect_true(mymap.upper_bound(0) != mymap.end());
    mymap.equal_range(0);

    mymap.get_allocator();
    mymap.clear();
}