Commit 6ab0ca9e06004c2bf7d6201c1ccf7a68ab7ec64a

Authored by Jürgen Knödlseder
1 parent 1f6d6c53

Review of GammaLib core code.

These are the final modifications for the GammaLib core code review.
include/GCaldb.hpp
... ... @@ -82,14 +82,15 @@ public:
82 82 GCaldb& operator= (const GCaldb& caldb);
83 83  
84 84 // Methods
85   - void clear(void);
86   - GCaldb* clone(void) const;
87   - int size(void) const;
88   - std::string dir(void) const { return m_caldb; }
89   - void dir(const std::string& pathname);
90   - void open(const std::string& mission, const std::string& instrument = "");
91   - void close(void);
92   - std::string print(const GChatter& chatter = NORMAL) const;
  85 + void clear(void);
  86 + GCaldb* clone(void) const;
  87 + int size(void) const;
  88 + const std::string& dir(void) const;
  89 + void dir(const std::string& pathname);
  90 + void open(const std::string& mission,
  91 + const std::string& instrument = "");
  92 + void close(void);
  93 + std::string print(const GChatter& chatter = NORMAL) const;
93 94  
94 95 protected:
95 96 // Protected methods
... ... @@ -110,4 +111,16 @@ protected:
110 111 GFitsTable* m_cif; //!< Pointer to CIF table
111 112 };
112 113  
  114 +
  115 +/***********************************************************************//**
  116 + * @brief Return calibration directory
  117 + *
  118 + * @return Calibration directory.
  119 + ***************************************************************************/
  120 +inline
  121 +const std::string& GCaldb::dir(void) const
  122 +{
  123 + return m_caldb;
  124 +}
  125 +
