예제 #1
0
Stroka PrintItemPerSecond(TDuration time, size_t itemscount, int kbase) {
    TStringStream res;
    double seconds = (double)(time.MilliSeconds()) / 1000.0;
    if (itemscount == 0)
        res << "0";
    else if (time == TDuration::Zero() && seconds == 0.0)
        res << "INF";
    else
        res << NFormat::Short<double>(itemscount / seconds, kbase);
    return res.Str();
}
예제 #2
0
Stroka PrintTimePerItem(TDuration time, size_t count) {
    TStringStream res;
    if (time == TDuration::Zero())
        res << "0";
    else if (count == 0)
        res << "INF";
    else
        res << NFormat::Duration(time / count);

    return res.Str();
}
예제 #3
0
static Stroka Summary(TInstant start, size_t totalLines, TInstant prev, size_t prevLines, bool shrinked = true) {
    TInstant current = Now();
    TStringStream res;

    if (shrinked)
        res << NFormat::Short(totalLines);
    else
        res << totalLines;

    res << " processed (" << NFormat::Duration(current - start) << ", "
        << PrintTimePerItem(current - prev, prevLines) << " -> "
        << PrintTimePerItem(current - start, totalLines) << " avg)";

    return res.Str();
}
예제 #4
0
        inline void TestVirtualInheritance() {
            TStringStream ss;

            OUTS = &ss;

            class TA {
                public:
                    inline TA() {
                        *OUTS << "A";
                    }
            };

            class TB {
                public:
                    inline TB() {
                        *OUTS << "B";
                    }
            };

            class TC: public virtual TB, public virtual TA {
                public:
                    inline TC() {
                        *OUTS << "C";
                    }
            };

            class TD: public virtual TA {
                public:
                    inline TD() {
                        *OUTS << "D";
                    }
            };

            class TE: public TC, public TD {
                public:
                    inline TE() {
                        *OUTS << "E";
                    }
            };

            TE e;

            UNIT_ASSERT_EQUAL(ss.Str(), "BACDE");
        }
예제 #5
0
static Stroka SummaryBytes(TInstant start, size_t totalLines, TInstant prev, size_t prevLines, bool shrinked = true) {
    TInstant current = Now();

    const size_t KB = 1024;
    const size_t MB = 1024*KB;

    TStringStream res;

    if (shrinked)
        res << NFormat::Short(totalLines, KB);
    else
        res << totalLines;

    res << " bytes processed (" << NFormat::Duration(current - start) << ", "
        << PrintTimePerItem(current - prev, prevLines/MB) << "/MB -> "
        << PrintTimePerItem(current - start, totalLines/MB) << "/MB, "
        << PrintItemPerSecond(current - start, totalLines, KB) << "B/s avg)";

    return res.Str();
}
예제 #6
0
bool TSimpleTextMiner::Run()
{
    if (Input == NULL || Output == NULL)
        return false;

    Wtroka text;
    SDocumentAttribtes docAttr;
    ETypeOfDocument type;

    while (DoInput(text, docAttr, type)) {
        bool res = DoProcess(text, docAttr, type);
        if (res)
            res = DoOutput(docAttr);

        if (!res && Errors != NULL && dynamic_cast<TStringStream*>(ErrorStream) != NULL) {
            TStringStream* str = static_cast<TStringStream*>(ErrorStream);
            Errors->OutputError(str->Str());
            str->clear();
        }
    }

    return true;
}
예제 #7
0
static TString FormatOption(const TOpt* option, const NColorizer::TColors& colors) {
    TStringStream result;
    const TOpt::TShortNames& shorts = option->GetShortNames();
    const TOpt::TLongNames& longs = option->GetLongNames();

    const size_t nopts = shorts.size() + longs.size();
    const bool multiple = 1 < nopts;
    if (multiple)
        result << '{';
    for (size_t i = 0; i < nopts; ++i) {
        if (multiple && 0 != i)
            result << '|';

        if (i < shorts.size()) // short
            result  << colors.GreenColor() << '-' << shorts[i] << colors.OldColor();
        else
            result << colors.GreenColor() << "--" << longs[i - shorts.size()] << colors.OldColor();
    }
    if (multiple)
        result << '}';

    static const TString metavarDef("VAL");
    const TString& title = option->GetArgTitle();
    const TString& metavar = title.Empty() ? metavarDef : title;

    if (option->GetHasArg() == OPTIONAL_ARGUMENT) {
        result << " [" << metavar;
        if (option->HasOptionalValue())
            result << ':' << option->GetOptionalValue();
        result << ']';
    } else if (option->GetHasArg() == REQUIRED_ARGUMENT)
        result << ' ' << metavar;
    else
        Y_ASSERT(option->GetHasArg() == NO_ARGUMENT);

    return result.Str();
}
예제 #8
0
static Stroka FormatOption(const TOpt* option) {
    TStringStream result;
    const TOpt::TShortNames& shorts = option->GetShortNames();
    const TOpt::TLongNames& longs = option->GetLongNames();

    const size_t nopts = shorts.size() + longs.size();
    const bool multiple = 1 < nopts;
    if (multiple)
        result << '{';
    for (size_t i = 0; i < nopts; ++i) {
        if (multiple && 0 != i)
            result << '|';

        if (i < shorts.size()) // short
            result << '-' << shorts[i];
        else
            result << "--" << longs[i - shorts.size()];
    }
    if (multiple)
        result << '}';

    static const Stroka metavarDef("VAL");
    const Stroka& title = option->ArgTitle_;
    const Stroka& metavar = title.Empty() ? metavarDef : title;

    if (option->HasArg_ == OPTIONAL_ARGUMENT) {
        result << " [" << metavar;
        if (option->HasOptionalValue())
            result << ':' << option->GetOptionalValue();
        result << ']';
    } else if (option->HasArg_ == REQUIRED_ARGUMENT)
        result << ' ' << metavar;
    else
        YASSERT(option->HasArg_ == NO_ARGUMENT);

    return result.Str();
}
예제 #9
0
 TString OptToString(const TString& longOption) {
     TStringStream ss;
     ss << "--" << longOption;
     return ss.Str();
 }
