<commit_before>/*$Id$
 *
 * This source file is a part of the Berlin Project.
 * Copyright (C) 1999, 2000 <NAME> <<EMAIL>> 
 * Copyright (C) 1999 <NAME> <<EMAIL>> 
 * http://www.berlin-consortium.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
 * MA 02139, USA.
 */
#ifndef _PickTraversalImpl_hh
#define _PickTraversalImpl_hh

#include <Warsaw/config.hh>
#include <Warsaw/Input.hh>
#include <Warsaw/Controller.hh>
#include <Warsaw/PickTraversal.hh>
#include <Warsaw/Transform.hh>
#include <Berlin/TraversalImpl.hh>
#include <Berlin/RegionImpl.hh>
#include <Berlin/Vertex.hh>
#include <Prague/Sys/Tracer.hh>

class PositionalFocus;

//. provide an implementation for the PickTraversal interface.
//. the traversal keeps a stack of controllers that are on the trail
//.
//. some methods are not implemented:
//. 'intersect_region' has to be implemented if the intersecting object
//. is known (for example a region for node selections, or a vertex for
//. positional events
//. the 'hit()' method needs to be implemented as it adds a specific
//. strategy for generating a memento. Derived classes may want to
//. cache the memento to avoid frequent object activation
class PickTraversalImpl : public virtual POA_Warsaw::PickTraversal,
                          public TraversalImpl
{
  typedef std::vector<Warsaw::Controller_var> cstack_t;
  typedef std::vector<size_t> pstack_t;
public:
  PickTraversalImpl(Warsaw::Graphic_ptr, Warsaw::Region_ptr, Warsaw::Transform_ptr, PositionalFocus *);
  PickTraversalImpl(const PickTraversalImpl &);
  ~PickTraversalImpl();
  PickTraversalImpl &operator = (const PickTraversalImpl &);
  virtual Warsaw::PickTraversal_ptr _this();
  virtual Warsaw::Region_ptr current_allocation();
  virtual Warsaw::Transform_ptr current_transformation();
  virtual Warsaw::Graphic_ptr current_graphic();
  virtual void traverse_child(Warsaw::Graphic_ptr, Warsaw::Tag, Warsaw::Region_ptr, Warsaw::Transform_ptr);
  virtual void visit(Warsaw::Graphic_ptr);
  virtual Warsaw::Traversal::order direction();
  virtual CORBA::Boolean ok();
  virtual CORBA::Boolean intersects_allocation();
//   virtual CORBA::Boolean intersects_region(Warsaw::Region_ptr) = 0;
  virtual void enter_controller(Warsaw::Controller_ptr);
  virtual void leave_controller();
  virtual void hit() = 0;
  virtual CORBA::Boolean picked() = 0;
  virtual Warsaw::Focus_ptr get_focus();
  virtual CORBA::Boolean forward();
  virtual CORBA::Boolean backward();

  void pop_controller();
  Warsaw::Controller_ptr top_controller();
  const std::vector<Warsaw::Controller_var> &controllers() const { return _controllers;}
  void reinit();
protected:
  size_t current() const { return _cursor;}
private:
  cstack_t                   _controllers;
  pstack_t                   _positions;
  PositionalFocus           *_focus;
  size_t                     _cursor;
  Warsaw::PickTraversal_var __this;
};

//. remove one controller level from the top, it might have got out of scope
inline void PickTraversalImpl::pop_controller()
{
  Prague::Trace trace("PickTraversal::pop_controller");
  if (_controllers.size())
    {
      while (size() > _positions.back()) pop();
      _cursor = size() - 1;
      _controllers.pop_back();
      _positions.pop_back();
    }
}

inline void PickTraversalImpl::reinit()
{
  Prague::Trace trace("PickTraversal::reinit");
  _controllers.clear();
  _positions.clear();
  while (size() > 1)
    {
      Lease_var<TransformImpl> trafo(get_transformation(size() - 1));
      pop();
    }
  _cursor = 0;
}

inline Warsaw::Controller_ptr PickTraversalImpl::top_controller()
{
  return _controllers.size() ? Warsaw::Controller::_duplicate(_controllers.back()) : Warsaw::Controller::_nil();
}

#endif <commit_msg>released allocation and graphic in PickTraversal::reinit, added comment explaining the whole thing.<commit_after>/*$Id$
 *
 * This source file is a part of the Berlin Project.
 * Copyright (C) 1999, 2000 <NAME> <<EMAIL>> 
 * Copyright (C) 1999 <NAME> <<EMAIL>> 
 * http://www.berlin-consortium.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
 * MA 02139, USA.
 */