113 126 #endif /* GCALDB_HPP */
... ...
include/GEnergies.hpp
... ... @@ -73,7 +73,7 @@ public:
73 73 void extend(const GEnergies& energies);
74 74 void load(const std::string& filename,
75 75 const std::string& extname = "ENERGIES");
76   - void save(const std::string& filename, bool clobber,
  76 + void save(const std::string& filename, const bool& clobber,
77 77 const std::string& extname = "ENERGIES") const;
78 78 void read(const GFitsTable& table);
79 79 void write(GFits& file,
... ...
include/GMatrixSparse.hpp
... ... @@ -256,9 +256,9 @@ public:
256 256 GMatrixSparse invert(void) const;
257 257 GVector solve(const GVector& vector) const;
258 258 GMatrixSparse abs(void) const;
259   - GMatrixSparse cholesky_decompose(bool compress = true) const;
260   - GVector cholesky_solver(const GVector& vector, bool compress = true) const;
261   - GMatrixSparse cholesky_invert(bool compress = true) const;
  259 + GMatrixSparse cholesky_decompose(const bool& compress = true) const;
  260 + GVector cholesky_solver(const GVector& vector, const bool& compress = true) const;
  261 + GMatrixSparse cholesky_invert(const bool& compress = true) const;
262 262 void set_mem_block(const int& block);
263 263 void stack_init(const int& size = 0, const int& entries = 0);
264 264 int stack_push_column(const GVector& vector, const int& col);
... ...
include/GMatrixSymmetric.hpp
... ... @@ -120,9 +120,9 @@ public:
120 120 GMatrixSymmetric abs(void) const;
121 121 GMatrix extract_lower_triangle(void) const;
122 122 GMatrix extract_upper_triangle(void) const;
123   - GMatrixSymmetric cholesky_decompose(bool compress = true) const;
124   - GVector cholesky_solver(const GVector& vector, bool compress = true) const;
125   - GMatrixSymmetric cholesky_invert(bool compress = true) const;
  123 + GMatrixSymmetric cholesky_decompose(const bool& compress = true) const;
  124 + GVector cholesky_solver(const GVector& vector, const bool& compress = true) const;
  125 + GMatrixSymmetric cholesky_invert(const bool& compress = true) const;
126 126  
127 127 private:
128 128 // Private methods
... ...
include/GRoi.hpp
1 1 /***************************************************************************
2   - * GRoi.hpp - Region of interest interface class *
  2 + * GRoi.hpp - Abstract Region of interest base class *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2010-2013 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file GRoi.hpp
23   - * @brief Region of interest interface class definition
  23 + * @brief Abstract Region of interest base class definition
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
... ...
include/GSkyRegion.hpp
... ... @@ -76,9 +76,9 @@ public:
76 76 virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
77 77  
78 78 // Implemented methods
79   - std::string type(void) const;
80   - std::string name(void) const;
81   - double solidangle(void) const;
  79 + const std::string& type(void) const;
  80 + const std::string& name(void) const;
  81 + const double& solidangle(void) const;
82 82  
83 83 protected:
84 84 // Protected methods
... ... @@ -101,7 +101,7 @@ protected:
101 101 * Returns the region name.
102 102 ***************************************************************************/
103 103 inline
104   -std::string GSkyRegion::name(void) const
  104 +const std::string& GSkyRegion::name(void) const
105 105 {
106 106 return (m_name);
107 107 }
... ... @@ -115,7 +115,7 @@ std::string GSkyRegion::name(void) const
115 115 * Returns the region type.
116 116 ***************************************************************************/
117 117 inline
118   -std::string GSkyRegion::type(void) const
  118 +const std::string& GSkyRegion::type(void) const
119 119 {
120 120 return (m_type);
121 121 }
... ... @@ -129,7 +129,7 @@ std::string GSkyRegion::type(void) const
129 129 * Returns the solid angle subtended by the region (in steradian).
130 130 ***************************************************************************/
131 131 inline
132   -double GSkyRegion::solidangle(void) const
  132 +const double& GSkyRegion::solidangle(void) const
133 133 {
134 134 return (m_solid);
135 135 }
... ...
include/GSkyRegionCircle.hpp
... ... @@ -72,9 +72,9 @@ public:
72 72 // Implemented methods
73 73 void clear(void);
74 74 GSkyRegionCircle* clone(void) const;
75   - double radius(void) const;
  75 + const double& radius(void) const;
76 76 void radius(const double& radius);
77   - GSkyDir centre(void) const;
  77 + const GSkyDir& centre(void) const;
78 78 void centre(const GSkyDir& centre);
79 79 void centre(const double& ra,const double& dec);
80 80 double ra(void) const;
... ... @@ -107,7 +107,7 @@ protected:
107 107 * Returns the region radius in degrees.
108 108 ***************************************************************************/
109 109 inline
110   -double GSkyRegionCircle::radius(void) const
  110 +const double& GSkyRegionCircle::radius(void) const
111 111 {
112 112 return (m_radius);
113 113 }
... ... @@ -121,7 +121,7 @@ double GSkyRegionCircle::radius(void) const
121 121 * Returns the region centre.
122 122 ***************************************************************************/
123 123 inline
124   -GSkyDir GSkyRegionCircle::centre(void) const
  124 +const GSkyDir& GSkyRegionCircle::centre(void) const
125 125 {
126 126 return (m_centre);
127 127 }
... ...
include/GSource.hpp
... ... @@ -63,7 +63,7 @@ public:
63 63 virtual ~GSource(void);
64 64  
65 65 // Operators
66   - GSource& operator= (const GSource& src);
  66 + GSource& operator=(const GSource& src);
67 67  
68 68 // Methods
69 69 void clear(void);
... ...
include/GUrl.hpp
... ... @@ -59,7 +59,7 @@ public:
59 59 virtual void close(void) = 0;
60 60 virtual int read(void* buffer, const int& nbyte) = 0;
61 61 virtual int write(const void* buffer, const int& nbyte) = 0;
62   - virtual int getchar(void) = 0;
  62 + virtual int getchar(void) const = 0;
63 63 virtual void putchar(const int& character) = 0;
64 64 virtual void scanf(const char* format, ...) = 0;
65 65 virtual void printf(const char* format, ...) = 0;
... ...
include/GUrlFile.hpp
... ... @@ -57,7 +57,7 @@ public:
57 57 virtual void close(void);
58 58 virtual int read(void* buffer, const int& nbyte);
59 59 virtual int write(const void* buffer, const int& nbyte);
60   - virtual int getchar(void);
  60 + virtual int getchar(void) const;
61 61 virtual void putchar(const int& character);
62 62 virtual void scanf(const char* format, ...);
63 63 virtual void printf(const char* format, ...);
... ...
include/GUrlString.hpp
... ... @@ -58,7 +58,7 @@ public:
58 58 virtual void close(void);
59 59 virtual int read(void* buffer, const int& nbyte);
60 60 virtual int write(const void* buffer, const int& nbyte);
61   - virtual int getchar(void);
  61 + virtual int getchar(void) const;
62 62 virtual void putchar(const int& character);
63 63 virtual void scanf(const char* format, ...);
64 64 virtual void printf(const char* format, ...);
... ... @@ -75,7 +75,7 @@ protected:
75 75 void free_members(void);
76 76  
77 77 // Protected members
78   - int m_index; //!< String position indicator
  78 + mutable int m_index; //!< String position indicator
79 79 std::string m_buffer; //!< Text string
80 80 };
81 81  
... ...
include/GXml.hpp
... ... @@ -207,7 +207,7 @@ public:
207 207 const GXmlElement* element(const std::string& name, const int& index) const;
208 208 void load(const std::string& filename);
209 209 void save(const std::string& filename);
210   - void read(GUrl& url);
  210 + void read(const GUrl& url);
211 211 void write(GUrl& url, const int& indent = 0) const;
212 212 std::string print(const GChatter& chatter = NORMAL) const;
213 213 std::string print(const GChatter& chatter = NORMAL,
... ... @@ -229,7 +229,7 @@ protected:
229 229 void init_members(void);
230 230 void copy_members(const GXml& xml);
231 231 void free_members(void);
232   - void parse(GUrl& url);
  232 + void parse(const GUrl& url);
233 233 void process_markup(GXmlNode** current, const std::string& segment);
234 234 void process_text(GXmlNode** current, const std::string& segment);
235 235 MarkupType get_markuptype(const std::string& segment) const;
... ...
pyext/GCaldb.i
... ... @@ -26,7 +26,6 @@
26 26 %{
27 27 /* Put headers and other declarations here that are needed for compilation */
28 28 #include "GCaldb.hpp"
29   -#include "GTools.hpp"
30 29 %}
31 30  
32 31  
... ... @@ -44,13 +43,14 @@ public:
44 43 virtual ~GCaldb(void);
45 44  
46 45 // Methods
47   - void clear(void);
48   - GCaldb* clone(void) const;
49   - int size(void) const;
50   - std::string dir(void) const;
51   - void dir(const std::string& pathname);
52   - void open(const std::string& mission, const std::string& instrument = "");
53   - void close(void);
  46 + void clear(void);
  47 + GCaldb* clone(void) const;
  48 + int size(void) const;
  49 + const std::string& dir(void) const;
  50 + void dir(const std::string& pathname);
  51 + void open(const std::string& mission,
  52 + const std::string& instrument = "");
  53 + void close(void);
54 54 };
55 55  
56 56  
... ... @@ -58,9 +58,6 @@ public:
58 58 * @brief GCaldb class extension
59 59 ***************************************************************************/
60 60 %extend GCaldb {
61   - char *__str__() {
62   - return gammalib::tochar(self->print());
63   - }
64 61 GCaldb copy() {
65 62 return (*self);
66 63 }
... ...
pyext/GEnergies.i
... ... @@ -59,7 +59,7 @@ public:
59 59 void extend(const GEnergies& energies);
60 60 void load(const std::string& filename,
61 61 const std::string& extname = "ENERGIES");
62   - void save(const std::string& filename, bool clobber,
  62 + void save(const std::string& filename, const bool& clobber,
63 63 const std::string& extname = "ENERGIES") const;
64 64 void read(const GFitsTable& table);
65 65 void write(GFits& file, const std::string& extname = "ENERGIES") const;
... ...
pyext/GSkyRegion.i
... ... @@ -52,9 +52,9 @@ public:
52 52 virtual bool contains(const GSkyRegion& reg) const = 0;
53 53  
54 54 // Implemented methods
55   - std::string type(void) const;
56   - std::string name(void) const;
57   - double solidangle(void) const;
  55 + const std::string& type(void) const;
  56 + const std::string& name(void) const;
  57 + const double& solidangle(void) const;
58 58 };
59 59  
60 60  
... ...
pyext/GSkyRegionCircle.i
... ... @@ -45,12 +45,12 @@ public:
45 45 GSkyRegionCircle(const GSkyRegionCircle& region);
46 46 virtual ~GSkyRegionCircle(void);
47 47  
48   - // Implemented methods
  48 + // Implemented methods
49 49 void clear(void);
50 50 GSkyRegionCircle* clone(void) const;
51   - double radius(void) const;
  51 + const double& radius(void) const;
52 52 void radius(const double& radius);
53   - GSkyDir centre(void) const;
  53 + const GSkyDir& centre(void) const;
54 54 void centre(const GSkyDir& centre);
55 55 void centre(const double& ra,const double& dec);
56 56 double ra(void) const;
... ...
pyext/GUrl.i
... ... @@ -47,7 +47,7 @@ public:
47 47 virtual GUrl* clone(void) const = 0;
48 48 virtual void open(const std::string& url, const std::string& mode) = 0;
49 49 virtual void close(void) = 0;
50   - virtual int getchar(void) = 0;
  50 + virtual int getchar(void) const = 0;
51 51 virtual void putchar(const int& character) = 0;
52 52 };
53 53  
... ...
pyext/GUrlFile.i
... ... @@ -48,7 +48,7 @@ public:
48 48 virtual GUrlFile* clone(void) const;
49 49 virtual void open(const std::string& url, const std::string& mode);
50 50 virtual void close(void);
51   - virtual int getchar(void);
  51 + virtual int getchar(void) const;
52 52 virtual void putchar(const int& character);
53 53 };
54 54  
... ...
pyext/GUrlString.i
... ... @@ -48,7 +48,7 @@ public:
48 48 virtual GUrlString* clone(void) const;
49 49 virtual void open(const std::string& string, const std::string& mode = "");
50 50 virtual void close(void);
51   - virtual int getchar(void);
  51 + virtual int getchar(void) const;
