Gyoto
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Gyoto::Spectrometer::Complex Class Reference

Complex spectrometer object. More...

#include <GyotoComplexSpectrometer.h>

Inheritance diagram for Gyoto::Spectrometer::Complex:
Gyoto::Spectrometer::Generic Gyoto::Hook::Listener Gyoto::SmartPointee Gyoto::Object Gyoto::Hook::Teller

Public Types

typedef Gyoto::SmartPointer< Gyoto::SmartPointeeSubcontractor_t(Gyoto::FactoryMessenger *)
 A subcontractor builds an object upon order from the Factory. More...
 

Public Member Functions

 Complex ()
 Default constructor.
 
 Complex (const Complex &)
 Copy constructor.
 
virtual Complexclone () const
 Clone an instance. More...
 
virtual ~Complex ()
 Destructor. More...
 
void append (Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > element)
 Add element at the end of the array. More...
 
void remove (size_t i)
 Remove i-th element from the array.
 
size_t getCardinal () const
 Get the number of elements in the array.
 
virtual void tell (Gyoto::Hook::Teller *msg)
 This is how a Teller tells. More...
 
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > & operator[] (size_t i)
 Retrieve i-th element. More...
 
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > const & operator[] (size_t i) const
 Retrieve a const version of the i-th element.
 
virtual Property const * getProperties () const
 Get list of properties. More...
 
virtual kind_t kindid () const
 Get kindid_. More...
 
virtual void kindid (kind_t)
 Set Generic::kindid_. More...
 
virtual size_t nSamples () const
 Get Generic::nsamples_.
 
virtual size_t getNBoundaries () const
 Get Generic::nboundaries_.
 
virtual double const * getMidpoints () const
 Get Generic::midpoints_.
 
virtual void getMidpoints (double data[], std::string unit)
 Copy Generic::midpoints_, converting to unit. More...
 
virtual void getChannelBoundaries (double data[], std::string unit)
 Copy Generic::boundaries_, converting to unit. More...
 
virtual double const * getChannelBoundaries () const
 Get Generic::boundaries_.
 
virtual size_t const * getChannelIndices () const
 Get Generic::chanind_.
 
virtual double const * getWidths () const
 Get Generic::widths_.
 
virtual void getWidths (double data[], std::string unit)
 Copy Generic::widths_, converting to unit. More...
 
void incRefCount ()
 Increment the reference counter. Warning: Don't mess with the counter.
 
int decRefCount ()
 Decrement the reference counter and return current value. Warning: Don't mess with the counter.
 
int getRefCount ()
 Get the current number of references.
 
void set (Property const &p, Value val)
 Set Value of a Property.
 
void set (Property const &p, Value val, std::string const &unit)
 Set Value (expressed in unit) of a Property.
 
void set (std::string const &pname, Value val)
 Set Value of a Property.
 
void set (std::string const &pname, Value val, std::string const &unit)
 Set Value (expressed in unit) of a Property.
 
Value get (Property const &p) const
 Get Value of a Property.
 
Value get (std::string const &pname) const
 Get Value of a Property.
 
Value get (Property const &p, std::string const &unit) const
 Get Value of a Property, converted to unit.
 
Value get (std::string const &pname, std::string const &unit) const
 Get Value of a Property, converted to unit.
 
Property const * property (std::string const pname) const
 Find property by name. More...
 
virtual void fillProperty (Gyoto::FactoryMessenger *fmp, Property const &p) const
 Output a single Property to XML. More...
 
virtual void fillElement (Gyoto::FactoryMessenger *fmp) const
 Fill the XML element for this Object. More...
 
virtual void setParameters (Gyoto::FactoryMessenger *fmp)
 Main loop for parsing Properties from XML description. More...
 
virtual int setParameter (std::string name, std::string content, std::string unit)
 Set parameter by name. More...
 
virtual void setParameter (Gyoto::Property const &p, std::string const &name, std::string const &content, std::string const &unit)
 Set parameter by Property (and name) More...
 
virtual void hook (Listener *listener)
 Start listening. More...
 
virtual void unhook (Listener *listener)
 Stop listening. More...
 

Public Attributes

size_t nsamples_
 Number of spectral elements.
 
size_t nboundaries_
 Size of the boundaries_ array.
 
double * boundaries_
 Frequency (in Hz) at the boundaries of the spectral channels. More...
 
size_tchanind_
 Indices in boundaries_. More...
 
double * midpoints_
 Effective frequency (in Hz) of each spectral channel. More...
 
double * widths_
 Width of each channel. More...
 

Static Public Attributes

static kind_t const Kind
 "Complex" More...
 
