Back to index

easystroke  0.5.5.1
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends
ActionListDiff Class Reference

#include <actiondb.h>

Collaboration diagram for ActionListDiff:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::list
< ActionListDiff >::iterator 
iterator

Public Member Functions

 ActionListDiff ()
iterator begin ()
iterator end ()
RStrokeInfo get_info (Unique *id, bool *deleted=0, bool *stroke=0, bool *name=0, bool *action=0) const
int order_size () const
int size_rec () const
bool resettable (Unique *id) const
Uniqueadd (StrokeInfo &si, Unique *before=0)
void set_action (Unique *id, RAction action)
void set_strokes (Unique *id, StrokeSet strokes)
void set_name (Unique *id, std::string name)
bool contains (Unique *id) const
bool remove (Unique *id)
void reset (Unique *id)
void add_apps (std::map< std::string, ActionListDiff * > &apps)
ActionListDiffadd_child (std::string name, bool app)
bool remove ()
bool move (Unique *src, Unique *dest)
boost::shared_ptr< std::map
< Unique *, StrokeSet > > 
get_strokes () const
boost::shared_ptr< std::set
< Unique * > > 
get_ids (bool include_deleted) const
int count_actions () const
void all_strokes (std::list< RStroke > &strokes) const
RAction handle (RStroke s, RRanking &r) const
void handle_advanced (RStroke s, std::map< guint, RAction > &a, std::map< guint, RRanking > &r, int b1, int b2) const
 ~ActionListDiff ()

Public Attributes

int level
bool app
std::string name

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int version)
void update_order ()
void fix_tree (bool rebuild_order)

Private Attributes

ActionListDiffparent
std::set< Unique * > deleted
std::map< Unique *, StrokeInfoadded
std::list< Unique * > order
std::list< ActionListDiffchildren

Friends

class boost::serialization::access
class ActionDB

Detailed Description

Definition at line 228 of file actiondb.h.


Member Typedef Documentation

Definition at line 265 of file actiondb.h.


Constructor & Destructor Documentation

Definition at line 263 of file actiondb.h.

: parent(0), level(0), app(false) {}

Here is the caller graph for this function:

Definition at line 388 of file actiondb.cc.

                                {
       if (app)
              actions.apps.erase(name);
}

Member Function Documentation

Unique* ActionListDiff::add ( StrokeInfo si,
Unique before = 0 
) [inline]

