Exemple #1
0
 ~ModelReferencesSnapshot()
 {
   for(Iterators::iterator i = m_iterators.begin(); i != m_iterators.end(); ++i)
   {
     m_references.release(*i);
   }
 }
Exemple #2
0
 ModelReferencesSnapshot(ModelReferences& references) : m_references(references)
 {
   for(ModelReferences::iterator i = m_references.begin(); i != m_references.end(); ++i)
   {
     m_references.capture(i);
     m_iterators.push_back(i);
   }
 }
Exemple #3
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 #4
0
 void permute(Iterators& iters, std::vector<int>& class_indices, unsigned index, std::vector<Label>& labels, Filter& filter) const {
   if(index == iters.size() - 1) {
     while(iters[index] != classes[class_indices[index]].end()) {
       labels[index] = fromInt(*iters[index]);
       filter(labels);
       ++iters[index];
     }
   } else {
     while(iters[index] != classes[class_indices[index]].end()) {
       labels[index] = fromInt(*iters[index]);
       permute(iters, class_indices, index + 1, labels, filter);
       iters[index + 1] = classes[class_indices[index + 1]].begin();
       ++iters[index];
     }
   }
 }
Exemple #5
0
 iterator end()
 {
   return m_iterators.end();
 }
Exemple #6
0
 iterator begin()
 {
   return m_iterators.begin();
 }