Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8777 for code/branches


Ignore:
Timestamp:
Jul 25, 2011, 2:47:49 PM (13 years ago)
Author:
landauf
Message:

output contexts are now defined as functions instead of global constants. this should avoid a static initialization fiasco and reduces the amount of context registrations (previosly it was N*M registrations with N = number of contexts and M = number of source files, now they are registered on demand). slightly worse performance though.

Location:
code/branches/output/src/libraries/util
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/output/src/libraries/util/Output.h

    r8765 r8777  
    4040    using namespace level;
    4141
    42     inline OutputStream& orxout(OutputLevel level = level::debug_output, OutputContext context = context::undefined)
     42    inline OutputStream& orxout(OutputLevel level = level::debug_output, OutputContextFunction context = context::undefined)
    4343    {
    4444        static OutputStream stream;
  • code/branches/output/src/libraries/util/output/LogWriter.cc

    r8776 r8777  
    8383
    8484        if (this->bDefaultPath_)
    85             OutputManager::getInstance().pushMessage(level::user_info, context::output, "Opening log file " + name);
     85            OutputManager::getInstance().pushMessage(level::user_info, context::output(), "Opening log file " + name);
    8686
    8787        this->file_.open(name.c_str(), std::fstream::out);
     
    9090            this->printLine("Log file opened");
    9191        else
    92             OutputManager::getInstance().pushMessage(level::user_warning, context::output, "Failed to open log file. File logging disabled.");
     92            OutputManager::getInstance().pushMessage(level::user_warning, context::output(), "Failed to open log file. File logging disabled.");
    9393    }
    9494
     
    104104    void LogWriter::setLogPath(const std::string& path)
    105105    {
    106         OutputManager::getInstance().pushMessage(level::internal_info, context::output, "Migrating log file from " + this->path_ + "\nto " + path);
     106        OutputManager::getInstance().pushMessage(level::internal_info, context::output(), "Migrating log file from " + this->path_ + "\nto " + path);
    107107
    108108        this->closeFile();
  • code/branches/output/src/libraries/util/output/MemoryWriter.cc

    r8776 r8777  
    6767    {
    6868        OutputManager::getInstance().unregisterListener(this);
    69         this->output(level::debug_output, context::undefined, std::vector<std::string>(1, "MemoryWriter disabled, further messages may be lost"));
     69        this->output(level::debug_output, context::undefined(), std::vector<std::string>(1, "MemoryWriter disabled, further messages may be lost"));
    7070    }
    7171}
  • code/branches/output/src/libraries/util/output/OutputDefinitions.h

    r8774 r8777  
    5858
    5959    typedef uint64_t OutputContext;
     60    typedef OutputContext (OutputContextFunction)();
    6061
    6162    extern _UtilExport OutputContext registerContext(const std::string& name);
     
    6566        static const OutputContext all       = 0xFFFFFFFFFFFFFFFF;
    6667        static const OutputContext none      = 0x0000000000000000;
    67         static const OutputContext undefined = registerContext("undefined");
    6868
    69         static const OutputContext test1     = registerContext("test1");
    70         static const OutputContext test2     = registerContext("test2");
    71         static const OutputContext output    = registerContext("output");
     69        namespace
     70        {
     71            OutputContext undefined()   { static OutputContext value = registerContext("undefined");    return value; }
     72
     73            OutputContext test1()       { static OutputContext value = registerContext("test1");        return value; }
     74            OutputContext test2()       { static OutputContext value = registerContext("test2");        return value; }
     75            OutputContext output()      { static OutputContext value = registerContext("output");       return value; }
     76        }
    7277    }
    7378}
  • code/branches/output/src/libraries/util/output/OutputManager.cc

    r8776 r8777  
    180180    const std::string& OutputManager::getContextName(OutputContext context) const
    181181    {
    182         if (context != context::undefined)
     182        if (context != context::undefined())
    183183        {
    184184            boost::bimap<OutputContext, std::string>::left_map::const_iterator it = this->contexts_.left.find(context);
     
    214214    {
    215215        std::string prefix = this->getLevelName(level) + ": ";
    216         if (context != context::undefined)
     216        if (context != context::undefined())
    217217        {
    218218            std::string context_name = this->getContextName(context);
  • code/branches/output/src/libraries/util/output/OutputStream.cc

    r8776 r8777  
    4848    }
    4949
    50     void OutputStream::setOutputAttributes(OutputLevel level, OutputContext context)
     50    void OutputStream::setOutputAttributes(OutputLevel level, OutputContextFunction context)
    5151    {
    5252        this->level_ = level;
    53         this->context_ = context;
     53        this->context_ = context();
    5454
    55         this->bAcceptsOutput_ = OutputManager::getInstanceAndCreateListeners().acceptsOutput(level, context);
     55        this->bAcceptsOutput_ = OutputManager::getInstanceAndCreateListeners().acceptsOutput(this->level_, this->context_);
    5656    }
    5757}
  • code/branches/output/src/libraries/util/output/OutputStream.h

    r8771 r8777  
    4747            _UtilExport OutputStream();
    4848
    49             void _UtilExport setOutputAttributes(OutputLevel level, OutputContext context);
     49            void _UtilExport setOutputAttributes(OutputLevel level, OutputContextFunction context);
    5050
    5151            template <class T>
Note: See TracChangeset for help on using the changeset viewer.