BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RangeIssue.cxx
Go to the documentation of this file.
1/*
2 * RangeIssue.cxx
3 * ers
4 *
5 * Created by Matthias Wiesmann on 15.02.05.
6 * Copyright 2005 CERN. All rights reserved.
7 *
8 */
9
10#include "ers/RangeIssue.h"
11#include <sstream>
12
13const char* const ers::RangeIssue::CLASS_NAME = "ers::RangeIssue";
14const char* const ers::RangeIssue::INDEX_REFERENCE_TYPE = "scalar";
15const char* const ers::RangeIssue::RANGE_MIN_KEY = "REFERENCE_RANGE_MIN";
16const char* const ers::RangeIssue::RANGE_MAX_KEY = "REFERENCE_RANGE_MAX";
17
18namespace {
19 ers::Issue* create_issue() { return new ers::RangeIssue(); }
21 create_issue );
22} // namespace
23
24void ers::RangeIssue::check_range( const ers::Context& c, int64_t min, int64_t value,
25 int64_t max, const char* entity_name ) {
26 if ( ( value > max ) || ( value < min ) )
27 throw RangeIssue( c, ers::error, min, value, max, entity_name );
28} // check_range
29
30void ers::RangeIssue::set_range( ers::Issue& issue, int64_t index, int64_t min_index,
31 int64_t max_index, const char* entity_name ) {
32 issue.set_value( REFERENCE_VALUE_KEY, index );
33 issue.set_value( RANGE_MIN_KEY, min_index );
34 issue.set_value( RANGE_MAX_KEY, max_index );
35 std::ostringstream reference_stream;
36 reference_stream << INDEX_REFERENCE_TYPE;
37 if ( entity_name ) { reference_stream << "(name=" << entity_name << ')'; }
38 issue.set_value( REFERENCE_TYPE_KEY, reference_stream.str() );
39} // set_range
40
42
47
49 int64_t index, int64_t max_index, const char* entity_name )
50 : ers::InvalidReferenceIssue( c, s ) {
51 set_range( *this, index, min_index, max_index, entity_name );
52 std::ostringstream message_stream;
53 message_stream << "invalid index: ";
54 if ( entity_name ) { message_stream << entity_name << '='; } // entity
55 message_stream << index << " is not in range " << min_index << '-' << max_index;
56 finish_setup( message_stream.str() );
57} // RangeIssue
58
59const char* ers::RangeIssue::get_class_name() const throw() { return CLASS_NAME; }
#define min(a, b)
#define max(a, b)
XmlRpcServer s
Source context for Issue.
InvalidReferenceIssue(const Context &context, severity_t s)
bool register_issue(const std::string &name, CreateIssueCallback creator)
register an issue factory
static IssueFactory * instance()
method to access singleton
Root Issue class.
void set_value(const std::string &key, uint8_t value)
Sets a value 8 bit unsigned.
void finish_setup(const std::string &message)
Finishes the setup of the Issue.
static const char *const INDEX_REFERENCE_TYPE
static const char *const RANGE_MAX_KEY
static const char *const RANGE_MIN_KEY
static void set_range(ers::Issue &issue, int64_t index, int64_t min_index, int64_t max_index, const char *entity_name=0)
static const char *const CLASS_NAME
virtual const char * get_class_name() const
Get key for class (used for serialisation).
static void check_range(const ers::Context &c, int64_t min, int64_t value, int64_t max, const char *entity_name=0)
enum ers::_severity_t severity_t