Commit 0a0a32d68ea105f966c92337bfd85900a2a167a4

Authored by Jürgen Knödlseder
1 parent 62a5e710

Add generic class template

dev/codegen.py
... ... @@ -191,12 +191,35 @@ def get_base_class(filename):
191 191 return baseclass
192 192  
193 193  
194   -# ========== #
195   -# Set tokens #
196   -# ========== #
197   -def set_tokens(name, instrument, author):
  194 +# ===================== #
  195 +# Set instrument tokens #
  196 +# ===================== #
  197 +def set_class_tokens(classname, author, what, object):
198 198 """
199   - Set replacement tokens
  199 + Set replacement tokens for a generic class
  200 + """
  201 + # Get current year
  202 + year = str(date.today().year)
  203 +
  204 + # Set tokens
  205 + tokens = [{'pattern': 'GTPLClass', 'string': classname},
  206 + {'pattern': 'GTPLCLASS', 'string': classname.upper()},
  207 + {'pattern': '[WHAT]', 'string': what},
  208 + {'pattern': '[what]', 'string': what.lower()},
  209 + {'pattern': '[AUTHOR]', 'string': author},
  210 + {'pattern': 'TPL_OBJECT', 'string': object.lower()},
  211 + {'pattern': '[YEAR]', 'string': year}]
  212 +
  213 + # Return tokens
  214 + return tokens
  215 +
  216 +
  217 +# ===================== #
  218 +# Set instrument tokens #
  219 +# ===================== #
  220 +def set_inst_tokens(name, instrument, author):
  221 + """
  222 + Set replacement tokens for an instrument
200 223 """
201 224 # Get current year
202 225 year = str(date.today().year)
... ... @@ -215,7 +238,7 @@ def set_tokens(name, instrument, author):
215 238 # ======================= #
216 239 # Add an instrument class #
217 240 # ======================= #
218   -def add_instrument_class(name, tokens, classname):
  241 +def add_instrument_class(name, tokens, classname, tmpname=None):
219 242 """
220 243 Add an instrument class
221 244  
... ... @@ -227,9 +250,12 @@ def add_instrument_class(name, tokens, classname):
227 250 Tokens for replacement
228 251 classname : str
229 252 Class name
  253 + tmpname : str, optional
  254 + Template name
230 255 """
231 256 # Set template classname
232   - tmpname = classname.replace(name.upper(), 'XXX')
  257 + if tmpname == None:
  258 + tmpname = classname.replace(name.upper(), 'XXX')
233 259  
234 260 # Set destination file names
235 261 incfile = 'inst/%s/include/%s.hpp' % (name, classname)
... ... @@ -495,7 +521,7 @@ def module_menu():
495 521 break
496 522  
497 523 # Set tokens
498   - tokens = set_tokens(name, instrument, author)
  524 + tokens = set_inst_tokens(name, instrument, author)
499 525  
500 526 # If the module exists already then determine all base classes that are
501 527 # not yet implemented and propose to add them one by one ...
... ... @@ -597,6 +623,61 @@ def module_menu():
597 623 return
598 624  
599 625  
  626 +# ==================== #
  627 +# Manage generic class #
  628 +# ==================== #
  629 +def generic_class_menu():
  630 + """
  631 + Manage class
  632 + """
  633 + # Annonce actions
  634 + print("")
  635 + print("Add generic class")
  636 + print("-----------------")
  637 +
  638 + # Stay in loop until there is a final confirmation
  639 + while True:
  640 +
  641 + # Get class directory
  642 + while True:
  643 + dir = response('Please enter directory where class should reside '
  644 + '(e.g. "inst/cta", "src/obs")').lower()
  645 + if os.path.isdir(dir):
  646 + break
  647 + else:
  648 + print('*** Error: Directory not found.')
  649 +
  650 + # Enter other information
  651 + classname = response('Please enter a class name (e.g. "GEnergy")')
  652 + what = response('Please say what the class is for (e.g. "Energy")')
  653 + object = response('Please say how an instance of the class should be named (e.g. "energy")')
  654 + author = response('Please enter your name (e.g. "Joe Public")')
  655 +
  656 + # Ask to confirm module summary
  657 + print('\nAll right. Have now:')
  658 + print('Class name ......: "%s"' % classname)
  659 + print('Class descriptor : "%s"' % what)
  660 + print('Class instance ..: "%s"' % object)
  661 + print('Your name .......: "%s"' % author)
  662 + if confirm('Is this correct?'):
  663 + break
  664 +
  665 + # Set tokens
  666 + tokens = set_class_tokens(classname, author, what, object)
  667 +
  668 + # If we have an instrument model then add a class to the instrument
  669 + if 'inst/' in dir:
  670 + name = dir[5:8]
  671 + add_instrument_class(name, tokens, classname, 'GTPLClass')
  672 +
  673 + # Otherwise we have a core module
  674 + else:
  675 + print('Core modules not supported yet, sorry ;)')
  676 +
  677 + # Return
  678 + return
  679 +
  680 +