52 52 virtual void putchar(const int& character);
53 53  
54 54 // Other methods
... ...
pyext/GXml.i
... ... @@ -83,7 +83,7 @@ public:
83 83 GXmlElement* element(const std::string& name, const int& index);
84 84 void load(const std::string& filename);
85 85 void save(const std::string& filename);
86   - void read(GUrl& url);
  86 + void read(const GUrl& url);
87 87 void write(GUrl& url, const int& indent = 0) const;
88 88 };
89 89  
... ...
src/linalg/GMatrixSparse.cpp
... ... @@ -1615,7 +1615,7 @@ double GMatrixSparse::sum(void) const
1615 1615 * Returns the Cholesky decomposition of a sparse matrix. The decomposition
1616 1616 * is stored within a GMatrixSparse object.
1617 1617 ***************************************************************************/
1618   -GMatrixSparse GMatrixSparse::cholesky_decompose(bool compress) const
  1618 +GMatrixSparse GMatrixSparse::cholesky_decompose(const bool& compress) const
1619 1619 {
1620 1620 // Create copy of matrix
1621 1621 GMatrixSparse matrix = *this;
... ... @@ -1695,7 +1695,7 @@ GMatrixSparse GMatrixSparse::cholesky_decompose(bool compress) const
1695 1695 * Choleksy factorization has been produced using 'cholesky_decompose'.
1696 1696 ***************************************************************************/
1697 1697 GVector GMatrixSparse::cholesky_solver(const GVector& vector,
1698   - bool compress) const
  1698 + const bool& compress) const
