commandQueue.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00040 
00041 #include <pcl/apps/point_cloud_editor/commandQueue.h>
00042 #include <pcl/apps/point_cloud_editor/command.h>
00043 
00044 CommandQueue::CommandQueue () : depth_limit_(DEFAULT_MAX_SIZE_)
00045 {
00046 }
00047 
00048 CommandQueue::CommandQueue (unsigned int max_size) : depth_limit_(max_size)
00049 {
00050 }
00051 
00052 void
00053 CommandQueue::enforceDequeLimit ()
00054 {
00055   // the following loop should actually execute only one iteration.
00056   while (command_deque_.size() > depth_limit_)
00057     command_deque_.pop_front();
00058 }
00059 
00060 void
00061 CommandQueue::execute (CommandPtr command_ptr)
00062 {
00063   if (!command_ptr)
00064     return;
00065   command_ptr->execute();
00066   if (command_ptr->hasUndo())
00067   {
00068     command_deque_.push_back(command_ptr);
00069     enforceDequeLimit();
00070   }
00071 }
00072 
00073 void
00074 CommandQueue::undo ()
00075 {
00076   // no-op when no command is in the queue.
00077   if (command_deque_.empty())
00078     return;
00079   (command_deque_.back())->undo();
00080   command_deque_.pop_back();
00081 }
00082 
00083 unsigned int
00084 CommandQueue::setMaxSize (unsigned int size)
00085 {
00086   depth_limit_ = size;
00087   if (depth_limit_ > command_deque_.max_size())
00088     depth_limit_ = command_deque_.max_size();
00089   // resize should be faster than enforceDequeLimit
00090   if (command_deque_.size() > depth_limit_)
00091     command_deque_.resize(depth_limit_);
00092   return (depth_limit_);
00093 }
00094 
00095 
00096 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:22:49