600 681 # ================ #
601 682 # Manage main menu #
602 683 # ================ #
... ... @@ -609,7 +690,7 @@ def main_menu():
609 690 #print('[2] Add spectral model')
610 691 #print('[3] Add spatial model')
611 692 #print('[4] Add temporal model')
612   - #print('[4] Add generic class')
  693 + print('[4] Add generic class')
613 694 print('[q] Quit')
614 695  
615 696 # Wait for the input
... ... @@ -618,7 +699,7 @@ def main_menu():
618 699 choice = str(raw_input('Enter your choice: '))
619 700 #if choice == '1' or choice == '2' or choice == '3' or choice == '4' or \
620 701 # choice == 'q':
621   - if choice == '1' or choice == 'q':
  702 + if choice == '1' or choice == '4' or choice == 'q':
622 703 waiting = False
623 704  
624 705 # Return choice
... ... @@ -661,7 +742,7 @@ if __name__ == '__main__':
661 742 #libtool_version_menu()
662 743 print('')
663 744 elif choice == '4':
664   - #commit('')
  745 + generic_class_menu()
665 746 print('')
666 747 elif choice == 'q':
667 748 break
... ...
src/template/GTPLClass.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GTPLClass.cpp - [WHAT] class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) [YEAR] by [AUTHOR] *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GTPLClass.cpp
  23 + * @brief [WHAT] class implementation
  24 + * @author [AUTHOR]
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include "GTPLClass.hpp"
  32 +
  33 +/* __ Method name definitions ____________________________________________ */
  34 +
  35 +/* __ Macros _____________________________________________________________ */
  36 +
  37 +/* __ Coding definitions _________________________________________________ */
  38 +
  39 +/* __ Debug definitions __________________________________________________ */
  40 +
  41 +
  42 +
  43 +/*==========================================================================
  44 + = =
  45 + = Constructors/destructors =
  46 + = =
  47 + ==========================================================================*/
  48 +
  49 +/***********************************************************************//**
  50 + * @brief Void constructor
  51 + ***************************************************************************/
  52 +GTPLClass::GTPLClass(void)
  53 +{
  54 + // Initialise class members
  55 + init_members();
  56 +
  57 + // Return
  58 + return;
  59 +}
  60 +
  61 +
  62 +/***********************************************************************//**
  63 + * @brief Copy constructor
  64 + *
  65 + * @param[in] TPL_OBJECT [WHAT].
  66 + ***************************************************************************/
  67 +GTPLClass::GTPLClass(const GTPLClass& TPL_OBJECT)
  68 +{
  69 + // Initialise class members
  70 + init_members();
  71 +
  72 + // Copy members
  73 + copy_members(TPL_OBJECT);
  74 +
  75 + // Return
  76 + return;
  77 +}
  78 +
  79 +
  80 +/***********************************************************************//**
  81 + * @brief Destructor
  82 + ***************************************************************************/
  83 +GTPLClass::~GTPLClass(void)
  84 +{
  85 + // Free members
  86 + free_members();
  87 +
  88 + // Return
  89 + return;
  90 +}
  91 +
  92 +
  93 +/*==========================================================================
  94 + = =
  95 + = Operators =
  96 + = =
  97 + ==========================================================================*/
  98 +
  99 +/***********************************************************************//**
  100 + * @brief Assignment operator
  101 + *
  102 + * @param[in] TPL_OBJECT [WHAT].
  103 + * @return [WHAT].
  104 + ***************************************************************************/
  105 +GTPLClass& GTPLClass::operator=(const GTPLClass& TPL_OBJECT)
  106 +{
  107 + // Execute only if object is not identical
  108 + if (this != &TPL_OBJECT) {
  109 +
  110 + // Free members
  111 + free_members();
  112 +
  113 + // Initialise private members
  114 + init_members();
  115 +
  116 + // Copy members
  117 + copy_members(TPL_OBJECT);
  118 +
  119 + } // endif: object was not identical
  120 +
  121 + // Return this object
  122 + return *this;
  123 +}
  124 +
  125 +
  126 +/*==========================================================================
  127 + = =
  128 + = Public methods =
  129 + = =
  130 + ==========================================================================*/
  131 +
  132 +/***********************************************************************//**
  133 + * @brief Clear [what]
  134 + ***************************************************************************/
  135 +void GTPLClass::clear(void)
  136 +{
  137 + // Free members
  138 + free_members();
  139 +
  140 + // Initialise private members
  141 + init_members();
  142 +
  143 + // Return
  144 + return;
  145 +}
  146 +
  147 +
  148 +/***********************************************************************//**
  149 + * @brief Clone [what]
  150 + *
  151 + * @return Pointer to deep copy of [WHAT].
  152 + ***************************************************************************/
  153 +GTPLClass* GTPLClass::clone(void) const
  154 +{
  155 + return new GTPLClass(*this);
  156 +}
  157 +
  158 +
  159 +/***********************************************************************//**
  160 + * @brief Print [what]
  161 + *
  162 + * @param[in] chatter Chattiness.
  163 + * @return String containing [what] information.
  164 + *
  165 + * @todo Implement method.
  166 + ***************************************************************************/
  167 +std::string GTPLClass::print(const GChatter& chatter) const
  168 +{
  169 + // Initialise result string
  170 + std::string result;
  171 +
  172 + // Continue only if chatter is not silent
  173 + if (chatter != SILENT) {
  174 +
  175 + // Append header
  176 + result.append("=== GTPLClass ===");
  177 +
  178 + // Append information
  179 + // TODO: Add any relevant information
  180 +
  181 + } // endif: chatter was not silent
  182 +
  183 + // Return result
  184 + return result;
  185 +}
  186 +
  187 +
  188 +/*==========================================================================
  189 + = =
  190 + = Private methods =
  191 + = =
  192 + ==========================================================================*/
  193 +
  194 +/***********************************************************************//**
  195 + * @brief Initialise class members
  196 + ***************************************************************************/
  197 +void GTPLClass::init_members(void)
  198 +{
  199 + // Initialise members
  200 + // TODO: Initialise all data members
  201 +
  202 + // Return
  203 + return;
  204 +}
  205 +
  206 +
  207 +/***********************************************************************//**
  208 + * @brief Copy class members
  209 + *
  210 + * @param[in] TPL_OBJECT [WHAT].
  211 + ***************************************************************************/
  212 +void GTPLClass::copy_members(const GTPLClass& TPL_OBJECT)
  213 +{
  214 + // Copy attributes
  215 + // TODO: Copy all data members
  216 +
  217 + // Return
  218 + return;
  219 +}
  220 +
  221 +
  222 +/***********************************************************************//**
  223 + * @brief Delete class members
  224 + ***************************************************************************/
  225 +void GTPLClass::free_members(void)
  226 +{
  227 + // Return
  228 + return;
  229 +}