1699 1699 {
1700 1700 // Dump header
1701 1701 #if defined(G_DEBUG_SPARSE_COMPRESSION)
... ... @@ -1920,7 +1920,7 @@ GVector GMatrixSparse::cholesky_solver(const GVector&amp; vector,
1920 1920 *
1921 1921 * Inverts the matrix using a Cholesky decomposition.
1922 1922 ***************************************************************************/
1923   -GMatrixSparse GMatrixSparse::cholesky_invert(bool compress) const
  1923 +GMatrixSparse GMatrixSparse::cholesky_invert(const bool& compress) const
1924 1924 {
1925 1925 // Generate Cholesky decomposition of matrix
1926 1926 GMatrixSparse decomposition = cholesky_decompose(compress);
... ...
src/linalg/GMatrixSymmetric.cpp
... ... @@ -914,7 +914,7 @@ GMatrix GMatrixSymmetric::extract_upper_triangle(void) const
914 914 * Case A operates on a full matrix, Case B operates on a (logically)
915 915 * compressed matrix where zero rows/columns have been removed.
916 916 ***************************************************************************/
917   -GMatrixSymmetric GMatrixSymmetric::cholesky_decompose(bool compress) const
  917 +GMatrixSymmetric GMatrixSymmetric::cholesky_decompose(const bool& compress) const
918 918 {
919 919 // Create copy of matrix
920 920 GMatrixSymmetric matrix = *this;
... ... @@ -1020,7 +1020,7 @@ GMatrixSymmetric GMatrixSymmetric::cholesky_decompose(bool compress) const
1020 1020 * matrix, Case B on a zero rows/columns (logically) compressed matrix.
1021 1021 ***************************************************************************/
1022 1022 GVector GMatrixSymmetric::cholesky_solver(const GVector& vector,
1023   - bool compress) const
  1023 + const bool& compress) const
1024 1024 {
1025 1025 // Raise an exception if the matrix and vector dimensions are not compatible
1026 1026 if (m_rows != vector.size()) {
... ... @@ -1113,7 +1113,7 @@ GVector GMatrixSymmetric::cholesky_solver(const GVector&amp; vector,
1113 1113 * Case B operates on a (logically) compressed matrix where all zero
1114 1114 * rows/columns are skipped.
1115 1115 ***************************************************************************/
1116   -GMatrixSymmetric GMatrixSymmetric::cholesky_invert(bool compress) const
  1116 +GMatrixSymmetric GMatrixSymmetric::cholesky_invert(const bool& compress) const
1117 1117 {
1118 1118 // Generate Cholesky decomposition of matrix
1119 1119 GMatrixSymmetric matrix = cholesky_decompose(compress);
... ...
src/obs/GEnergies.cpp
... ... @@ -389,7 +389,7 @@ void GEnergies::load(const std::string&amp; filename, const std::string&amp; extname)
389 389 * extension. If another energies extension exists already it is overwritten
390 390 * if @p clobber=true.
391 391 ***************************************************************************/
392   -void GEnergies::save(const std::string& filename, bool clobber,
  392 +void GEnergies::save(const std::string& filename, const bool& clobber,
393 393 const std::string& extname) const
394 394 {
395 395 // Allocate FITS file
... ...
src/support/GUrlFile.cpp
... ... @@ -345,7 +345,7 @@ int GUrlFile::write(const void* buffer, const int&amp; nbyte)
345 345 *
346 346 * If no file has been opened, the method returns EOF.
347 347 ***************************************************************************/
348   -int GUrlFile::getchar(void)
  348 +int GUrlFile::getchar(void) const
349 349 {
350 350 // Initialise character to EOF
351 351 int character = EOF;
... ...
src/support/GUrlString.cpp
... ... @@ -348,7 +348,7 @@ int GUrlString::write(const void* buffer, const int&amp; nbyte)
348 348 *
349 349 * If no string exists, the method returns EOF.
350 350 ***************************************************************************/
351   -int GUrlString::getchar(void)
  351 +int GUrlString::getchar(void) const
352 352 {
353 353 // Initialise character to EOF
354 354 int character = EOF;
... ...
src/xml/GXml.cpp
... ... @@ -524,7 +524,7 @@ void GXml::save(const std::string&amp; filename)
524 524 * Reads in the XML document by parsing a Unified Resource Locator of any
525 525 * type.
526 526 ***************************************************************************/
527   -void GXml::read(GUrl& url)
  527 +void GXml::read(const GUrl& url)
528 528 {
529 529 // Clear object
530 530 clear();
... ... @@ -656,7 +656,7 @@ void GXml::free_members(void)
656 656 * nodes. The XML file is split into segments, made either of text or of
657 657 * tags.
658 658 ***************************************************************************/
659   -void GXml::parse(GUrl& url)
  659 +void GXml::parse(const GUrl& url)
660 660 {
661 661 // Initialise parser
662 662 int c;
... ...