IMP  2.1.0
The Integrative Modeling Platform
IMP::example::ExampleDecorator Class Reference

A simple decorator which adds a name to a particle. More...

#include <IMP/example/ExampleDecorator.h>

+ Inheritance diagram for IMP::example::ExampleDecorator:

Public Member Functions

 ExampleDecorator (::IMP::kernel::Model *m,::IMP::kernel::ParticleIndex id)
 
 ExampleDecorator (const IMP::kernel::ParticleAdaptor &d)
 
std::string get_decorator_name () const
 Get the name added to the particle.
 
void set_decorator_name (std::string nm)
 Set the name added to the particle.
 
void show (std::ostream &out=std::cout) const
 
- Public Member Functions inherited from IMP::kernel::Decorator
ParticleIndex get_particle_index () const
 
Particleget_particle () const
 
Modelget_model () const
 Returns the Model containing the particle.
 
 Decorator (Particle *p)
 
 Decorator ()
 

Static Public Member Functions

static ExampleDecorator decorate_particle (::IMP::kernel::Particle *p)
 
static bool get_is_setup (kernel::Model *m, kernel::ParticleIndex pi)
 return true if the particle has a name
 
static bool get_is_setup (const IMP::kernel::ParticleAdaptor &p)
 
static bool particle_is_instance (IMP::kernel::Model *m, IMP::kernel::ParticleIndex pi)
 
static bool particle_is_instance (::IMP::kernel::Particle *p)
 
static ExampleDecorator setup_particle (kernel::Model *m, ParticleIndex pi, std::string name)
 
static ExampleDecorator setup_particle (IMP::kernel::ParticleAdaptor decorator, std::string name)
 
- Static Public Member Functions inherited from IMP::kernel::Decorator
static bool get_is_setup (Particle *p)
 Return true if the particle can be cast to the decorator. More...
 

Additional Inherited Members

- Protected Member Functions inherited from IMP::kernel::Decorator
 Decorator (kernel::Model *m, ParticleIndex pi)
 
 Decorator (ParticleAdaptor p)
 

Detailed Description

A decorator adds functionality to a particle and ensures that invariants are preserved. In this case, the functionality is the setting and access of a name for the kernel::Particle and the invariant is that the name is always non-empty.

The source code is as follows:

/**
* \file IMP/example/ExampleDecorator.h \brief Add a name to a particle.
*
* Copyright 2007-2013 IMP Inventors. All rights reserved.
*
*/
#ifndef IMPEXAMPLE_EXAMPLE_DECORATOR_H
#define IMPEXAMPLE_EXAMPLE_DECORATOR_H
#include <IMP/example/example_config.h>
#include <IMP/Decorator.h>
IMPEXAMPLE_BEGIN_NAMESPACE
//! A simple decorator which adds a name to a particle.
/** A decorator adds functionality to a particle and ensures that invariants
are preserved. In this case, the functionality is the setting and access
of a name for the kernel::Particle and the invariant is that the name is always
non-empty.
The source code is as follows:
\include ExampleDecorator.h
\include ExampleDecorator.cpp
*/
class IMPEXAMPLEEXPORT ExampleDecorator : public Decorator {
/* Use a static variable in a static method to create the key
so that it is only done once and is only done when it is first
needed. Lazy initialization of keys makes \imp more efficient as
kernel::Particles do not have to allocate memory for ununsed keys.
*/
static StringKey get_name_key();
//! Add a name to the particle
/** The create function should take arguments which allow
the initial state of the Decorator to be reasonable (i.e.
make sure there is a non-empty name).
*/
static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi, std::string name) {
// use the usage check macro to make sure that arguments are correct
IMP_USAGE_CHECK(!name.empty(), "The name cannot be empty.");
m->add_attribute(get_name_key(), pi, name);
}
public:
//! return true if the particle has a name
return m->get_has_attribute(get_name_key(), pi);
}
//! Get the name added to the particle
std::string get_decorator_name() const {
return get_particle()->get_value(get_name_key());
}
//! Set the name added to the particle
void set_decorator_name(std::string nm) {
// use the usage check macro to check that functions are called properly
IMP_USAGE_CHECK(!nm.empty(), "The name cannot be empty");
get_particle()->set_value(get_name_key(), nm);
}
/* Declare the basic constructors and the cast function.*/
IMP_DECORATOR_METHODS(ExampleDecorator, Decorator);
IMP_DECORATOR_SETUP_1(ExampleDecorator, std::string, name);
};
/** Define a collection of them. Also look at example.i*/
IMP_DECORATORS(ExampleDecorator, ExampleDecorators, kernel::Particles);
IMPEXAMPLE_END_NAMESPACE
#endif /* IMPEXAMPLE_EXAMPLE_DECORATOR_H */
/**
* \file example/ExampleDecorator.cpp
* \brief Add a name to a particle.
*
* Copyright 2007-2013 IMP Inventors. All rights reserved.
*
*/
IMPEXAMPLE_BEGIN_NAMESPACE
StringKey ExampleDecorator::get_name_key() {
/* the compiler will make sure this is initialized the first time the
method is called. */
static StringKey mykey("my name");
return mykey;
}
void ExampleDecorator::show(std::ostream &out) const {
}
IMPEXAMPLE_END_NAMESPACE

Definition at line 31 of file ExampleDecorator.h.

Member Function Documentation

static ExampleDecorator IMP::example::ExampleDecorator::decorate_particle ( ::IMP::kernel::Particle p)
static
Deprecated:
As of IMP release 2.1. See the IMP Deprecation Policy for more information about deprecation in IMP. Check explicitly instead.

Definition at line 68 of file ExampleDecorator.h.

static bool IMP::example::ExampleDecorator::particle_is_instance ( ::IMP::kernel::Particle p)
static
Deprecated:
As of IMP release 2.1. See the IMP Deprecation Policy for more information about deprecation in IMP. Use get_is_setup() instead.

Definition at line 68 of file ExampleDecorator.h.

static bool IMP::example::ExampleDecorator::particle_is_instance ( IMP::kernel::Model m,
IMP::kernel::ParticleIndex  pi 
)
static
Deprecated:
As of IMP release 2.1. See the IMP Deprecation Policy for more information about deprecation in IMP. Use get_is_setup() instead.

Definition at line 68 of file ExampleDecorator.h.

static ExampleDecorator IMP::example::ExampleDecorator::setup_particle ( kernel::Model m,
ParticleIndex  pi,
std::string  name 
)
static

Setup the particle so it can be used with this decorator.

Definition at line 69 of file ExampleDecorator.h.


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