예제 #10
0
 TString OptToString(char c) {
     TStringStream ss;
     ss << "-" << c;
     return ss.Str();
 }
예제 #11
0
void TOpts::PrintUsage(const TStringBuf& program, IOutputStream& osIn, const NColorizer::TColors& colors) const {
    TStringStream os;

    if (!Title.empty())
        os << Title << "\n\n";

    PrintCmdLine(program, os, colors);

    TVector<TString> leftColumn(Opts_.size());
    TVector<size_t> leftColumnSizes(leftColumn.size());
    size_t leftWidth = 0;
    size_t requiredOptionsCount = 0;
    NColorizer::TColors disabledColors(false);

    for (size_t i = 0; i < Opts_.size(); i++) {
        const TOpt* opt = Opts_[i].Get();
        if (opt->IsHidden())
            continue;
        leftColumn[i] = FormatOption(opt, colors);
        const size_t leftColumnSize = colors.IsTTY() ? FormatOption(opt, disabledColors).size() : leftColumn[i].size();
        leftColumnSizes[i] = leftColumnSize;
        leftWidth = Max(leftWidth, leftColumnSize);
        if (opt->IsRequired())
            requiredOptionsCount++;
    }

    const size_t kMaxLeftWidth = 25;
    leftWidth = Min(leftWidth, kMaxLeftWidth);
    const TString maxPadding(kMaxLeftWidth, ' ');
    const TString leftPadding(leftWidth, ' ');

    for (size_t sectionId = 0; sectionId <= 1; sectionId++) {
        bool requiredOptionsSection = (sectionId == 0);

        if (requiredOptionsSection) {
            if (requiredOptionsCount == 0)
                continue;
            os << Endl << colors.BoldColor() << "Required parameters" << colors.OldColor() << ":" << Endl;
        } else {
            if (requiredOptionsCount == Opts_.size())
                continue;
            if (requiredOptionsCount == 0)
                os << Endl << colors.BoldColor() << "Options" << colors.OldColor() << ":" << Endl;
            else
                os << Endl << colors.BoldColor() << "Optional parameters" << colors.OldColor() << ":" << Endl;  // optional options would be a tautology
        }

        for (size_t i = 0; i < Opts_.size(); i++) {
            const TOpt* opt = Opts_[i].Get();

            if (opt->IsHidden())
                continue;
            if (opt->IsRequired() != requiredOptionsSection)
                continue;

            if (leftColumnSizes[i] > leftWidth && !opt->GetHelp().empty()) {
                os <<
                SPad << leftColumn[i] << Endl <<
                SPad << maxPadding << ' ';
            } else {
                os << SPad << leftColumn[i] << ' ';
                if (leftColumnSizes[i] < leftWidth)
                    os << TStringBuf(~leftPadding, leftWidth - leftColumnSizes[i]);
            }

            bool multiLineHelp = false;
            if (!opt->GetHelp().empty()) {
                TVector<TStringBuf> helpLines;
                Split(opt->GetHelp(), "\n", helpLines);
                multiLineHelp = (helpLines.size() > 1);
                os << helpLines[0];
                for (size_t j = 1; j < helpLines.size(); ++j) {
                    if (helpLines[j].empty())
                        continue;
                    os << Endl << SPad << leftPadding << ' ' << helpLines[j];
                }
            }

            if (opt->HasDefaultValue()) {
                TString quotedDef = QuoteForHelp(opt->GetDefaultValue());
                if (multiLineHelp)
                    os << Endl << SPad << leftPadding << " Default: " << colors.CyanColor() << quotedDef << colors.OldColor();
                else if (opt->GetHelp().empty())
                    os << "Default: " << colors.CyanColor() << quotedDef << colors.OldColor();
                else
                    os << " (default: " << colors.CyanColor() << quotedDef << colors.OldColor() << ")";
            }

            os << Endl;
        }
    }
    PrintFreeArgsDesc(os, colors);
    osIn << os.Str();
}
예제 #12
0
Stroka CPrimitiveGroup::DebugString() const {
    TStringStream str;
    str << "CPrimitiveGroup \"" << NStr::DebugEncode(UTF8ToWide(GetRuleName())) << "\": homonyms [" << m_ActiveHomonyms << "]";
    return str.Str();
}