首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CppDepend中的圈复杂度

CppDepend中的圈复杂度
EN

Stack Overflow用户
提问于 2018-06-20 19:49:40
回答 1查看 124关注 0票数 1

我试图理解圈复杂度是如何工作的,有人能解释一下为什么下面的代码给出了3的分数:

代码语言:javascript
运行
复制
CommandLineAgruments Parse(int argc, char *argv[])
{
    CommandLineAgruments result;

    std::string command;
    std::vector<std::string> arguments;
    for (int i = 0; i < argc; i++)
    {
        std::string currentArg = std::string(argv[i]);
        size_t index = currentArg.find('-');
        if (index == 0)
        {
            // new commandline argument. Parse the old argument if we have one, then reset
            if (command.size() != 0)
            {
                if (m_supportedCommandLines.find(command) != m_supportedCommandLines.end())
                    m_supportedCommandLines[command](arguments, result);
                else
                    throw std::invalid_argument("Argument not supported : '" + command + "'");
            }

            command = currentArg;
            arguments.clear();
        }
        else
        {
            arguments.push_back(currentArg);
        }
    }

    // Parse last command if we have one
    if (command.size() != 0)
    {
        if (m_supportedCommandLines.find(command) != m_supportedCommandLines.end())
            m_supportedCommandLines[command](arguments, result);
        else
            throw std::invalid_argument("Argument not supported : '" + command + "'");
    }

    return result;
}

这个函数给出了1的分数:

代码语言:javascript
运行
复制
void ParseOutputArgument(const std::vector<std::string> &arguments, 
CommandLineAgruments &commandLine)
{
    std::string arg = arguments[0];
    std::transform(arg.begin(), arg.end(), arg.begin(), ::tolower);
    if (arg == "file")
    {
        if (arguments.size() != 2)
            throw std::invalid_argument("Missing output file path");

        commandLine.OutputFile = arguments[1];
        commandLine.FileOutputType = CommandLineAgruments::OutputEnum::File;
    }
    else if (arg == "console")
    {
        if (arguments.size() != 1)
            throw std::invalid_argument("Invalid arguments for output");

        commandLine.FileOutputType = CommandLineAgruments::OutputEnum::Console;
    }
    else
    {
        throw std::invalid_argument("'" + arg + "' is an invalid argument for output");
    }
}

我知道函数A比函数B更复杂,但我很难看出函数B是如何得到1分的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-21 16:43:36

这是CppDepend的一个问题,计划2018年7月推出的新版本2018.2将解决这个问题。感谢克里斯蒂安给我们一个样本来复制它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50956017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档