Source

mana-core-navigation / Navigation / Navigable.h

#ifndef NAVIGATION_NAVIGABLE_H
#define NAVIGATION_NAVIGABLE_H
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//              Generalization of Navigable Object Features                  //
//                                                                           //
// File:     Control/Navigation/Navigable.h                                  //
// Authors:  P. Calafiura, P. Loch, S. Rajagopalan                           //
// Comments: Implements navigation query with honoring or forwarding the     //
//           client request for a given object type. The actual              //
//           implementation is in Navigable.icc                              //
//                                                                           //
// Created:  07-Oct-03  Calafiura/Loch/Rajagopalan                           //
// Update:   18-Dec-03  Loch                                                 //
//                      - implement ElementLink -> change of template        //
//                        parameters necessary!                              //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
 
/** @class Navigable
 * @brief  a template helper to implement INavigable. Holds
 *         the container of children
 *
 * @author ATLAS Collaboration
 * $Id: Navigable.h,v 1.1.1.1 2004-02-10 18:11:52 lochp Exp $
 **/

// package includes
#include "Navigation/INavigable.h"
#include "Navigation/INavigationToken.h"
#include "Navigation/NavigationToken.h"
#include "Navigation/DefaultWeight.h"
#include "Navigation/DefaultChildColl.h"

// services etc.
#ifndef DATAMODEL_TOOLS_GENERATEINDEXINGPOLICY_H
# include "DataModel/tools/GenerateIndexingPolicy.h"
#endif

// STL includes
#include <vector>
#include <map>
#include <utility>  // pair

// boost include (pointer arbitration)
#include <boost/any.hpp>

////////////////////////////////////////////////////////////////
// Base class for implementation of Navigation token handling //
////////////////////////////////////////////////////////////////

// do-nothing class for Navigation termination implementation
class NavTerminator{};

template <typename CHILDCONTAINER=NavTerminator, 
	  typename CHILDPAR=DefaultWeight,
          typename CHILDCOLL=typename 
	  DefaultChildColl<CHILDCONTAINER, CHILDPAR>::type >
class Navigable : virtual public INavigable 
{
  public:

  //////////////////////
  // Type definitions //
  //////////////////////

  typedef CHILDCOLL                           child_coll;
  typedef typename child_coll::iterator       child_iter;
  typedef typename child_coll::const_iterator const_child_iter;
  typedef typename CHILDCONTAINER::value_type child_type

  /////////////////////////////////
  // Constructors and Destructor //
  /////////////////////////////////

  Navigable();

  virtual ~Navigable();

  ////////////////////////////////////////////////////////////////////
  // NavigationToken handling (INavigable interface implementation) //
  ////////////////////////////////////////////////////////////////////

  // no relational parameters
  virtual void fillToken(INavigationToken& rTok) const;
  // forwarding of parameters included
  virtual void fillToken(INavigationToken& rTok, 
			 const boost::any& parentParm) const;

  //////////////////////////////////
  // Add data objects or elements //
  //////////////////////////////////

  // add data object to the Navigable: replaces existing one (FIXME)
  //  virtual void putDataObj(const CHILD* aChild, 
  //			  const CHILDPAR& aPar=CHILDPAR());
  // add element to the Navigable: use element pointer (linear search!)
  void putElement(const CHILDCONTAINER& objCont, 
		  const child_type* aChild,
		  const CHILDPAR& aPar=CHILDPAR());
  // add element to the Navigable: use element index (direct access!)
  void putElement(const CHILDCONTAINER& objCont, 
		  typename SG::GenerateIndexingPolicy<CHILDCONTAINER>::type::index_type index,
		  const CHILDPAR& aPar=CHILDPAR());

  ///////////////////////
  // Data manipulation //
  ///////////////////////

  // remove object from the Navigable
  bool remove(const child_type* aChild);

  // check if child is already there  
  bool contains(const child_type* aChild) const;

  // get the associated parameter if any
  const CHILDPAR& getParameter(const child_type* aChild) const;

  ///////////////////////////
  // Protected data access //
  ///////////////////////////

  protected:

  // get collection of children
  const child_coll& getChildren() const { return m_children; }
  child_coll& getChildren() { return m_children; }

  // get pointer to child given its collection iterator 
  virtual const child_type* 
  getChildPtr(const_child_iter iter) const;

  // get the parameter associated with the child, if any
  virtual CHILDPAR getChildPar(const_child_iter iter) const;

  /////////////////////////////
  // Internal query handling //
  /////////////////////////////

  private:

  // honoring the query: filling the token if we match the token type
  virtual void apply(NavigationToken<typename child_type>& 
		     rTok) const;    // w/o parameters
  virtual void apply(NavigationToken<typename child_type, 
		     CHILDPAR>& rTok, // w/  parameters
		     const CHILDPAR& aPar) const;

  ///forwarding the query to children
  virtual void toKids(INavigationToken& rTok) const;         // w/o parameters
  virtual void toKids(INavigationToken& rTok,                // w/ parameters
		      const boost::any& aPar) const;

  ///////////////////////////
  // Internal data storage //
  ///////////////////////////

  private:

  child_coll m_children;

};

//////////////////////////
// Termination handling //
//////////////////////////

// dummy type for dummy child collections
class ErrorType{};

template<>
class Navigable<NavTerminator> : public INavigable 
{
 public:

  // suppress compiler warnings
  typedef ErrorType child_coll;
  typedef ErrorType child_iter;

  Navigable() { }
  virtual ~Navigable() { }

  // implement INavigable::fillToken(...) as "do-nothing"
  virtual void fillToken( INavigationToken & ) const { }
  virtual void fillToken( INavigationToken &, const boost::any& ) const { }
};

//////////////////////////////
// Navigable implementation //
//////////////////////////////

#include "Navigation/Navigable.icc"

#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.