[mathicgb] 186/393: Added support for prefixes and suffices on log aliases. Added the log aliases none, all and SPairs. Made the default log none, while empty string is replaced with all, so that doing "-log" turns on all logs.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:58:57 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.

commit 71fa758c46211881e733fe8509b747692562d3ab
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Thu Mar 7 15:40:20 2013 +0100

    Added support for prefixes and suffices on log aliases. Added the log aliases none, all and SPairs. Made the default log none, while empty string is replaced with all, so that doing "-log" turns on all logs.
---
 src/cli/CommonParams.cpp      | 11 ++++--
 src/cli/HelpAction.cpp        | 22 +++++++++--
 src/mathicgb/F4Reducer.cpp    |  3 +-
 src/mathicgb/LogDomainSet.cpp | 89 +++++++++++++++++++++++++++++--------------
 src/mathicgb/LogDomainSet.hpp | 24 +++++++++---
 src/mathicgb/SPairs.cpp       |  5 +++
 6 files changed, 111 insertions(+), 43 deletions(-)

diff --git a/src/cli/CommonParams.cpp b/src/cli/CommonParams.cpp
index f370a73..841bb6e 100644
--- a/src/cli/CommonParams.cpp
+++ b/src/cli/CommonParams.cpp
@@ -16,9 +16,11 @@ CommonParams::CommonParams(size_t minDirectParams, size_t maxDirectParams):
     1),
 
   mLogs("log",
-    "Enable the specified log. Do \"help logs\" to see all available logs. "
-    "To enable logs X, Y and Z, do \"-log X,Y,Z\".",
-    ""),
+    "Enable the specified log. Do \"help logs\" to see all available logs and "
+    "the details of how to configure what kind of logging you want. "
+    "To enable logs X, Y and Z, do \"-log X,Y,Z\". "
+    "To enabled all logs, do \"-log\" or \"-log all\".",
+    "none"),
 
   mMinDirectParams(minDirectParams),
   mMaxDirectParams(maxDirectParams)
