[Debian-astro-commits] [gyoto] 128/221: Convert all Spectra to Object/Property

Thibaut Jean-Claude Paumard thibaut at moszumanska.debian.org
Fri May 22 20:52:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

thibaut pushed a commit to branch master
in repository gyoto.

commit 6abd4422798979f5474faa5524ceb4fbb800d9ee
Author: Thibaut Paumard <paumard at users.sourceforge.net>
Date:   Thu Dec 4 18:09:44 2014 +0100

    Convert all Spectra to Object/Property
---
 include/GyotoBlackBodySpectrum.h             |  9 ++-----
 include/GyotoPowerLawSpectrum.h              |  9 ++-----
 include/GyotoSpectrum.h                      | 35 ++--------------------------
 include/GyotoThermalBremsstrahlungSpectrum.h |  5 ++--
 lib/BlackBodySpectrum.C                      | 28 ++++++++--------------
 lib/PowerLawSpectrum.C                       | 30 ++++++++----------------
 lib/Spectrum.C                               | 25 ++++++++++----------
 lib/ThermalBremsstrahlungSpectrum.C          | 18 ++++++++------
 8 files changed, 51 insertions(+), 108 deletions(-)

diff --git a/include/GyotoBlackBodySpectrum.h b/include/GyotoBlackBodySpectrum.h
index 638bc40..1f36b8c 100644
--- a/include/GyotoBlackBodySpectrum.h
+++ b/include/GyotoBlackBodySpectrum.h
@@ -60,6 +60,8 @@ class Gyoto::Spectrum::BlackBody : public Gyoto::Spectrum::Generic {
   double Tm1_; ///< 1./T_;
 
  public:
+  GYOTO_OBJECT;
+
   BlackBody();
 
   /**
@@ -76,13 +78,6 @@ class Gyoto::Spectrum::BlackBody : public Gyoto::Spectrum::Generic {
   using Gyoto::Spectrum::Generic::operator();
   virtual double operator()(double nu) const;
 
-  virtual int setParameter(std::string name,
-			    std::string content,
-			    std::string unit);
-
-#ifdef GYOTO_USE_XERCES
-  virtual void fillElement(FactoryMessenger *fmp) const ;
-#endif
 };
 
 #endif
diff --git a/include/GyotoPowerLawSpectrum.h b/include/GyotoPowerLawSpectrum.h
index 52ac99a..93faf62 100644
--- a/include/GyotoPowerLawSpectrum.h
+++ b/include/GyotoPowerLawSpectrum.h
@@ -56,6 +56,8 @@ class Gyoto::Spectrum::PowerLaw : public Gyoto::Spectrum::Generic {
   double exponent_; ///< I_nu=constant_*nu^exponent_
 
  public:
+  GYOTO_OBJECT;
+
   PowerLaw();
 
   /**
@@ -73,13 +75,6 @@ class Gyoto::Spectrum::PowerLaw : public Gyoto::Spectrum::Generic {
   using Gyoto::Spectrum::Generic::operator();
   virtual double operator()(double nu) const;
 
-#ifdef GYOTO_USE_XERCES
-  virtual int setParameter(std::string name,
-			    std::string content,
-			    std::string unit);
-
-  virtual void fillElement(FactoryMessenger *fmp) const ;
-#endif
 };
 
 #endif
diff --git a/include/GyotoSpectrum.h b/include/GyotoSpectrum.h
index 42efefb..d72d9fb 100644
--- a/include/GyotoSpectrum.h
+++ b/include/GyotoSpectrum.h
@@ -132,6 +132,8 @@ class Gyoto::Spectrum::Generic
   std::string kind_; ///< e.g. constants, blackbody...
 
  public:
+  GYOTO_OBJECT;
+
   Generic(const std::string kind); ///< Set kind in constructor
   //  Spectrum::Generic(const Spectrum::Generic &); ///< Copy constructor. Default is fine.
   virtual Generic * clone() const; ///< Cloner
@@ -176,39 +178,6 @@ class Gyoto::Spectrum::Generic
   virtual double integrate(double nu1, double nu2,
 			   const Spectrum::Generic * opacity, double ds) ;
 
-
-#ifdef GYOTO_USE_XERCES
-  /**
-   * Spectrum implementations should impement fillElement to save their
-   * parameters to XML and call the generic implementation to save
-   * generic parts.
-   */
-
-  virtual void fillElement(FactoryMessenger *fmp) const ;
-                                             ///< called from Factory
-
-  /**
-   * The Subcontractor_t function for each Spectrum kind should look
-   * somewhat like this:
-   * \code
-   * SmartPointer<Spectrum::Generic>
-   * Gyoto::Spectrum::MyKind::Subcontractor(FactoryMessenger* fmp) {
-   *   SmartPointer<MyKind> sp = new MyKind();
-   *   sp -> setParameters(fmp);
-   *   return sp;
-   * }
-   * \endcode
-   *
-   * Each spectrum kind should implement setParameter(string name,
-   * string content) to interpret the individual XML
-   * elements. setParameters() can be overloaded in case the specific
-   * Spectrum class needs low level access to the FactoryMessenger (see
-   * Astrobj::UniformSphere::setParameters()).
-   */
-  virtual void setParameters(FactoryMessenger *fmp);
-  ///< Main loop in Subcontractor_t function
-
-#endif
 };
 
 
