advgetopt/conf_file.cpp
/** \brief Transform the setup in a URL.
 *
 * This function transforms the configuration file setup in a unique URL.
 * This URL allows us to verify that two setup are the same so when
 * attempting to reload the same configuration file, we can make sure
 * you are attempting to do so with the same URL.
 *
 * This is because trying to read the same file with, for example, line
 * continuation set to Unix the first time and then set to MS-DOS the
 * second time would not load the same thing is either line continuation
 * was used.
 *
 * \todo
 * We should look into have a set_config_url() or have a constructor
 * which accepts a URL.
 *
 * \return The URL representing this setup.
 */
\brief Transform the setup in a URL.
This function transforms the configuration file setup in a unique URL.
This URL allows us to verify that two setup are the same so when
attempting to reload the same configuration file, we can make sure
you are attempting to do so with the same URL.

This is because trying to read the same file with, for example, line
continuation set to Unix the first time and then set to MS-DOS the
second time would not load the same thing is either line continuation
was used.

\todo
We should look into have a set_config_url() or have a constructor
which accepts a URL.

\return The URL representing this setup.
\ brief Transform the setup in a URL . This function transforms the configuration file setup in a unique URL . This URL allows us to verify that two setup are the same so when attempting to reload the same configuration file we can make sure you are attempting to do so with the same URL . This is because trying to read the same file with for example line continuation set to Unix the first time and then set to MS - DOS the second time would not load the same thing is either line continuation was used . \ todo We should look into have a set_config_url () or have a constructor which accepts a URL . \ return The URL representing this setup .
std::string conf_file_setup::get_config_url() const
{
    if(f_url.empty())
    {
        std::stringstream ss;
        ss << "file:"
           << (f_filename.empty()
                    ? "/<empty>"
                    : f_filename);
        std::vector<std::string> params;
        if(f_line_continuation != line_continuation_t::line_continuation_unix)
        {
            std::string name;
            switch(f_line_continuation)
            {
            case line_continuation_t::line_continuation_single_line:
                name = "single-line";
                break;
            case line_continuation_t::line_continuation_rfc_822:
                name = "rfc-822";
                break;
            case line_continuation_t::line_continuation_msdos:
                name = "msdos";
                break;
            case line_continuation_t::line_continuation_unix:
                name = "unix";
                break;
            case line_continuation_t::line_continuation_fortran:
                name = "fortran";
                break;
            case line_continuation_t::line_continuation_semicolon:
                name = "semi-colon";
                break;
            default:
                throw getopt_logic_error("unexpected line continuation.");
            }
            params.push_back("line-continuation=" + name);
        }
        if(f_assignment_operator != ASSIGNMENT_OPERATOR_EQUAL)
        {
            std::vector<std::string> assignments;
            if((f_assignment_operator & ASSIGNMENT_OPERATOR_EQUAL) != 0)
            {
                assignments.push_back("equal");
            }
            if((f_assignment_operator & ASSIGNMENT_OPERATOR_COLON) != 0)
            {
                assignments.push_back("colon");
            }
            if((f_assignment_operator & ASSIGNMENT_OPERATOR_SPACE) != 0)
            {
                assignments.push_back("space");
            }
            if(!assignments.empty())
            {
                params.push_back("assignment-operator=" + boost::algorithm::join(assignments, ","));
            }
        }
        if(f_comment != COMMENT_INI | COMMENT_SHELL)
        {
            std::vector<std::string> comment;
            if((f_comment & COMMENT_INI) != 0)
            {
                comment.push_back("ini");
            }
            if((f_comment & COMMENT_SHELL) != 0)
            {
                comment.push_back("shell");
            }
            if((f_comment & COMMENT_CPP) != 0)
            {
                comment.push_back("cpp");
            }
            if(comment.empty())
            {
                params.push_back("comment=none");
            }
            else
            {
                params.push_back("comment=" + boost::algorithm::join(comment, ","));
            }
        }
        if(f_section_operator != SECTION_OPERATOR_INI_FILE)
        {
            std::vector<std::string> section_operator;
            if((f_section_operator & SECTION_OPERATOR_C) != 0)
            {
                section_operator.push_back("c");
            }
            if((f_section_operator & SECTION_OPERATOR_CPP) != 0)
            {
                section_operator.push_back("cpp");
            }
            if((f_section_operator & SECTION_OPERATOR_BLOCK) != 0)
            {
                section_operator.push_back("block");
            }
            if((f_section_operator & SECTION_OPERATOR_INI_FILE) != 0)
            {
                section_operator.push_back("ini-file");
            }
            if(!section_operator.empty())
            {
                params.push_back("section-operator=" + boost::algorithm::join(section_operator, ","));
            }
        }
        std::string const query_string(boost::algorithm::join(params, "&"));
        if(!query_string.empty())
        {
            ss << '?'
               << query_string;
        }
        f_url = ss.str();
    }
    return f_url;
}
std :: string conf_file_setup :: get_config_url ( ) const { if ( f_url . empty ( ) ) { std :: stringstream ss ; ss << " " << ( f_filename . empty ( ) ? " " : f_filename ) ; std :: vector < std :: string > params ; if ( f_line_continuation != line_continuation_t :: line_continuation_unix ) { std :: string name ; switch ( f_line_continuation ) { case line_continuation_t :: line_continuation_single_line : name = " " ; break ; case line_continuation_t :: line_continuation_rfc_822 : name = " " ; break ; case line_continuation_t :: line_continuation_msdos : name = " " ; break ; case line_continuation_t :: line_continuation_fortran : name = " " ; break ; case line_continuation_t :: line_continuation_semicolon : name = " " ; break ; default : throw getopt_logic_error ( " " ) ; } params . push_back ( " " + name ) ; } if ( f_assignment_operator != ASSIGNMENT_OPERATOR_EQUAL ) { std :: vector < std :: string > assignments ; if ( ( f_assignment_operator & ASSIGNMENT_OPERATOR_EQUAL ) != 0 ) { assignments . push_back ( " " ) ; } if ( ( f_assignment_operator & ASSIGNMENT_OPERATOR_COLON ) != 0 ) { assignments . push_back ( " " ) ; } if ( ( f_assignment_operator & ASSIGNMENT_OPERATOR_SPACE ) != 0 ) { assignments . push_back ( " " ) ; } if ( ! assignments . empty ( ) ) { params . push_back ( " " + boost :: algorithm :: join ( assignments , " " ) ) ; } } if ( f_comment != COMMENT_INI | COMMENT_SHELL ) { std :: vector < std :: string > comment ; if ( ( f_comment & COMMENT_INI ) != 0 ) { comment . push_back ( " " ) ; } if ( ( f_comment & COMMENT_SHELL ) != 0 ) { comment . push_back ( " " ) ; } if ( ( f_comment & COMMENT_CPP ) != 0 ) { comment . push_back ( " " ) ; } if ( comment . empty ( ) ) { params . push_back ( " " ) ; } else { params . push_back ( " " + boost :: algorithm :: join ( comment , " " ) ) ; } } if ( f_section_operator != SECTION_OPERATOR_INI_FILE ) { std :: vector < std :: string > section_operator ; if ( ( f_section_operator & SECTION_OPERATOR_C ) != 0 ) { section_operator . push_back ( " " ) ; } if ( ( f_section_operator & SECTION_OPERATOR_CPP ) != 0 ) { section_operator . push_back ( " " ) ; } if ( ( f_section_operator & SECTION_OPERATOR_BLOCK ) != 0 ) { section_operator . push_back ( " " ) ; } if ( ( f_section_operator & SECTION_OPERATOR_INI_FILE ) != 0 ) { section_operator . push_back ( " " ) ; } if ( ! section_operator . empty ( ) ) { params . push_back ( " " + boost :: algorithm :: join ( section_operator , " " ) ) ; } } std :: string const query_string ( boost :: algorithm :: join ( params , " " ) ) ; if ( ! query_string . empty ( ) ) { ss << ' ' << query_string ; } f_url = ss . str ( ) ; } return f_url ; }
\brief Transform the setup in a URL.
\ brief Transform the setup in a URL .
// we should not ever receive this one since we don't enter // this block when the value is "unix" // //case line_continuation_t::line_continuation_unix: //    name = "unix"; //    break;