@@ -45,7 +47,8 @@ void CommonParams::pushBackParameters(
 }
 
 void CommonParams::perform() {
-  LogDomainSet::singleton().performLogCommands(mLogs.value());
+  const std::string logs = mLogs.value().empty() ? "all" : mLogs.value();
+  LogDomainSet::singleton().performLogCommands(logs);
   tracingLevel = mTracingLevel.value();
 
   // delete the old init object first to make the new one take control.
diff --git a/src/cli/HelpAction.cpp b/src/cli/HelpAction.cpp
index c02a04d..6dd4590 100755
--- a/src/cli/HelpAction.cpp
+++ b/src/cli/HelpAction.cpp
@@ -39,7 +39,8 @@ void HelpAction::performAction() {
     "\n"
     "A prefix of - disables the log while no prefix or a prefix of + enables "
     "it. A suffix of - turns off streaming while a suffix of + turns it on. "
-    "If there is no suffix then the setting for streaming is unchanged.\n"
+    "If there is no suffix then the setting for streaming is unchanged. A "
+    "prefix or suffix of 0 means do nothing.\n"
     "\n"
     "The following is a list of all compile-time enabled logs. The prefixes "
     "and suffixes indicate the default state of the log.\n";
@@ -58,9 +59,22 @@ void HelpAction::performAction() {
 
   const char* aliasDescription =
     "\nA log alias is a short-hand where one name stands for several log "
-    "specifications. The following is a list of all aliases.\n";
+    "specifications. Prefixes and Suffixes also apply to aliases. If X "
+    "expands to A+,-B,C then +X- expands to +A-,+B-,+C-. 0all- turns off "
+    "all streaming output without enabling or disabling any logs.\n"
+    "\n"
+    "The following is a list of all aliases.\n";
   mathic::display(aliasDescription);
   auto& aliases = LogDomainSet::singleton().aliases();
-  for (auto it = aliases.begin(); it != aliases.end(); ++it)
-    std::cerr << "\n " << it->first << "\n   " << it->second << "\n\n";
+  for (auto it = aliases.begin(); it != aliases.end(); ++it) {
+    std::cerr << "\n " << it->first << " expands to\n";
+    std::string str = it->second;
+    std::replace(str.begin(), str.end(), ',', ' ');
+    mathic::display(str, "   ");
+  }
+  std::cerr <<
+    "\n none expands to nothing\n"
+    "\n"
+    " all expands to all log names\n";
+    "\n";
 }
diff --git a/src/mathicgb/F4Reducer.cpp b/src/mathicgb/F4Reducer.cpp
index cc2f0df..6be1f39 100755
--- a/src/mathicgb/F4Reducer.cpp
+++ b/src/mathicgb/F4Reducer.cpp
@@ -31,7 +31,8 @@ MATHICGB_DEFINE_LOG_DOMAIN(
 
 MATHICGB_DEFINE_LOG_ALIAS(
   "F4",
-  "F4MatrixEntries-,F4MatrixBottomRows-,F4MatrixTopRows-" ",F4MatrixRows-,F4MatrixBuild+,F4MatrixBuild2+,F4MatrixReduce+"
+  "F4MatrixEntries,F4MatrixBottomRows,F4MatrixTopRows,F4MatrixRows,"
+  "F4MatrixBuild,F4MatrixBuild2,F4MatrixReduce"
 );
 
 F4Reducer::F4Reducer(const PolyRing& ring, Type type):
diff --git a/src/mathicgb/LogDomainSet.cpp b/src/mathicgb/LogDomainSet.cpp
index a902e55..f537d89 100644
--- a/src/mathicgb/LogDomainSet.cpp
+++ b/src/mathicgb/LogDomainSet.cpp
@@ -8,6 +8,8 @@ LogDomainSet::LogDomainSet():
 }
 
 void LogDomainSet::registerLogDomain(LogDomain<true>& domain) {
+  MATHICGB_ASSERT(std::strcmp(domain.name(), "none") != 0);
+  MATHICGB_ASSERT(std::strcmp(domain.name(), "all") != 0);
   mLogDomains.push_back(&domain);
 }
 
@@ -32,53 +34,82 @@ void LogDomainSet::registerLogAlias(const char* alias, const char* of) {
   mAliases.push_back(std::make_pair(alias, of));
 }
 
-void LogDomainSet::performLogCommand(std::string cmd) {
+void LogDomainSet::performLogCommandsInternal(
+  const char prefix,
+  const std::string& cmds,
+  const char suffix
+) {
+  size_t offset = 0;
+  while (offset < cmds.size()) {
+    const size_t next = cmds.find(',', offset);
+    performLogCommandInternal
+      (prefix, cmds.substr(offset, next - offset), suffix);
+    offset = next;
+    if (offset < cmds.size()) {
+      MATHICGB_ASSERT(cmds[offset] == ',');
+      ++offset;
+    }
+  }
+}
+
+void LogDomainSet::performLogCommandInternal(
+  char prefix,
+  std::string cmd,
+  char suffix
+) {
+  const auto isSign =
+    [](const char c) {return c == '+' || c == '-' || c == '0';};
+  MATHICGB_ASSERT(prefix == ' ' || isSign(prefix));
+  MATHICGB_ASSERT(suffix == ' ' || isSign(suffix));
+
   if (cmd.empty())
     return;
-
+
   // This could be more efficient, but this is not supposed to be a
   // method that is called very often.
-  const auto isSign = [](const char c) {return c == '+' || c == '-';};
-  char prefix = ' ';
+
   if (isSign(cmd.front())) {
-    prefix = cmd.front();
+    if (prefix == ' ')
+      prefix = cmd.front();
     cmd.erase(cmd.begin());
   }
 
-  char suffix = ' ';
   if (!cmd.empty() && isSign(cmd.back())) {
-    suffix = cmd.back();
+    if (suffix == ' ')
+      suffix = cmd.back();
     cmd.erase(cmd.end() - 1);
   }
 
-  auto log = logDomain(cmd.c_str());
-  if (log != 0) {
-    log->setEnabled(prefix != '-');
-    if (suffix != ' ')
-      log->setStreamEnabled(suffix == '+');
+  if (cmd == "none")
     return;
-  }
 
-  auto aliasOf = this->alias(cmd.c_str());
+  if (cmd == "all") {
+    for (auto it = mLogDomains.begin(); it != mLogDomains.end(); ++it)
+      performLogCommandInternal(prefix, (*it)->name(), suffix);
+    return;
+  }
+
+  auto aliasOf = alias(cmd.c_str());
   if (aliasOf != 0) {
-    performLogCommands(aliasOf);
+    performLogCommandsInternal(prefix, aliasOf, suffix);
     return;
   }
-
-  mathic::reportError("Unknown log \"" + cmd + "\".\n");
-}
-
-void LogDomainSet::performLogCommands(const std::string& cmds) {
-  size_t offset = 0;
-  while (offset < cmds.size()) {
-    const size_t next = cmds.find(',', offset);
-    performLogCommand(cmds.substr(offset, next - offset));
-    offset = next;
-    if (offset < cmds.size()) {
-      MATHICGB_ASSERT(cmds[offset] == ',');
-      ++offset;
-    }
+
+  // The default modifiers are +X0.
+  if (prefix == ' ')
+    prefix = '+';
+  if (suffix == ' ')
+    suffix = '0';
+  auto log = logDomain(cmd.c_str());
+  if (log != 0) {
+    if (prefix != '0')
+      log->setEnabled(prefix != '-');
+    if (suffix != '0')
+      log->setStreamEnabled(suffix == '+');
+    return;
   }
+
+  mathic::reportError("Unknown log \"" + cmd + "\".\n");
 }
 
 void LogDomainSet::printReport(std::ostream& out) const {
diff --git a/src/mathicgb/LogDomainSet.hpp b/src/mathicgb/LogDomainSet.hpp
index 70c799e..4edf81c 100755
--- a/src/mathicgb/LogDomainSet.hpp
+++ b/src/mathicgb/LogDomainSet.hpp
@@ -21,13 +21,15 @@ public:
   ///   A       a prefix
   ///   B       a suffix
   /// The possible values of A are
-  ///           enabled X (this is the empty string)
-  ///   +       enabled X
+  ///           enable X (this is the empty string)
+  ///   +       enable X
   ///   -       disable X
+  ///   0       do nothing
   /// The possible values of B are
-  ///           leaving sub-state as-is (this is the empty string)
+  ///           do nothing (this is the empty string)
   ///   +       stream-enabled X
   ///   -       stream-disable X
+  ///   0       do nothing
   ///
   /// No white-space is allowed.
   /// If the command cannot be parsed then you will get an exception.
@@ -41,10 +43,12 @@ public:
   ///   "+MyLog" will enabled MyLog. Since the streaming state was enabled
   ///     before, we now get streaming.
   ///
-  void performLogCommand(std::string cmd);
+  void performLogCommand(std::string cmd)
+    {performLogCommandInternal(' ', std::move(cmd), ' ');}
 
   /// Performs a comma-seperated list of commands. No white-space is allowed.
-  void performLogCommands(const std::string& cmds);
+  void performLogCommands(const std::string& cmds)
+    {performLogCommandsInternal(' ', cmds, ' ');}
 
   LogDomain<true>* logDomain(const char* const name);
 
@@ -61,6 +65,16 @@ public:
   static LogDomainSet& singleton();
 
 private:
+  void performLogCommandInternal(
+    char prefix,
+    std::string name,
+    char suffix
+  );
+  void performLogCommandsInternal(
+    const char prefix,
+    const std::string& cmds,
+    const char suffix
+  );
   LogDomainSet(); // private for singleton
 
   std::vector<LogDomain<true>*> mLogDomains;
diff --git a/src/mathicgb/SPairs.cpp b/src/mathicgb/SPairs.cpp
index 63f0397..8fcb483 100755
--- a/src/mathicgb/SPairs.cpp
+++ b/src/mathicgb/SPairs.cpp
@@ -17,6 +17,11 @@ MATHICGB_DEFINE_LOG_DOMAIN_WITH_DEFAULTS(
   0, 0, 1
 );
 
+MATHICGB_DEFINE_LOG_ALIAS(
+  "SPairs",
+  "SPairEarly,SPairLate"
+);
+
 SPairs::SPairs(const PolyBasis& basis, bool preferSparseSPairs):
   mQueue(QueueConfiguration(basis, preferSparseSPairs)),
   mBasis(basis),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git



More information about the debian-science-commits mailing list