static GYOTO_OBJECT Property const properties []
 

Protected Member Functions

virtual void tellListeners ()
 Call tell() on each hooked Listener. More...
 

Protected Attributes

size_t cardinal_
 Number of subspectrometers. More...
 
Gyoto::SmartPointer< Gyoto::Spectrometer::Generic > * elements_
 Actual array of SmartPointer<Spectrometer::Generic> objects.
 
kind_t kindid_
 Spectrometer kind ID. More...
 
std::string kind_
 The "kind" that is output in the XML entity. More...
 

Friends

class Gyoto::SmartPointer< Gyoto::Spectrometer::Complex >
 

Detailed Description

Complex spectrometer object.

A Gyoto::Spectrometer::Generic whic contain several Gyoto::Spectrometer::Generic instances. It is essentially a SmartPointer<Spectrometer::Generic> array, which some methods arround. Indeed, the operator[](size_t i) method is implemented to retrieve the i-th element.

In an XML description, the <Spectrometer> section is unique, its kind is "Complex". Each sub-spectrometer then appears as a <SubSpectrometer> subsection. For instance, to compute 10 channels ovr the K infrared band plus 10 channels in the high energy domain:

<Spectrometer kind = "Complex">
<SubSpectrometer kind = "wave" nsamples=10 unit="µm">
2.0 2.4
</SubSpectrometer>
<SubSpectrometer kind = "freqlog" nsamples=10 unit="eV">
14 22
</SubSpectrometer>
</Spectrometer>

Member Typedef Documentation

typedef Gyoto::SmartPointer<Gyoto::SmartPointee> Gyoto::SmartPointee::Subcontractor_t(Gyoto::FactoryMessenger *)
inherited

A subcontractor builds an object upon order from the Factory.

Various classes need to provide a subcontractor to be able to instanciate themselves upon order from the Factory. A subcontractor is a function (often a static member function) which accepts a pointer to a FactoryMessenger as unique parameter, communicates with the Factory using this messenger to read an XML description of the object to build, and returns this objet. SmartPointee::Subcontractor_t* is just generic enough a typedef to cast to and from other subcontractor types: Astrobj::Subcontractor_t, Metric::Subcontractor_t, Spectrum::Subcontractor_t. A subcontractor needs to be registered using the relevant Register() function: Astrobj::Register(), Metric::Register(), Spectrum::Register().

Constructor & Destructor Documentation

virtual Gyoto::Spectrometer::Complex::~Complex ( )
virtual

Destructor.

Frees every SmartPointer<Spectrometer::Generic> before freed the array itself.

Member Function Documentation

void Gyoto::Spectrometer::Complex::append ( Gyoto::SmartPointer< Gyoto::Spectrometer::Generic element)

Add element at the end of the array.

