Ignore:
Timestamp:
03/01/14 22:05:02 (8 years ago)
Author:
sz
Message:

Warn against missing converter, convert() caller can differentiate between conversion failure and missing converter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/geno.h

    r145 r150  
    1515class GenoValidator
    1616{
    17   public:
    18 virtual int testGenoValidity(Geno& g)=0;/// -1=no information  0=invalid  1=valid
     17public:
     18        virtual int testGenoValidity(Geno& g) = 0;/// -1=no information  0=invalid  1=valid
    1919};
    2020
    21 /// basic GenoValidator that works by building a Model from any Geno (by converting to f0)
    22 /// validation fails when the model can't be built or the genotype can't be converted
    23 class ModelGenoValidator: public GenoValidator
     21/// Basic GenoValidator that works by building a Model from any Geno (by converting to f0).
     22/// Validation fails when the model can't be built or the genotype can't be converted.
     23class ModelGenoValidator : public GenoValidator
    2424{
    2525public:
     
    2828
    2929/// basic information about a single genotype.
    30 class Geno: public DestrBase
     30class Geno : public DestrBase
    3131{
    32 friend class Simulator;//needs to access validators directly
    33 SString gen;
    34 SString name;
    35 char format;
    36 SString txt;
    37 int isvalid; ///< <0 -> unknown   >=0 -> value for "isValid"
     32        friend class Simulator;//needs to access validators directly
     33        SString gen;
     34        SString name;
     35        char format;
     36        SString txt;
     37        int isvalid; ///< <0 -> unknown   >=0 -> value for "isValid"
    3838
    39 Geno *f0gen;
     39        Geno *f0gen;
    4040
    41 int mapinshift; /// # of characters in the initial comment
    42 int mapoutshift; /// # of characters in the output comment
    43 int multiline;
     41        int mapinshift; /// number of characters in the initial comment
     42        int mapoutshift; /// number of characters in the output comment
     43        int multiline;
    4444
    45 void init(const SString& genstring,char genformat,const SString& genname,const SString& comment);
    46 void validate(void);
     45        void init(const SString& genstring, char genformat, const SString& genname, const SString& comment);
     46        void validate(void);
    4747
    48 void freeF0();
     48        void freeF0();
    4949
    50 bool isInvalid() {return isvalid==0;}
     50        bool isInvalid() { return isvalid == 0; }
    5151
    52 friend class Model;
    53 friend class GenoConvManager;
    54        
     52        friend class Model;
     53        friend class GenoConvManager;
     54
    5555public:
    56 /// create a genotype object from primitives
    57 /// @param genstring pure genotype, without any comments
    58 /// @param genformat genotype format
    59 /// @param comment information about genotype (for genetic operators and "history")
    60 Geno(const char *genstring=0,char genformat=-1,const char *genname=0,const char *comment=0);
     56        /// create a genotype object from primitives
     57        /// @param genstring pure genotype, without any comments
     58        /// @param genformat genotype format
     59        /// @param comment information about genotype (for genetic operators and "history")
     60        Geno(const char *genstring = 0, char genformat = -1, const char *genname = 0, const char *comment = 0);
    6161
    62 /// create a genotype object from primitives
    63 /// @param genstring pure genotype, wihtout any comments
    64 /// @param genformat genotype format
    65 /// @param name genotype name, new name will generated if needed
    66 /// @param comment information about genotype (for genetic operators and "history")
    67 Geno(const SString& genstring,char genformat,const SString& genname,const SString& comment);
     62        /// create a genotype object from primitives
     63        /// @param genstring pure genotype, wihtout any comments
     64        /// @param genformat genotype format
     65        /// @param name genotype name, new name will generated if needed
     66        /// @param comment information about genotype (for genetic operators and "history")
     67        Geno(const SString& genstring, char genformat, const SString& genname, const SString& comment);
    6868
    69 /// create object from full string, containing optional format and comment information
    70 Geno(const SString & fullstring);
     69        /// create object from full string, containing optional format and comment information
     70        Geno(const SString & fullstring);
    7171
    72 /// clone
    73 Geno(const Geno& src);
     72        /// clone
     73        Geno(const Geno& src);
    7474
    75 void operator=(const Geno& src);
     75        void operator=(const Geno& src);
    7676
    77 ~Geno();
     77        ~Geno();
    7878
    79 void setValid(int v) {isvalid=v;}
    80 int getValid() {return isvalid;}
     79        void setValid(int v) { isvalid = v; }
     80        int getValid() { return isvalid; }
    8181
    82 /// return string representation, with format comment at the beginning
    83 SString toString(void) const;
    84 SString shortString(void) const;
     82        /// return string representation, with format comment at the beginning
     83        SString toString(void) const;
     84        SString shortString(void) const;
    8585
    86 void setString(const SString& genewithcomments);
     86        void setString(const SString& genewithcomments);
    8787
    88 /** @param newformat=-1 -> don't change */
    89 void setGene(const SString& g, char newformat=-1);
    90 SString getGene(void) const;
     88        /** @param newformat=-1 -> don't change */
     89        void setGene(const SString& g, char newformat = -1);
     90        SString getGene(void) const;
    9191
    92 SString getName(void) const;
    93 void setName(const SString&);
    94 char getFormat(void) const;
     92        SString getName(void) const;
     93        void setName(const SString&);
     94        char getFormat(void) const;
    9595
    96 SString getComment(void) const;
    97 void setComment(const SString&);
     96        SString getComment(void) const;
     97        void setComment(const SString&);
    9898
    99 /// invalid genotype cannot be used to build a creature
    100 bool isValid(void);
     99        /// invalid genotype cannot be used to build a creature
     100        bool isValid(void);
    101101
    102 /// make converted version of the genotype.
    103 Geno getConverted(char otherformat,MultiMap *m=0);
     102        /// make converted version of the genotype.
     103        /// @param converter_missing optional output parameter (ignored when NULL). Receives true if the conversion fails because of the lack of appropriate converter(s) (the returned Geno is always invalid in this case). Receives false if the genotype was converted by a converter or a converter chain (the returned Geno can be valid or invalid, depending on the converter's decision).
     104        Geno getConverted(char otherformat, MultiMap *m = 0, bool *converter_missing = NULL);
    104105
    105 /// @return -1 = before first char in the string
    106 /// @return -2 = after last char in the string
    107 int mapGenToString(int genpos) const;
    108 /// @return -1 = before first char in the genotype
    109 /// @return -2 = after last char in the genotype
    110 int mapStringToGen(int stringpos) const;
     106        /// @return -1 = before first char in the string
     107        /// @return -2 = after last char in the string
     108        int mapGenToString(int genpos) const;
     109        /// @return -1 = before first char in the genotype
     110        /// @return -2 = after last char in the genotype
     111        int mapStringToGen(int stringpos) const;
    111112
    112 int operator==(const Geno &g) {return (format==g.format)&&(gen==g.gen);}
     113        int operator==(const Geno &g) { return (format == g.format) && (gen == g.gen); }
    113114
    114 void* owner;
     115        void* owner;
    115116
    116 // managing global Geno-related objects (used for validation and conversion)
    117 static void addValidator(GenoValidator* gv) {validators+=gv;}
    118 static void removeValidator(GenoValidator* gv) {validators-=gv;}
    119 static void useConverters(GenoConvManager& gcm) {converters=&gcm;}
    120 static GenoConvManager &getConverters() {return *converters;}
    121   protected:
    122 static GenoConvManager *converters;
    123 static SListTempl<GenoValidator*> validators;
     117        // managing global Geno-related objects (used for validation and conversion)
     118        static void addValidator(GenoValidator* gv) { validators += gv; }
     119        static void removeValidator(GenoValidator* gv) { validators -= gv; }
     120        static void useConverters(GenoConvManager& gcm) { converters = &gcm; }
     121        static GenoConvManager &getConverters() { return *converters; }
     122protected:
     123        static GenoConvManager *converters;
     124        static SListTempl<GenoValidator*> validators;
    124125};
    125126
Note: See TracChangeset for help on using the changeset viewer.