Files
SingularityViewer/indra/llcommon/aialert.cpp
Aleric Inglewood 193010e947 Add THROW_[MF]ALERT[EC] (AIArgs, AIAlert, AIAlertCode, AIAlertPrefix, AIAlertLine)
A system to throw errors that allow for easy error reporting to the user
by showing a translated pop-up alert box with the error message.

The messages use strings.xml for translation and allow the usual
replacement args (ie [FILE] is replaced with a filename).

The exceptions can be cascaded, by adding more (translated) text
when caught and then re-throwing the result.

Macros are being used to support adding a function name prefix
to a message of the current function that the exception is thrown
from.

The syntax is:

  <macro>(<line>);		to show 'line'
  <macro>(<alert>, <line>);	to append 'line' to a caught alert.
  <macro>(<line>, <alert>);	to prepend 'line' to a caught alert.

  where <macro> is one of:
  THROW_ALERT, THROW_MALERT, THROW_FALERT, THROW_FMALERT,
  THROW_ALERTE, THROW_MALERTE, THROW_FALERTE, THROW_FMALERTE, where
  M = modal, F = Function name.
  and where <line> is one of:

  <xmldesc>
  <xmldesc>, AIArgs<args>

  where <xmldesc> is a string literal that will be looked up
  in strings.xml, and <args> is:

  (<key>, <replacement>)[<args>]

  There are more variations of the macros to throw an arbitrary
  class (append _CLASS), include an int code (append C) or
  to store the current errno as code (append E).

  For example, THROW_MALERTC(code, ...), or THROW_FALERT_CLASS(Foobar, ...),
  where the ... is the same as for the macros above.

Documentation and example usage has been added to aialert.h.
2013-11-05 03:01:47 +01:00

68 lines
2.5 KiB
C++

/**
* @file aialert.cpp
*
* Copyright (c) 2013, Aleric Inglewood.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution.
*
* CHANGELOG
* and additional copyright holders.
*
* 02/11/2013
* - Initial version, written by Aleric Inglewood @ SL
*/
#include "aialert.h"
AIAlert::AIAlert(AIAlertPrefix const& prefix, modal_nt type,
std::string const& xml_desc, AIArgs const& args) : mModal(type)
{
if (prefix) mLines.push_back(AIAlertLine(prefix));
mLines.push_back(AIAlertLine(xml_desc, args));
}
AIAlert::AIAlert(AIAlertPrefix const& prefix, modal_nt type,
AIAlert const& alert,
std::string const& xml_desc, AIArgs const& args) : mLines(alert.mLines), mModal(type)
{
if (alert.mModal == modal) mModal = modal;
if (prefix) mLines.push_back(AIAlertLine(prefix, !mLines.empty()));
mLines.push_back(AIAlertLine(xml_desc, args));
}
AIAlert::AIAlert(AIAlertPrefix const& prefix, modal_nt type,
std::string const& xml_desc,
AIAlert const& alert) : mLines(alert.mLines), mModal(type)
{
if (alert.mModal == modal) mModal = modal;
if (!mLines.empty()) { mLines.front().set_newline(); }
mLines.push_front(AIAlertLine(xml_desc));
if (prefix) mLines.push_front(AIAlertLine(prefix));
}
AIAlert::AIAlert(AIAlertPrefix const& prefix, modal_nt type,
std::string const& xml_desc, AIArgs const& args,
AIAlert const& alert) : mLines(alert.mLines), mModal(type)
{
if (alert.mModal == modal) mModal = modal;
if (!mLines.empty()) { mLines.front().set_newline(); }
mLines.push_front(AIAlertLine(xml_desc, args));
if (prefix) mLines.push_front(AIAlertLine(prefix));
}