"Fossies" - the Fresh Open Source Software Archive

Member "regexxer-0.10/src/completionstack.cc" (6 Oct 2011, 2977 Bytes) of package /linux/privat/old/regexxer-0.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "completionstack.cc" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2009  Fabien Parent  <parent.f@gmail.com>
    3  *
    4  * This file is part of regexxer.
    5  *
    6  * regexxer is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * regexxer is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License
   17  * along with regexxer; if not, write to the Free Software Foundation,
   18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19  */
   20 
   21 #include "completionstack.h"
   22 
   23 #include <gtkmm/liststore.h>
   24 
   25 namespace Regexxer
   26 {
   27 
   28 CompletionStack::CompletionStack(const std::list<Glib::ustring>& stack) :
   29   infinite_stack_(true),
   30   stack_size_(0),
   31   completion_column_model_(),
   32   completion_model_(Gtk::ListStore::create(completion_column_model_))
   33 {
   34   push(stack);
   35 }
   36 
   37 CompletionStack::CompletionStack(unsigned int stack_size, const std::list<Glib::ustring>& stack) :
   38   infinite_stack_(false),
   39   stack_size_(stack_size),
   40   completion_column_model_(),
   41   completion_model_(Gtk::ListStore::create(completion_column_model_))
   42 {
   43   push(stack);
   44 }
   45 
   46 void CompletionStack::push(const std::list<Glib::ustring> values)
   47 {
   48   for (std::list<Glib::ustring>::const_reverse_iterator item = values.rbegin();
   49        item != values.rend(); item++)
   50   {
   51     push(*item);
   52   }
   53 }
   54 
   55 void CompletionStack::push(const Glib::ustring value)
   56 {
   57   if (value.empty())
   58     return;
   59   
   60   Gtk::ListStore::Children children = completion_model_->children();
   61   for (Gtk::ListStore::Children::iterator i = children.begin(); i != children.end(); i++)
   62   {
   63     if (i->get_value(completion_column_model_.value_) == value)
   64     {
   65       completion_model_->move(i, children.begin());
   66       return;
   67     }
   68   }
   69   
   70   Gtk::TreeModel::Row row = *(completion_model_->prepend());
   71   row[completion_column_model_.value_] = value;
   72   
   73   if (!infinite_stack_ && children.size() > stack_size_)
   74   {
   75     Gtk::ListStore::Children::iterator last_element = --(children.end());
   76     completion_model_->erase(last_element);
   77   }
   78 }
   79 
   80 std::list<Glib::ustring> CompletionStack::get_stack()
   81 {
   82   std::list<Glib::ustring> return_stack;
   83   Gtk::ListStore::Children children = completion_model_->children();
   84   for (Gtk::ListStore::Children::iterator i = children.begin(); i != children.end(); i++)
   85   {
   86     return_stack.push_back(i->get_value(completion_column_model_.value_));
   87   }
   88   
   89   return return_stack;
   90 }
   91 
   92 Glib::RefPtr<Gtk::ListStore> CompletionStack::get_completion_model()
   93 {
   94   return completion_model_;
   95 }
   96 
   97 Gtk::TreeModelColumn<Glib::ustring> CompletionStack::get_completion_column()
   98 {
   99     return completion_column_model_.value_;
  100 }
  101 
  102 CompletionStack::~CompletionStack()
  103 {
  104   
  105 }
  106 
  107 } // namespace Regexxer