| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 
 | // RuleTest2.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <string>
#include <iostream>
#include <sstream>
#include <map>
 
class Rule;
 
class RuleTypeDescription{
private:
    RuleTypeDescription();
public:
    RuleTypeDescription(int id, std::string name, int nature, std::string creaDate, std::string doc): id(id), name(name), nature(nature),creaDate(creaDate), doc(doc) {}
 
    static void insertDesc(int i, RuleTypeDescription* obj) {rulesTypeDesc[i] = obj;}
 
    int getNature() {return nature;}
private:
    int id;
    std::string name;
    int nature;
    std::string creaDate;
    std::string doc;
 
    static std::map <int, RuleTypeDescription*> rulesTypeDesc;
 
public:
    void printRule() const{
        std::cout << id << ":" << name << ":" << nature << ":" << creaDate << doc << std::endl;
    }
 
    static void listRules() {
        std::cout << "Listing RuleType:" << std::endl;
        for(std::map <int, RuleTypeDescription*>::const_iterator i = rulesTypeDesc.begin(); i != rulesTypeDesc.end(); i++){
            i->second->printRule();
        }
        std::cout << "----" << std::endl;
    }
    static void kill() {
        while (!rulesTypeDesc.empty()){
            delete rulesTypeDesc.begin()->second;
            rulesTypeDesc.erase(rulesTypeDesc.begin());
        }
    }
    static RuleTypeDescription* getRuleType(int i) {return rulesTypeDesc[i];}
};
 
std::map <int, RuleTypeDescription*> RuleTypeDescription::rulesTypeDesc;
 
 
class RuleDescription{
private:
    RuleDescription();
public:
    RuleDescription(int id, std::string name, std::string scope, RuleTypeDescription * ruleType): id(id), name(name), scope(scope),ruleType(ruleType)  {}
 
    static void insertDesc(int i, RuleDescription* obj) {rulesDesc[i] = obj;}
 
    std::string getName() {return name;}
private:
    int id;
    std::string name;
    std::string scope;
    std::string creaDate;
    std::string startDate;
    std::string endDate;
    std::string user;
 
    RuleTypeDescription * ruleType;
 
    static std::map <int, RuleDescription*> rulesDesc;
 
public:
    void printRule() const {
        std::cout << id << ":" << name << ":" << ruleType->getNature() << ":" << scope << ":" << creaDate << std::endl;
    }
 
    static void listRules() {
        std::cout << "Listing Rules:" << std::endl;
        for(std::map <int, RuleDescription*>::const_iterator i = rulesDesc.begin(); i != rulesDesc.end(); i++){
            i->second->printRule();
        }
        std::cout << "----" << std::endl;
    }
    static void kill() {
        while (!rulesDesc.empty()){
            delete rulesDesc.begin()->second;
            rulesDesc.erase(rulesDesc.begin());
        }
    }
 
    static RuleDescription* getRule(int i) {return rulesDesc[i];}
};
 
std::map <int, RuleDescription*> RuleDescription::rulesDesc;
 
class ParameterDescription{
public:
    ParameterDescription(int id, std::string name, int op, std::string value): id (id), name (name), idoperator(op), value(value) {}
 
private:
    ParameterDescription();
    int id;
    std::string name;
 
    int idoperator;
    std::string value;
public:
    std::string getName() {return name;}
    int getOperator() {return idoperator;}
    std::string getValue() {return value;}
 
    void print() {std::cout << name << ":" << idoperator << ":" << value << std::endl;}
 
};
 
class Rule{
protected:
    Rule() {ruleDesc = NULL;}
public:
    Rule(RuleDescription* ruleDesc):  ruleDesc(ruleDesc) {}
    virtual ~Rule(){
        while (!paramDesc.empty()){
            delete paramDesc.begin()->second;
            paramDesc.erase(paramDesc.begin());
        }
    }
 
    void insertParam(int i, ParameterDescription* param) {paramDesc[i] = param;}
 