diff --git a/include/GyotoThermalBremsstrahlungSpectrum.h b/include/GyotoThermalBremsstrahlungSpectrum.h
index feb8bec..6a7081a 100644
--- a/include/GyotoThermalBremsstrahlungSpectrum.h
+++ b/include/GyotoThermalBremsstrahlungSpectrum.h
@@ -57,6 +57,8 @@ class Gyoto::Spectrum::ThermalBremsstrahlung : public Gyoto::Spectrum::Generic {
   double massdensityCGS_; ///< Mass density in CGS UNITS (careful)
 
  public:
+  GYOTO_OBJECT;
+
   ThermalBremsstrahlung();
 
   /**
@@ -103,9 +105,6 @@ class Gyoto::Spectrum::ThermalBremsstrahlung : public Gyoto::Spectrum::Generic {
    */
   double alphanuCGS(double nu) const;
 
-#ifdef GYOTO_USE_XERCES
-  virtual void fillElement(FactoryMessenger *fmp) const ;
-#endif
 };
 
 #endif
diff --git a/lib/BlackBodySpectrum.C b/lib/BlackBodySpectrum.C
index d0ec228..f13382b 100644
--- a/lib/BlackBodySpectrum.C
+++ b/lib/BlackBodySpectrum.C
@@ -27,6 +27,16 @@
 #endif
 using namespace Gyoto;
 
+/// Properties
+
+#include "GyotoProperty.h"
+GYOTO_PROPERTY_START(Spectrum::BlackBody)
+GYOTO_PROPERTY_DOUBLE(Spectrum::BlackBody, Temperature, temperature)
+GYOTO_PROPERTY_DOUBLE(Spectrum::BlackBody, Scaling, scaling)
+GYOTO_PROPERTY_END(Spectrum::BlackBody, Generic::properties)
+
+///
+
 Spectrum::BlackBody::BlackBody() :
   Spectrum::Generic("BlackBody"), T_(10000.),
   cst_(2.*GYOTO_PLANCK_OVER_C_SQUARE) {Tm1_=1./T_;}
@@ -45,21 +55,3 @@ double Spectrum::BlackBody::operator()(double nu) const {
     /(exp(GYOTO_PLANCK_OVER_BOLTZMANN*nu*Tm1_)-1.);
 }
 
-int Spectrum::BlackBody::setParameter(std::string name,
-				       std::string content,
-				       std::string unit) {
-  char * tc=const_cast<char*>(content.c_str());
-  if (name=="Temperature") temperature(atof(tc));
-  else if (name=="Scaling") scaling(atof(tc));
-  else return Spectrum::Generic::setParameter(name, content, unit);
-  return 0;
-}
-
-#ifdef GYOTO_USE_XERCES
-void Spectrum::BlackBody::fillElement(FactoryMessenger *fmp) const {
-  fmp->setParameter("Temperature", T_);
-  fmp->setParameter("Scaling", cst_);
-  Spectrum::Generic::fillElement(fmp);
-}
-
-#endif
diff --git a/lib/PowerLawSpectrum.C b/lib/PowerLawSpectrum.C
index 7d81d71..5a8f446 100644
--- a/lib/PowerLawSpectrum.C
+++ b/lib/PowerLawSpectrum.C
@@ -26,6 +26,16 @@
 #endif
 using namespace Gyoto;
 
