Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Functions | Variables
ErrorCode.cpp File Reference

implements of error code function More...

#include "stdafx.h"
#include "ErrorCode.h"
#include "CoreMacros.h"
#include <string>
#include <vector>
Include dependency graph for ErrorCode.cpp:

Go to the source code of this file.

Functions

unsigned int errorcode (const char *errorName)
 get new error code More...
 
const char * errorstring (unsigned int errorCode)
 get error string for an existing error More...
 
void errorcleanup (void)
 deallocate error strings object
 

Variables

std::vector< std::pair
< std::string, unsigned int > > * 
pErrorList
 

Detailed Description

implements of error code function

Author
S.Tanaka
Date
2006.08.18

Copyright(C) 2006-2014 Eisai Co., Ltd. All rights reserved.

Definition in file ErrorCode.cpp.

Function Documentation

int errorcode ( const char *  errorName)

get new error code

Parameters
errorNameerror name
Returns
error code

Definition at line 23 of file ErrorCode.cpp.

23  {
24  // static variable
25  static unsigned int maxErrorCode = 0;
26 
27  // create string object
28  std::string s = std::string( NVL( errorName, "" ) );
29 
30  // get error code
31  unsigned code = maxErrorCode;
32 
33  unsigned errorIndex = -1;
34 
35  if (pErrorList == NULL)
36  {
37  pErrorList = new std::vector<std::pair<std::string, unsigned int>>;
38  }
39 
40  for (int i = 0; (i < static_cast<int>(pErrorList->size())) && (errorIndex == -1); i++)
41  {
42  if ((*pErrorList)[i].first.compare(errorName) == 0)
43  {
44  errorIndex = i;
45  }
46  }
47 
48  if( errorIndex == -1 ) { // new error code
49  pErrorList->push_back(std::pair<std::string, unsigned int>(errorName, code));
50  maxErrorCode++;
51  }
52  else { // already exists
53  code = (*pErrorList)[errorIndex].second;
54  }
55 
56  return code;
57 }
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
#define NULL
Definition: CoreMacros.h:18
const char * errorstring ( unsigned int  errorCode)

get error string for an existing error

Parameters
errorCodeerror code
Returns
error string

Definition at line 60 of file ErrorCode.cpp.

60  {
61 
62  unsigned errorIndex = -1;
63 
64  // get error string
65  for (int i = 0; (i < static_cast<int>(pErrorList->size())) && (errorIndex == -1); i++)
66  {
67  if ((*pErrorList)[i].second == errorCode)
68  {
69  errorIndex = i;
70  }
71  }
72 
73  if (errorIndex != -1)
74  {
75  return (*pErrorList)[errorIndex].first.c_str();
76  }
77  else
78  {
79  return "";
80  }
81 }