    int getNumberParam() {return paramDesc.size();}
    std::string getNameParam(int i) {return paramDesc[i]->getName();}
    int getOperatorParam(int i) {return paramDesc[i]->getOperator();}
    std::string getOperatorValue(int i) {return paramDesc[i]->getValue();}
 
    void print() {
        std::cout << "Listing Params for rule:" << ruleDesc->getName() << std::endl;
        for(std::map <int, ParameterDescription*>::const_iterator i = paramDesc.begin(); i != paramDesc.end(); i++){
            i->second->print();
        }
        std::cout << "----" << std::endl;
    }
    virtual int getScope(int i) = 0;
    virtual Rule* getRule(int i)  = 0;
 
protected:
    RuleDescription* ruleDesc;
    std::map <int, ParameterDescription*> paramDesc;
 
};
 
class RuleBackToBench: public Rule{
public:
    RuleBackToBench( RuleDescription* ruleDesc): Rule( ruleDesc) {}
 
    static RuleBackToBench* getRule(int i) {
        std::stringstream strname;
        std::stringstream strdate;
        // Recherche Scope et recuperation bon RuleDescription
        RuleBackToBench* ruleB = new RuleBackToBench(RuleDescription::getRule(getScope(i)));
        for (int i = 0; i < 5; i++){
            ParameterDescription* tmp = NULL;
            strname.str("");
            strdate.str("");
            strname << "NameParam" << i;
            strdate << "Value" << i;
            tmp = new ParameterDescription(i, strname.str(), i%2, strdate.str());
            ruleB->insertParam(i, tmp);
        }
        return ruleB;
    }
 
    static int getScope(int i) {return i;}
};
 
class RuleSettlement: public Rule{
public:
    RuleSettlement( RuleDescription* ruleDesc): Rule( ruleDesc) {}
 
    static RuleSettlement* getRule(int i) {
        std::stringstream strname;
        std::stringstream strdate;
        // Recherche Scope et recuperation bon RuleDescription
        RuleSettlement* ruleB = new RuleSettlement(RuleDescription::getRule(getScope(i)));
        for (int i = 0; i < 5; i++){
            ParameterDescription* tmp = NULL;
            strname.str("");
            strdate.str("");
            strname << "NameParam" << i;
            strdate << "Value" << i;
            tmp = new ParameterDescription(i, strname.str(), i%2, strdate.str());
            ruleB->insertParam(i, tmp);
        }
        return ruleB;
    }
 
    static int getScope(int i) {return i;}
};
 
int _tmain(int argc, _TCHAR* argv[])
{    
    std::stringstream strname;
    std::stringstream strdate;
    std::stringstream strdoc;
    for (int i = 0; i < 5; i++) {
        RuleTypeDescription* tmp = NULL;
        strname.str("");
        strdate.str("");
        strdoc.str("");
        strname << "Name" << i;
        strdate << "Today" << i;
        strdoc << "Doc" << i;
        tmp = new RuleTypeDescription(i, strname.str(),i, strdate.str(), strdoc.str());
        RuleTypeDescription::insertDesc(i, tmp);
    }
    RuleTypeDescription::listRules();
 
    for (int i = 0; i < 10; i++) {
        RuleDescription* tmp = NULL; 
        strname.str("");
        strdate.str("");
        strdoc.str("");
        strname << "NameRule" << i;
        strdate << "Scope" << i;
        tmp = new RuleDescription(i, strname.str(), strdate.str(), RuleTypeDescription::getRuleType(i%3));
        RuleDescription::insertDesc(i, tmp);
    }
    RuleDescription::listRules();
 
    RuleBackToBench* ruleB = RuleBackToBench::getRule(0);
    ruleB->print();
    delete ruleB;
    ruleB = RuleBackToBench::getRule(1);
    ruleB->print();
    delete ruleB;
 
    RuleSettlement* ruleS = RuleSettlement::getRule(2);
    ruleS->print();
    delete ruleS;
 
    RuleTypeDescription::kill();
    RuleDescription::kill();
 
    int i;
    std::cin >> i;
    return 0;
} |