+/// Properties
+
+#include "GyotoProperty.h"
+GYOTO_PROPERTY_START(Spectrum::PowerLaw)
+GYOTO_PROPERTY_DOUBLE(Spectrum::PowerLaw, Exponent, exponent)
+GYOTO_PROPERTY_DOUBLE(Spectrum::PowerLaw, Constant, constant)
+GYOTO_PROPERTY_END(Spectrum::PowerLaw, Generic::properties)
+
+///
+
 Spectrum::PowerLaw::PowerLaw() :
   Spectrum::Generic("PowerLaw"), constant_(1.), exponent_(0.) {}
 Spectrum::PowerLaw::PowerLaw(double p, double c) :
@@ -41,23 +51,3 @@ void Spectrum::PowerLaw::exponent(double c) { exponent_ = c; }
 double Spectrum::PowerLaw::operator()(double nu) const {
   return constant_ * pow(nu, exponent_);
 }
-
-#ifdef GYOTO_USE_XERCES
-void Spectrum::PowerLaw::fillElement(FactoryMessenger *fmp) const {
-  fmp->setParameter("Exponent", exponent_);
-  fmp->setParameter("Constant", constant_);
-  Spectrum::Generic::fillElement(fmp);
-}
-
-int Gyoto::Spectrum::PowerLaw::setParameter(std::string name,
-			      std::string content,
-			      std::string unit) {
-  char * tc=const_cast<char*>(content.c_str());
-  if (name=="Exponent") exponent(atof(tc));
-  else if (name=="Constant") constant(atof(tc));
-  else return Spectrum::Generic::setParameter(name, content, unit);
-  return 0;
-}
-
-#endif
-
diff --git a/lib/Spectrum.C b/lib/Spectrum.C
index b37f051..b0205e3 100644
--- a/lib/Spectrum.C
+++ b/lib/Spectrum.C
@@ -27,6 +27,18 @@
 using namespace Gyoto;
 using namespace std;
 
+/// Properties
+
+// There is no generic properties for spectra. Nevertheless, we define
+// this to derived classes can point to Spectrum::Generic::properties
+// rather than Object::properties
+
+#include "GyotoProperty.h"
+GYOTO_PROPERTY_START(Spectrum::Generic)
+GYOTO_PROPERTY_END(Spectrum::Generic, Object::properties)
+
+///
+
 Spectrum::Generic::Generic(const string kin) : kind_(kin) {}
 Spectrum::Generic * Spectrum::Generic::clone() const 
 {
@@ -120,19 +132,6 @@ double Spectrum::Generic::operator()(double nu, double opacity, double ds)
   return 0.;
 }
 
-#ifdef GYOTO_USE_XERCES
-// do nothing... for now
-void Spectrum::Generic::fillElement(FactoryMessenger *fmp ) const {
-  fmp->setSelfAttribute("kind", kind_);
-}
-void Spectrum::Generic::setParameters(FactoryMessenger *fmp) {
-  string name="", content="", unit="";
-  if (fmp)
-    while (fmp->getNextParameter(&name, &content, &unit))
-      setParameter(name, content, unit);
-}
-#endif
-
 Register::Entry* Gyoto::Spectrum::Register_ = NULL;
 
 void Gyoto::Spectrum::Register(std::string name,
diff --git a/lib/ThermalBremsstrahlungSpectrum.C b/lib/ThermalBremsstrahlungSpectrum.C
index 09e327d..c21cad7 100644
--- a/lib/ThermalBremsstrahlungSpectrum.C
+++ b/lib/ThermalBremsstrahlungSpectrum.C
@@ -27,6 +27,17 @@
 #endif
 using namespace Gyoto;
 
+/// Properties
+
+#include "GyotoProperty.h"
+GYOTO_PROPERTY_START(Spectrum::ThermalBremsstrahlung)
+GYOTO_PROPERTY_DOUBLE(Spectrum::ThermalBremsstrahlung, Temperature, temperature)
+GYOTO_PROPERTY_END(Spectrum::ThermalBremsstrahlung, Generic::properties)
+
+///
+
+
+
 Spectrum::ThermalBremsstrahlung::ThermalBremsstrahlung() :
   T_(10000.), massdensityCGS_(0.),
   spectrumBB_(NULL),Spectrum::Generic("ThermalBremsstrahlung") {
@@ -81,10 +92,3 @@ double Spectrum::ThermalBremsstrahlung::alphanuCGS(double nu) const{
   // Kirchhoff's law:
   return jnuCGS(nu)/BB;
 }
-
-#ifdef GYOTO_USE_XERCES
-void Spectrum::ThermalBremsstrahlung::fillElement(FactoryMessenger *fmp) const {
-  Spectrum::Generic::fillElement(fmp);
-}
-
-#endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-astro/packages/gyoto.git



More information about the Debian-astro-commits mailing list