#ifndef _PickTraversalImpl_hh
#define _PickTraversalImpl_hh

#include <Warsaw/config.hh>
#include <Warsaw/Input.hh>
#include <Warsaw/Controller.hh>
#include <Warsaw/PickTraversal.hh>
#include <Warsaw/Transform.hh>
#include <Berlin/TraversalImpl.hh>
#include <Berlin/RegionImpl.hh>
#include <Berlin/Vertex.hh>
#include <Prague/Sys/Tracer.hh>

class PositionalFocus;

//. provide an implementation for the PickTraversal interface.
//. the traversal keeps a stack of controllers that are on the trail
//.
//. some methods are not implemented:
//. 'intersect_region' has to be implemented if the intersecting object
//. is known (for example a region for node selections, or a vertex for
//. positional events
//. the 'hit()' method needs to be implemented as it adds a specific
//. strategy for generating a memento. Derived classes may want to
//. cache the memento to avoid frequent object activation
class PickTraversalImpl : public virtual POA_Warsaw::PickTraversal,
                          public TraversalImpl
{
  typedef std::vector<Warsaw::Controller_var> cstack_t;
  typedef std::vector<size_t> pstack_t;
public:
  PickTraversalImpl(Warsaw::Graphic_ptr, Warsaw::Region_ptr, Warsaw::Transform_ptr, PositionalFocus *);
  PickTraversalImpl(const PickTraversalImpl &);
  ~PickTraversalImpl();
  PickTraversalImpl &operator = (const PickTraversalImpl &);
  virtual Warsaw::PickTraversal_ptr _this();
  virtual Warsaw::Region_ptr current_allocation();
  virtual Warsaw::Transform_ptr current_transformation();
  virtual Warsaw::Graphic_ptr current_graphic();
  virtual void traverse_child(Warsaw::Graphic_ptr, Warsaw::Tag, Warsaw::Region_ptr, Warsaw::Transform_ptr);
  virtual void visit(Warsaw::Graphic_ptr);
  virtual Warsaw::Traversal::order direction();
  virtual CORBA::Boolean ok();
  virtual CORBA::Boolean intersects_allocation();
//   virtual CORBA::Boolean intersects_region(Warsaw::Region_ptr) = 0;
  virtual void enter_controller(Warsaw::Controller_ptr);
  virtual void leave_controller();
  virtual void hit() = 0;
  virtual CORBA::Boolean picked() = 0;
  virtual Warsaw::Focus_ptr get_focus();
  virtual CORBA::Boolean forward();
  virtual CORBA::Boolean backward();

  void pop_controller();
  Warsaw::Controller_ptr top_controller();
  const std::vector<Warsaw::Controller_var> &controllers() const { return _controllers;}
  void reinit();
protected:
  size_t current() const { return _cursor;}
private:
  cstack_t                   _controllers;
  pstack_t                   _positions;
  PositionalFocus           *_focus;
  size_t                     _cursor;
  Warsaw::PickTraversal_var __this;
};

//. remove one controller level from the top, it might have got out of scope
inline void PickTraversalImpl::pop_controller()
{
  Prague::Trace trace("PickTraversal::pop_controller");
  if (_controllers.size())
    {
      while (size() > _positions.back()) pop();
      _cursor = size() - 1;
      _controllers.pop_back();
      _positions.pop_back();
    }
}

inline void PickTraversalImpl::reinit()
{
  // DO NOT CALL DURING A TRAVERSAL!
  
  // At the end of the Traversal only the very first element is on the stack
  // i(and we won't touch that), or this is a memento of another Traversal.
  // In that case we own Graphic, Transformation and Allocation, so we
  // must explicitly release them before calling pop().
  Prague::Trace trace("PickTraversal::reinit");
  _controllers.clear();
  _positions.clear();
  while (size() > 1)
    {
      CORBA::release(get_allocation(size() - 1));
      CORBA::release(get_graphic(size() - 1));
      Provider<TransformImpl>::adopt(get_transformation(size() - 1));
      pop();
    }
  _cursor = 0;
}

inline Warsaw::Controller_ptr PickTraversalImpl::top_controller()
{
  return _controllers.size() ? Warsaw::Controller::_duplicate(_controllers.back()) : Warsaw::Controller::_nil();
}

#endif 
{'fraction_non_alphanumeric': 0.10684636118598383, 'fraction_numerical': 0.006253369272237197, 'mean_word_length': 4.380510440835267, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3820787', 'n_tokens_mistral': 2874, 'n_tokens_neox': 2674, 'n_words': 874}