... ...
src/template/GTPLClass.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GTPLClass.hpp - [WHAT] class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) [YEAR] by [AUTHOR] *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GTPLClass.hpp
  23 + * @brief [WHAT] class definition
  24 + * @author [AUTHOR]
  25 + */
  26 +
  27 +#ifndef GTPLCLASS_HPP
  28 +#define GTPLCLASS_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include <string>
  32 +#include "GBase.hpp"
  33 +
  34 +
  35 +/***********************************************************************//**
  36 + * @class GTPLClass
  37 + *
  38 + * @brief [WHAT] class
  39 + *
  40 + * @todo Add class description.
  41 + ***************************************************************************/
  42 +class GTPLClass : public GBase {
  43 +
  44 +public:
  45 + // Constructors and destructors
  46 + GTPLClass(void);
  47 + GTPLClass(const GTPLClass& TPL_OBJECT);
  48 + virtual ~GTPLClass(void);
  49 +
  50 + // Operators
  51 + GTPLClass& operator=(const GTPLClass& TPL_OBJECT);
  52 +
  53 + // Implemented pure virtual base class methods
  54 + virtual void clear(void);
  55 + virtual GTPLClass* clone(void) const;
  56 + virtual std::string classname(void) const;
  57 + virtual std::string print(const GChatter& chatter = NORMAL) const;
  58 +
  59 + // Other methods
  60 + // TODO: Add any further methods that are needed
  61 +
  62 +protected:
  63 + // Protected methods
  64 + void init_members(void);
  65 + void copy_members(const GTPLClass& TPL_OBJECT);
  66 + void free_members(void);
  67 +
  68 + // Protected members
  69 + // TODO: Add any data members that are necessary
  70 +};
  71 +
  72 +
  73 +/***********************************************************************//**
  74 + * @brief Return class name
  75 + *
  76 + * @return String containing the class name ("GTPLClass").
  77 + ***************************************************************************/
  78 +inline
  79 +std::string GTPLClass::classname(void) const
  80 +{
  81 + return ("GTPLClass");
  82 +}
  83 +
  84 +#endif /* GTPLCLASS_HPP */
