Пример #1
0
int processMethodBody(Method *m, string& buf)
{
    cout << "------Begin processMethodBody------"<< endl;
    map<string, Arg*>::iterator it;
    for (it = m->GetArgMap().begin(); it != m->GetArgMap().end(); it++)
    {
        Arg *arg = it->second;
        string body_str;
        if (arg->GetDir() == "in")
        {
            readTemplateFile("/home/shankar/Dropbox/ASU_Courses/SmartHome/home_automation/smartgateway/codegen/template/smartobject_method_body_dir_in.template", body_str);
        }
        else
        {
            readTemplateFile("/home/shankar/Dropbox/ASU_Courses/SmartHome/home_automation/smartgateway/codegen/template/smartobject_method_body_dir_out.template", body_str);
        }

        std::string::const_iterator start, end;
        boost::regex exp("\\?<(\\w+)>");
        boost::match_results<std::string::const_iterator> what;
        boost::match_flag_type flags = boost::match_default;
        start = body_str.begin();
        end = body_str.end();

        while (regex_search(start, end, what, exp, flags))
        {
            string res = string(what[0].first, what[0].second);
            string command = string(what[1].first, what[1].second);
            cout << "res = ";
            cout << res << endl;
            cout << "command = ";
            cout << command << endl;

            /*
             * Now we have to replace the res with what the command specifies
             * For eg:
             * if res = "?<nocapital>" and command = "nocapital", then
             * 		replace "?<nocapital>" with "lighting".
             * if res = "?<allcapital>" and command = "allcapital", then
             * 		replace "?<allcapital>" with "LIGHTING".
             */
            if (command == "argname")
            {
                body_str.replace((what[0].first - body_str.begin()), res.size(), arg->GetName());
                start = body_str.begin();
            }
            else
            {
                start = what[0].second;
            }

            end = body_str.end();
        }

        buf.append(body_str);
    }
    cout << "------End processMethodBody------"<< endl;

    return 0;
}
Пример #2
0
int processMethodDecl(Method *m, string& buf)
{
    cout << "------Begin processMethodDecl------"<< endl;
    readTemplateFile("/home/shankar/Dropbox/ASU_Courses/SmartHome/home_automation/smartgateway/codegen/template/smartobject_method_decl.template",
                     buf);
    /* buf has the file data */
    std::string::const_iterator start, end;
    boost::regex exp("\\?<(\\w+)>");
    boost::match_results<std::string::const_iterator> what;
    boost::match_flag_type flags = boost::match_default;
    start = buf.begin();
    end = buf.end();

    while (regex_search(start, end, what, exp, flags))
    {
        string res = string(what[0].first, what[0].second);
        string command = string(what[1].first, what[1].second);
        cout << "res = ";
        cout << res << endl;
        cout << "command = ";
        cout << command << endl;
        //start = what[0].second;

        /*
         * Now we have to replace the res with what the command specifies
         * For eg:
         * if res = "?<nocapital>" and command = "nocapital", then
         * 		replace "?<nocapital>" with "lighting".
         * if res = "?<allcapital>" and command = "allcapital", then
         * 		replace "?<allcapital>" with "LIGHTING".
         */
        if (command == "methodname")
        {
            //buf.replace((what[0].first - start), res.size(), m->GetName());
            buf.replace((what[0].first - buf.begin()), res.size(), m->GetName());
            //start = what[0].first + m->GetName().size();
            start = buf.begin();
            //start = what[0].first;
        }
        else if (command == "arglist")
        {
            string arglist_str;
            map<string, Arg*>::iterator it;
            for (it = m->GetArgMap().begin(); it != m->GetArgMap().end(); it++)
            {
                Arg *arg = it->second;
                if (arg->GetDir() == "in")
                {
                    arglist_str = arglist_str + arg->GetType() + " " + arg->GetName() + ",";
                }
                else
                {
                    arglist_str = arglist_str + arg->GetType() + " *" + arg->GetName() + ",";
                }
            }

            cout << what[0].first - buf.begin() << endl;
            buf.replace((what[0].first - buf.begin()), res.size(), arglist_str);
            cout << buf << endl;
            start = buf.begin();
        }
        else
        {
            start = what[0].second;
        }

        end = buf.end();
    }

    cout << buf << endl;

    cout << "------End processMethodDecl------"<< endl;
    return 0;
}