If the Spectrometer::Complex itself does not have a metric already assigned, it takes it from the new element. Else, it sets the metric in the new element to its own. This ensures that all elements use the same metric (this heuristic is not entirely fool-proof, it's safer to set the metric directly in the Spectrometer::Complex).

virtual Complex* Gyoto::Spectrometer::Complex::clone ( ) const
virtual

Clone an instance.

Use this to get a deep copy of an instance;

SmartPointer<Generic> myclone = orig->clone();

Most implementations will use the copy constructor:

Generic* Uniform::clone() const { return new Uniform(*this); }

Implements Gyoto::Spectrometer::Generic.

virtual void Gyoto::Object::fillElement ( Gyoto::FactoryMessenger *  fmp) const
virtualinherited

Fill the XML element for this Object.

The base implementation simply calls fillProperty() for each Property defined for the Object.

Derived classes should avoid overriding fillElement(). It may make sense occasionally, e.g. to make sure that the metric is output first.

To customize how a given Property is rendered, it is better to override fillProperty().

If this method is overridden, the implementation should in general call fillElement() on the direct base.

virtual void Gyoto::Object::fillProperty ( Gyoto::FactoryMessenger *  fmp,
Property const &  p 
) const
virtualinherited

Output a single Property to XML.

The base implementation decides what to do based on the p.type. The format matches how setParameters() an setParameter() would interpret the XML descition.

Overriding this method should be avoided, but makes sense in some cases (for instance Screen::fillProperty() selects a different unit for Distance based on its magnitude, so that stellar sizes are expressed in solar radii while smaller sizes can be expressed in meters and larger sizes in parsecs).

Overriding implementation should fall-back on calling the implementation in the direct parent class:

class A: public Object {};
class B: public A {
using B::setParameter;
virtual void fillProperty(Gyoto::FactoryMessenger *fmp,
Property const &p) const ;
};
void B::fillProperty(Gyoto::FactoryMessenger *fmp,
Property const &p) const {
if (name=="Duff") fmp->doSomething();
else A::fillProperty(fmp, p);
}

Reimplemented in Gyoto::Screen, Gyoto::Astrobj::Star, Gyoto::Spectrometer::Uniform, Gyoto::Astrobj::Disk3D, Gyoto::Astrobj::PatternDisk, Gyoto::Astrobj::PolishDoughnut, and Gyoto::Astrobj::DirectionalDisk.

virtual void Gyoto::Spectrometer::Generic::getChannelBoundaries ( double  data[],
std::string  unit 
)
virtualinherited

Copy Generic::boundaries_, converting to unit.

Parameters
dataan array of Generic::nboundaries_ doubles to fill with result
unita string
virtual void Gyoto::Spectrometer::Generic::getMidpoints ( double  data[],
std::string  unit 
)
virtualinherited

Copy Generic::midpoints_, converting to unit.

Parameters
dataan array of Generic::nsamples_ doubles to fill with result
unita string
virtual Property const* Gyoto::Spectrometer::Generic::getProperties ( ) const
virtualinherited

Get list of properties.

This method is declared automatically by the GYOTO_OBJECT macro and defined automatically by the GYOTO_PROPERTY_END macro.

Reimplemented from Gyoto::Object.

Reimplemented in Gyoto::Spectrometer::Uniform.

virtual void Gyoto::Spectrometer::Generic::getWidths ( double  data[],
std::string  unit 
)
virtualinherited

Copy Generic::widths_, converting to unit.

Think carefully before using: widths are often used to convert spectral flux density to flux. If flux density is per Herz, you don't need to convert widths.

Parameters
dataan array of Generic::nboundaries_ doubles to fill with result
unita string
virtual void Gyoto::Hook::Teller::hook ( Listener listener)
virtualinherited

Start listening.

Use from a Hook::Listener object method:

teller->hook(this)

where "this" is a Listener and "teller" is a Teller.

Use unhook() later to stop listening to a given Teller.

Parameters
listenerpointer to the new listener
virtual kind_t Gyoto::Spectrometer::Generic::kindid ( ) const
virtualinherited

Get kindid_.

You can check whether the Spectrometer sp is of a given kind MyKind with something like:

if (sp->kind()) == MyKind::Kindid;

See Uniform::WaveKind, Uniform::WaveLogKind, Uniform::FreqKind, Uniform::FreqLogKind and Complex::Kind.

virtual void Gyoto::Spectrometer::Generic::kindid ( kind_t  )
virtualinherited

Set Generic::kindid_.

This should rarely be used as the Generic::kindid_ attribute usually is set in the constructor and doesn't change after that.

Always set to the address of a static variable, not to a temporary. Usually your class should have a static member for that purpose:

class MyKind : public Spectrometer::Generic
{
static kind_t Kindid;
};
kind_t MyKind::Kind = "MyKind";
...
SmartPointer<MyKind> sp();
sp->kindid(MyKind::Kindid)

Reimplemented in Gyoto::Spectrometer::Uniform.

Gyoto::SmartPointer<Gyoto::Spectrometer::Generic>& Gyoto::Spectrometer::Complex::operator[] ( size_t  i)

Retrieve i-th element.

This should work as expected:

SmartPointer<Spectrometer::Complex> cplx;
SmartPointer<Spectrometer::TypeA> objA;
SmartPointer<Spectrometer::TypeB> objB;
cplx -> append(objA);
cplx[0] = objB;
Property const* Gyoto::Object::property ( std::string const  pname) const
inherited

Find property by name.

Look into the Property list for a Property whose name (or name_false, for a boolean Property) is pname. Return a const pointer to the first such property found, or NULL if none is found.

virtual int Gyoto::Object::setParameter ( std::string  name,
std::string  content,
std::string  unit 
)
virtualinherited

Set parameter by name.

This function is used when parsing an XML description, if no Property of this name is found. Overriding implementation should fall-back on calling the direct's parent implementation:

class A: public Object {};
class B: public A {
using B::setParameter;
virtual int setParameter(std::string name,
std::string content,
std::string unit);
};
int B::setParameter(std::string name,
std::string content,
std::string unit) {
if (name=="Duff") doSomething(content, unit);
else return A::setParameter(name, content, unit);
return 0; // name was known
}
Parameters
nameXML name of the parameter (XML entity)
contentstring representation of the value
unitstring representation of the unit
Returns
0 if this parameter is known, 1 if it is not.

Reimplemented in Gyoto::Astrobj::Star, and Gyoto::Metric::RotStar3_1.

virtual void Gyoto::Object::setParameter ( Gyoto::Property const &  p,
std::string const &  name,
std::string const &  content,
std::string const &  unit 
)
virtualinherited

Set parameter by Property (and name)

This function is used when parsing an XML description, if Property (p) of this name is found (i.e. either p.name or p.name_false is equal to name). Implementation should fall-back on calling the direct's parent implementation:

class A: public Object {};
class B: public A {
using B::setParameter;
virtual void setParameter(Gyoto::Property const &p,
std::string name,
std::string content,
std::string unit);
};
void B::setParameter(Gyoto::Property const &p,
std::string name,
std::string content,
std::string unit) {
if (name=="Duff") doSomething(content, unit);
else A::setParameter(p, name, content, unit);
}
Parameters
pProperty that matches name (p.name == name or p.name_false == name)
nameXML name of the parameter (XML entity)
contentstring representation of the value
unitstring representation of the unit

Reimplemented in Gyoto::Astrobj::PolishDoughnut.

virtual void Gyoto::Object::setParameters ( Gyoto::FactoryMessenger *  fmp)
virtualinherited

Main loop for parsing Properties from XML description.

This function queries the FactoryMessenger for elements to parse, and tries to matche each element to a Property to set it accordingly.

Any class that tries to be buildable from XML must supply a subcontractor (for base classes such as Metric, Astrobj, Spectrum and Spectrometer, it is done as a template that must be specialized for each class).

This subcontractor typically looks somewhat like this:

SmartPointer<Metric::Generic>
Gyoto::Metric::MyKind::Subcontractor(FactoryMessenger* fmp) {
SmartPointer<MyKind> gg = new MyKind();
gg -> setParameters(fmp);
return gg;
}
 Although this is discouraged, it is possible to override the
 following functions to customize how XML entities are parsed:
   - setParameters() if low-level access to the
     FactoryMessenger is required;
   - setParameter(std::string name,
                  std::string content,
                  std::string unit)
     to interpret an entity that does not match a Property
     (e.g. alternative name);
   - setParameter(Gyoto::Property const &p,
                  std::string const &name,
                  std::string const &content,
                  std::string const &unit)
     to change how a Property is interpreted.
virtual void Gyoto::Spectrometer::Complex::tell ( Gyoto::Hook::Teller msg)
virtual

This is how a Teller tells.

A teller will basically call listener->tell(this).

Parameters
msgTeller* the Teller who is telling... Useful if the Listener listens to several Tellers.

Reimplemented from Gyoto::Hook::Listener.

virtual void Gyoto::Hook::Teller::tellListeners ( )
protectedvirtualinherited

Call tell() on each hooked Listener.

Whenever a Teller mutates, it should warn any Listener hooked to it using tellListeners().

virtual void Gyoto::Hook::Teller::unhook ( Listener listener)
virtualinherited

Stop listening.

Use from a Hook::Listener object method:

teller->unhook(this)

where "this" is a Listener, "teller" is a Teller, and "this" has called teller->hook(this) previously.

Parameters
listenerpointer to the listener

Member Data Documentation

double* Gyoto::Spectrometer::Generic::boundaries_
inherited

Frequency (in Hz) at the boundaries of the spectral channels.

Array of size nboundaries_

Spectral channel i extends from

to

. Channels may or may not be contiguous or ordered.

size_t Gyoto::Spectrometer::Complex::cardinal_
protected

Number of subspectrometers.

Size of elements_.

size_t* Gyoto::Spectrometer::Generic::chanind_
inherited

Indices in boundaries_.

Array of size 2*nsamples_

kind_t const Gyoto::Spectrometer::Complex::Kind
static

"Complex"

Use this static member attribute to check whether a Spectrometer object spectro is of kind Complex:

if (spectro->kind() == Complex::Kind) ... ;
std::string Gyoto::Object::kind_
protectedinherited

The "kind" that is output in the XML entity.

E.g. for an Astrobj, fillElement() will ensure

<Astrobj kind="kind_">...</Astrobj>

is written.

kind_t Gyoto::Spectrometer::Generic::kindid_
protectedinherited

Spectrometer kind ID.

The content is not copied. kindid_ should be set (as a parameter to the Generic() constructor or using kindid()) to the address of a static variable holding the name. This allows checking the kind using pointer comparison rather than string comparison.

double* Gyoto::Spectrometer::Generic::midpoints_
inherited

Effective frequency (in Hz) of each spectral channel.

Array of size nsamples_

double* Gyoto::Spectrometer::Generic::widths_
inherited

Width of each channel.

Array of size nsamples_ (in Hz)


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