Exemple #1
0
 ~ModelReferencesSnapshot()
 {
   for(Iterators::iterator i = m_iterators.begin(); i != m_iterators.end(); ++i)
   {
     m_references.release(*i);
   }
 }
Exemple #2
0
// The exercise description is a little unclear whether it is strings or
// words should be counted. That is, should whitespace be taken into account
// or should simple words be matched?
//
// I chose to match simple strings, which consequently can overlap. For
// example, if the string "bcd" and "def" are being searched, they would
// both be matched in a line containing "abcdef". It is case sensitive.
map<const string,int> countStringLines(istream* input, const vector<string>& strings)
{
    // Initialize the return value, so that it contains all strings
    // even if they were not found.
    map<const string,int> stringCounts;
    for(vector<string>::const_iterator i = strings.begin(); i != strings.end(); i++)
    {
        stringCounts[*i] = 0;
    }

    typedef map<string const*,string::const_iterator> Iterators;
    Iterators iter;

    while(*input)
    {
        // Reset all iterators
        for(vector<string>::const_iterator i = strings.begin(); i != strings.end(); i++)
        {
            iter[&(*i)] = i->begin();
        }

        char ch;

        // Loop until end of line or input
        while(input->get(ch) && ch != '\n')
        {
            for(Iterators::iterator i = iter.begin(); i != iter.end(); i++)
            {
                if(i->second != i->first->end())
                {
                    if (*(i->second) == ch)
                    {
                        i->second++;
                        if(i->second == i->first->end())
                            stringCounts[*(i->first)]++;
                    }
                    else
                    {
                        i->second = i->first->begin();
                    }
                }
            }
        }
    }
    return stringCounts;
}
Exemple #3
0
 iterator begin()
 {
   return m_iterators.begin();
 }