Definition at line 281 of file actiondb.h.

                                                       {
              Unique *id = new Unique;
              added.insert(std::pair<Unique *, StrokeInfo>(id, si));
              id->level = level;
              id->i = order.size();
              if (before)
                     order.insert(std::find(order.begin(), order.end(), before), id);
              else
                     order.push_back(id);
              update_order();
              return id;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void ActionListDiff::add_apps ( std::map< std::string, ActionListDiff * > &  apps) [inline]

Definition at line 321 of file actiondb.h.

                                                                {
              if (app)
                     apps[name] = this;
              for (std::list<ActionListDiff>::iterator i = children.begin(); i != children.end(); i++)
                     i->add_apps(apps);
       }
ActionListDiff* ActionListDiff::add_child ( std::string  name,
bool  app 
) [inline]

Definition at line 327 of file actiondb.h.

                                                           {
              children.push_back(ActionListDiff());
              ActionListDiff *child = &(children.back());
              child->name = name;
              child->app = app;
              child->parent = this;
              child->level = level + 1;
              return child;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void ActionListDiff::all_strokes ( std::list< RStroke > &  strokes) const

Definition at line 300 of file actiondb.cc.

                                                                {
       for (std::map<Unique *, StrokeInfo>::const_iterator i = added.begin(); i != added.end(); i++)
              for (std::set<RStroke>::const_iterator j = i->second.strokes.begin(); j != i->second.strokes.end(); j++)
                     strokes.push_back(*j);
       for (std::list<ActionListDiff>::const_iterator i = children.begin(); i != children.end(); i++)
              i->all_strokes(strokes);
}

Here is the caller graph for this function:

Definition at line 266 of file actiondb.h.

{ return children.begin(); }

Here is the caller graph for this function:

bool ActionListDiff::contains ( Unique id) const [inline]

Definition at line 296 of file actiondb.h.

                                       {
              if (deleted.count(id))
                     return false;
              if (added.count(id))
                     return true;
              return parent && parent->contains(id);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

int ActionListDiff::count_actions ( ) const [inline]

Definition at line 369 of file actiondb.h.

                                 {
              return (parent ? parent->count_actions() : 0) + order.size() - deleted.size();
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 267 of file actiondb.h.

{ return children.end(); }

Here is the caller graph for this function:

void ActionListDiff::fix_tree ( bool  rebuild_order) [inline, private]

Definition at line 246 of file actiondb.h.

                                         {
              if (rebuild_order)
                     for (std::map<Unique *, StrokeInfo>::iterator i = added.begin(); i != added.end(); i++)
                            if (!(parent && parent->contains(i->first)))
                                   order.push_back(i->first);
              update_order();
              for (std::list<ActionListDiff>::iterator i = children.begin(); i != children.end(); i++) {
                     i->parent = this;
                     i->level = level + 1;
                     i->fix_tree(rebuild_order);
              }
       }

Here is the call graph for this function:

boost::shared_ptr< std::set< Unique * > > ActionListDiff::get_ids ( bool  include_deleted) const

Definition at line 289 of file actiondb.cc.

                                                                                     {
       boost::shared_ptr<std::set<Unique *> > ids = parent ? parent->get_ids(false) :
              boost::shared_ptr<std::set<Unique *> >(new std::set<Unique *>);
       if (!include_deleted)
              for (std::set<Unique *>::const_iterator i = deleted.begin(); i != deleted.end(); i++)
                     ids->erase(*i);
       for (std::map<Unique *, StrokeInfo>::const_iterator i = added.begin(); i != added.end(); i++)
              ids->insert(i->first);
       return ids;
}

Here is the caller graph for this function:

RStrokeInfo ActionListDiff::get_info ( Unique id,
bool *  deleted = 0,
bool *  stroke = 0,
bool *  name = 0,
bool *  action = 0 
) const

Definition at line 242 of file actiondb.cc.

                                                                                                            {
       if (deleted)
              *deleted = this->deleted.count(id);
       if (stroke)
              *stroke = false;
       if (name)
              *name = false;
       if (action)
              *action = false;
       RStrokeInfo si = parent ? parent->get_info(id) : RStrokeInfo(new StrokeInfo);
       std::map<Unique *, StrokeInfo>::const_iterator i = added.find(id);
       for (i = added.begin(); i != added.end(); i++) {
              if (i->first == id)
                     break;
       }
       if (i == added.end()) {
              return si;
       }
       if (i->second.name != "") {
              si->name = i->second.name;
              if (name)
                     *name = parent;
       }
       if (i->second.strokes.size()) {
              si->strokes = i->second.strokes;
              if (stroke)
                     *stroke = parent;
       }
       if (i->second.action) {
              si->action = i->second.action;
              if (action)
                     *action = parent;
       }
       return si;
}

Here is the caller graph for this function:

boost::shared_ptr< std::map< Unique *, StrokeSet > > ActionListDiff::get_strokes ( ) const

Definition at line 278 of file actiondb.cc.

                                                                                {
       boost::shared_ptr<std::map<Unique *, StrokeSet> > strokes = parent ? parent->get_strokes() :
              boost::shared_ptr<std::map<Unique *, StrokeSet> >(new std::map<Unique *, StrokeSet>);
       for (std::set<Unique *>::const_iterator i = deleted.begin(); i != deleted.end(); i++)
              strokes->erase(*i);
       for (std::map<Unique *, StrokeInfo>::const_iterator i = added.begin(); i != added.end(); i++)
              if (i->second.strokes.size())
                     (*strokes)[i->first] = i->second.strokes;
       return strokes;
}

Definition at line 308 of file actiondb.cc.

                                                           {
       if (!s)
              return RAction();
       r.reset(new Ranking);
       r->stroke = s;
       r->score = 0.0;
       boost::shared_ptr<std::map<Unique *, StrokeSet> > strokes = get_strokes();
       for (std::map<Unique *, StrokeSet>::const_iterator i = strokes->begin(); i!=strokes->end(); i++) {
              for (StrokeSet::iterator j = i->second.begin(); j!=i->second.end(); j++) {
                     double score;
                     int match = Stroke::compare(s, *j, score);
                     if (match < 0)
                            continue;
                     RStrokeInfo si = get_info(i->first);
                     r->r.insert(pair<double, pair<std::string, RStroke> >
                                   (score, pair<std::string, RStroke>(si->name, *j)));
                     if (score > r->score) {
                            r->score = score;
                            if (match) {
                                   r->name = si->name;
                                   r->action = si->action;
                                   r->best_stroke = *j;
                            }
                     }
              }
       }
       if (!r->action && s->trivial())
              return RAction(new Click);
       if (r->action) {
              if (verbosity >= 1)
                     printf("Executing Action %s\n", r->name.c_str());
       } else {
              if (verbosity >= 1)
                     printf("Couldn't find matching stroke.\n");
       }
       return r->action;
}

Here is the call graph for this function:

void ActionListDiff::handle_advanced ( RStroke  s,
std::map< guint, RAction > &  a,
std::map< guint, RRanking > &  r,
int  b1,
int  b2 
) const

Definition at line 346 of file actiondb.cc.

                                                                 {
       if (!s)
              return;
       boost::shared_ptr<std::map<Unique *, StrokeSet> > strokes = get_strokes();
       for (std::map<Unique *, StrokeSet>::const_iterator i = strokes->begin(); i!=strokes->end(); i++) {
              for (StrokeSet::iterator j = i->second.begin(); j!=i->second.end(); j++) {
                     int b = (*j)->button;
                     if (!s->timeout && !b)
                            continue;
                     s->button = b;
                     double score;
                     int match = Stroke::compare(s, *j, score);
                     if (match < 0)
                            continue;
                     Ranking *r;
                     if (b == b1)
                            b = b2;
                     if (rs.count(b)) {
                            r = rs[b].get();
                     } else {
                            r = new Ranking;
                            rs[b].reset(r);
                            r->stroke = RStroke(new Stroke(*s));
                            r->score = -1;
                     }
                     RStrokeInfo si = get_info(i->first);
                     r->r.insert(pair<double, pair<std::string, RStroke> >
                                   (score, pair<std::string, RStroke>(si->name, *j)));
                     if (score > r->score) {
                            r->score = score;
                            if (match) {
                                   r->name = si->name;
                                   r->action = si->action;
                                   r->best_stroke = *j;
                                   as[b] = si->action;
                            }
                     }
              }
       }
}

Here is the call graph for this function:

bool ActionListDiff::move ( Unique src,
Unique dest 
) [inline]

Definition at line 348 of file actiondb.h.

                                            {
              if (!src)
                     return false;
              if (src == dest)
                     return false;
              if (parent && parent->contains(src))
                     return false;
              if (dest && parent && parent->contains(dest))
                     return false;
              if (!added.count(src))
                     return false;
              if (dest && !added.count(dest))
                     return false;
              order.remove(src);
              order.insert(dest ? std::find(order.begin(), order.end(), dest) : order.end(), src);
              update_order();
              return true;
       }

Here is the call graph for this function:

int ActionListDiff::order_size ( ) const [inline]

Definition at line 270 of file actiondb.h.

{ return order.size(); }

Here is the caller graph for this function:

bool ActionListDiff::remove ( Unique id) [inline]

Definition at line 303 of file actiondb.h.

                               {
              bool really = !(parent && parent->contains(id));
              if (really) {
                     added.erase(id);
                     order.remove(id);
                     update_order();
              } else
                     deleted.insert(id);
              for (std::list<ActionListDiff>::iterator i = children.begin(); i != children.end(); i++)
                     i->remove(id);
              return really;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

bool ActionListDiff::remove ( ) [inline]

Definition at line 336 of file actiondb.h.

                     {
              if (!parent)
                     return false;
              for (std::list<ActionListDiff>::iterator i = parent->children.begin(); i != parent->children.end(); i++) {
                     if (&*i == this) {
                            parent->children.erase(i);
                            return true;
                     }

              }
              return false;
       }
void ActionListDiff::reset ( Unique id) [inline]

Definition at line 315 of file actiondb.h.

                              {
              if (!parent)
                     return;
              added.erase(id);
              deleted.erase(id);
       }

Here is the caller graph for this function:

bool ActionListDiff::resettable ( Unique id) const [inline]

Definition at line 277 of file actiondb.h.

                                         {
              return parent && (added.count(id) || deleted.count(id)) && parent->contains(id);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class Archive >
void ActionListDiff::serialize ( Archive &  ar,
const unsigned int  version 
) [private]

Definition at line 147 of file actiondb.cc.

                                                                                               {
       ar & deleted;
       ar & added;
       ar & name;
       ar & children;
       ar & app;
       if (version == 0)
              return;
       ar & order;
}
void ActionListDiff::set_action ( Unique id,
RAction  action 
) [inline]

Definition at line 293 of file actiondb.h.

{ added[id].action = action; }

Here is the caller graph for this function:

void ActionListDiff::set_name ( Unique id,
std::string  name 
) [inline]

Definition at line 295 of file actiondb.h.

{ added[id].name = name; }

Here is the caller graph for this function:

void ActionListDiff::set_strokes ( Unique id,
StrokeSet  strokes 
) [inline]

Definition at line 294 of file actiondb.h.

{ added[id].strokes = strokes; }

Here is the caller graph for this function:

int ActionListDiff::size_rec ( ) const [inline]

Definition at line 271 of file actiondb.h.

                            {
              int size = added.size();
              for (std::list<ActionListDiff>::const_iterator i = children.begin(); i != children.end(); i++)
                     size += i->size_rec();
              return size;
       }

Here is the caller graph for this function:

void ActionListDiff::update_order ( ) [inline, private]

Definition at line 238 of file actiondb.h.

                           {
              int j = 0;
              for (std::list<Unique *>::iterator i = order.begin(); i != order.end(); i++, j++) {
                     (*i)->level = level;
                     (*i)->i = j;
              }
       }

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class ActionDB [friend]

Definition at line 230 of file actiondb.h.

friend class boost::serialization::access [friend]

Definition at line 229 of file actiondb.h.


Member Data Documentation

std::map<Unique *, StrokeInfo> ActionListDiff::added [private]

Definition at line 234 of file actiondb.h.

Definition at line 260 of file actiondb.h.

Definition at line 236 of file actiondb.h.

std::set<Unique *> ActionListDiff::deleted [private]

Definition at line 233 of file actiondb.h.

Definition at line 259 of file actiondb.h.

std::string ActionListDiff::name

Definition at line 261 of file actiondb.h.

std::list<Unique *> ActionListDiff::order [private]

Definition at line 235 of file actiondb.h.

Definition at line 232 of file actiondb.h.


The documentation for this class was generated from the following files: