Пример #1
0
void fill_amortization_dictionary(
  ctemplate::TemplateDictionary& dict, Request& req)
{
  dict.SetValue("LoanAmt", req.post.count("LoanAmt")
      ? "$250,000" : req.post["LoanAmt"]);
  dict.SetIntValue("YearlyIntRate", req.post.pick("YearlyIntRate", 6.000));

  boost::array<std::string, 8> year_opts
    = {{ "5", "7", "10", "20", "30", "40", "50" }};
    
  BOOST_FOREACH(std::string& year, year_opts)
  {
    dict.SetValueAndShowSection("TermYrs", year, "SELECT_TERM_YEARS");
  }
Пример #2
0
static bool atpDictToCtemplateDict(ctemplate::TemplateDictionary &p_tplDict, ATP_Dictionary *p_atpDict)
{
    ATP_DictionaryIterator it;
    DBG("dictionary %p has %u entries\n", *p_atpDict, ATP_dictionaryCount(p_atpDict));
    for (it = ATP_dictionaryBegin(p_atpDict); ATP_dictionaryHasNext(it); it = ATP_dictionaryNext(it))
    {
        std::string l_key = ATP_dictionaryGetKey(it);

        DBG("reading from %p entry (type %s) '%s'\n", *p_atpDict, ATP_valueTypeToString(ATP_dictionaryGetType(it)), l_key.c_str());
        switch (ATP_dictionaryGetType(it))
        {
            case e_ATP_ValueType_string:
                {
                    const char *l_value = NULL;
                    ATP_dictionaryItGetString(it, &l_value);
                    p_tplDict.SetValue(l_key, l_value);
                }
                break;
            case e_ATP_ValueType_uint:
                {
                    unsigned long long l_value = 0;
                    ATP_dictionaryItGetUint(it, &l_value);
                    p_tplDict.SetValue(l_key, toString(l_value));
                }
                break;
            case e_ATP_ValueType_int:
                {
                    signed long long l_value = 0;
                    ATP_dictionaryItGetInt(it, &l_value);
                    p_tplDict.SetValue(l_key, toString(l_value));
                }
                break;
            case e_ATP_ValueType_double:
                {
                    double l_value = 0.0;
                    ATP_dictionaryItGetDouble(it, &l_value);
                    p_tplDict.SetValue(l_key, toString(l_value));
                }
                break;
            case e_ATP_ValueType_bool:
                {
                    int l_value = 0;
                    ATP_dictionaryItGetBool(it, &l_value);
                    p_tplDict.SetValue(l_key, (l_value ? "true" : "false"));
                }
                break;
            case e_ATP_ValueType_dict:
                {
                    ATP_Dictionary *l_value = NULL;
                    ctemplate::TemplateDictionary *l_subDict = p_tplDict.AddSectionDictionary(l_key);

                    ATP_dictionaryItGetDict(it, &l_value);
                    if (!atpDictToCtemplateDict(*l_subDict, l_value))
                    {
                        return false;
                    }
                    DBG("processed dictionary %p\n", *l_value);
                }
                break;
            case e_ATP_ValueType_array:
                {
                    ATP_Array *l_value = NULL;
                    ATP_dictionaryItGetArray(it, &l_value);
                    if (!atpArrayToCtemplateDicts(p_tplDict, l_value, l_key))
                    {
                        return false;
                    }
                    DBG("processed array %p\n", *l_value);
                }
                break;
            default:
                break;
        }
    }

    return true;
}