... ...
src/template/GTPLClass.i 0 → 100644
  1 +/***************************************************************************
  2 + * GTPLClass.i - [WHAT] class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) [YEAR] by [AUTHOR] *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GTPLClass.i
  23 + * @brief [WHAT] class definition
  24 + * @author [AUTHOR]
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GTPLClass.hpp"
  29 +%}
  30 +
  31 +
  32 +/***********************************************************************//**
  33 + * @class GTPLClass
  34 + *
  35 + * @brief [WHAT] class
  36 + ***************************************************************************/
  37 +class GTPLClass : public GRoi {
  38 +
  39 +public:
  40 + // Constructors and destructors
  41 + GTPLClass(void);
  42 + GTPLClass(const GTPLClass& TPL_OBJECT);
  43 + virtual ~GTPLClass(void);
  44 +
  45 + // Implemented pure virtual base class methods
  46 + virtual void clear(void);
  47 + virtual GTPLClass* clone(void) const;
  48 +
  49 + // Other methods
  50 + // TODO: Copy methods from GTPLClass.hpp file
  51 +};
  52 +
  53 +
  54 +/***********************************************************************//**
  55 + * @brief GTPLClass class extension
  56 + ***************************************************************************/
  57 +%extend GTPLClass {
  58 + GTPLClass copy() {
  59 + return (*self);
  60 + }
  61 +};
... ...
src/template/Makefile.am
... ... @@ -25,7 +25,8 @@ INCLUDES = -I$(top_srcdir)/include \
25 25 -I$(top_srcdir)/src/support
26 26  
27 27 # Define sources for this directory
28   -sources = GXXXObservation.cpp \
  28 +sources = GTPLClass.cpp \
  29 + GXXXObservation.cpp \
29 30 GXXXResponse.cpp \
30 31 GXXXEventList.cpp \
31 32 GXXXEventAtom.cpp \
... ... @@ -42,7 +43,9 @@ libtemplate_la_SOURCES = $(sources)
42 43 libtemplate_la_LDFLAGS =
43 44  
44 45 # Additional files to distribute
45   -EXTRA_DIST = GXXXLib.hpp \
  46 +EXTRA_DIST = GTPLClass.hpp \
  47 + GTPLClass..i \
  48 + GXXXLib.hpp \
46 49 GXXXObservation.hpp \
47 50 GXXXObservation.i \
48 51 GXXXResponse.hpp \
... ...