EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
EVEUtils.h File Reference
#include "EvilNumber.h"
#include "python/PyRep.h"
Include dependency graph for EVEUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool IsPrintable (const PyString *str)
 Checks whether string is printable. More...
 
bool IsPrintable (const PyWString *str)
 Checks whether string is printable. More...
 
bool DBTYPE_IsCompatible (DBTYPE type, const PyRep *rep)
 

Function Documentation

bool DBTYPE_IsCompatible ( DBTYPE  type,
const PyRep rep 
)

Checks compatibility between DBTYPE and PyRep.

Parameters
[in]typeDBTYPE to check.
[in]repPyRep to check.
Returns
True if arguments are compatible, false if not.

Definition at line 42 of file EVEUtils.cpp.

References CheckTypeRange, CheckTypeRangeUnsigned, DBTYPE_BOOL, DBTYPE_BYTES, DBTYPE_CY, DBTYPE_EMPTY, DBTYPE_ERROR, DBTYPE_FILETIME, DBTYPE_I1, DBTYPE_I2, DBTYPE_I4, DBTYPE_I8, DBTYPE_R4, DBTYPE_R8, DBTYPE_STR, DBTYPE_UI1, DBTYPE_UI2, DBTYPE_UI4, DBTYPE_UI8, DBTYPE_WSTR, PyRep::IsBool(), PyRep::IsBuffer(), PyRep::IsNone(), PyRep::IsWString(), and EVEAPI::CacheStyles::Long.

Referenced by DBRowDescriptor::VerifyValue().

43 {
44 // Helper macro, checks type and range
45 #define CheckTypeRangeUnsigned( type, lower_bound, upper_bound ) \
46  ( rep->Is##type() && (int64)rep->As##type()->value() >= lower_bound && (int64)rep->As##type()->value() <= upper_bound )
47 #define CheckTypeRange( type, lower_bound, upper_bound ) \
48  ( rep->Is##type() && rep->As##type()->value() >= lower_bound && rep->As##type()->value() <= upper_bound )
49 
50  if( rep->IsNone() )
51  // represents NULL
52  return true;
53 
54  return true;
55 
56  switch( type )
57  {
58  case DBTYPE_UI8:
59  case DBTYPE_CY:
60  case DBTYPE_FILETIME:
61  return ( CheckTypeRangeUnsigned( Int, 0LL, 0xFFFFFFFFFFFFFFFFLL )
62  || CheckTypeRangeUnsigned( Long, 0LL, 0xFFFFFFFFFFFFFFFFLL )
63  || CheckTypeRangeUnsigned( Float, 0LL, 0xFFFFFFFFFFFFFFFFLL ) );
64  case DBTYPE_UI4:
65  return ( CheckTypeRangeUnsigned( Int, 0L, 0xFFFFFFFFL )
66  || CheckTypeRangeUnsigned( Long, 0L, 0xFFFFFFFFL )
67  || CheckTypeRangeUnsigned( Float, 0L, 0xFFFFFFFFL ) );
68  case DBTYPE_UI2:
69  return ( CheckTypeRangeUnsigned( Int, 0, 0xFFFF )
70  || CheckTypeRangeUnsigned( Long, 0, 0xFFFF )
71  || CheckTypeRangeUnsigned( Float, 0, 0xFFFF ) );
72  case DBTYPE_UI1:
73  return ( CheckTypeRangeUnsigned( Int, 0, 0xFF )
74  || CheckTypeRangeUnsigned( Long, 0, 0xFF )
75  || CheckTypeRangeUnsigned( Float, 0, 0xFF ) );
76 
77  case DBTYPE_I8:
78  return ( CheckTypeRange( Int, -0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL )
79  || CheckTypeRange( Long, -0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL )
80  || CheckTypeRange( Float, -0x7FFFFFFFFFFFFFFFLL, 0x7FFFFFFFFFFFFFFFLL ) );
81  case DBTYPE_I4:
82  return ( CheckTypeRange( Int, -0x7FFFFFFFL, 0x7FFFFFFFL )
83  || CheckTypeRange( Long, -0x7FFFFFFFL, 0x7FFFFFFFL )
84  || CheckTypeRange( Float, -0x7FFFFFFFL, 0x7FFFFFFFL ) );
85  case DBTYPE_I2:
86  return ( CheckTypeRange( Int, -0x7FFF, 0x7FFF )
87  || CheckTypeRange( Long, -0x7FFF, 0x7FFF )
88  || CheckTypeRange( Float, -0x7FFF, 0x7FFF ) );
89  case DBTYPE_I1:
90  return ( CheckTypeRange( Int, -0x7F, 0x7F )
91  || CheckTypeRange( Long, -0x7F, 0x7F )
92  || CheckTypeRange( Float, -0x7F, 0x7F ) );
93 
94  case DBTYPE_R8:
95  return ( CheckTypeRange( Int, -DBL_MAX, DBL_MAX )
96  || CheckTypeRange( Long, -DBL_MAX, DBL_MAX )
97  || CheckTypeRange( Float, -DBL_MAX, DBL_MAX ) );
98  case DBTYPE_R4:
99  return ( CheckTypeRange( Int, -FLT_MAX, FLT_MAX )
100  || CheckTypeRange( Long, -FLT_MAX, FLT_MAX )
101  || CheckTypeRange( Float, -FLT_MAX, FLT_MAX ) );
102 
103  case DBTYPE_BOOL:
104  return rep->IsBool();
105 
106  case DBTYPE_BYTES:
107  return rep->IsBuffer();
108 
109  // this looks like a horrible hack, and it is - but one that is used on live!
110  // this works because STR type stuff is just tacked on to the marshal object
111  case DBTYPE_STR:
112  return true;
113  //return rep->IsString();
114 
115  case DBTYPE_WSTR:
116  return rep->IsWString();
117 
118  case DBTYPE_EMPTY:
119  case DBTYPE_ERROR:
120  return false;
121  }
122 
123  return false;
124 
125 #undef CheckTypeRange
126 #undef CheckTypeRangeUnsigned
127 }
bool IsBuffer() const
Definition: PyRep.h:104
#define CheckTypeRange(type, lower_bound, upper_bound)
bool IsNone() const
Definition: PyRep.h:111
bool IsBool() const
Definition: PyRep.h:103
#define CheckTypeRangeUnsigned(type, lower_bound, upper_bound)
bool IsWString() const
Definition: PyRep.h:106

Here is the call graph for this function:

Here is the caller graph for this function:

bool IsPrintable ( const PyString str)

Checks whether string is printable.

Parameters
[in]strString to be checked.
Return values
trueThe string is printable.
falseThe string is not printable.

Definition at line 31 of file EVEUtils.cpp.

References PyString::content(), and IsPrintable().

Referenced by build_hex_line(), XMLPacketGen::FNameToDef(), IsPrintable(), PyDumpVisitor::VisitString(), and PyDumpVisitor::VisitWString().

32 {
33  return IsPrintable( str->content() );
34 }
bool IsPrintable(const PyString *str)
Checks whether string is printable.
Definition: EVEUtils.cpp:31
const std::string & content() const
Get the PyString content.
Definition: PyRep.h:458

Here is the call graph for this function:

Here is the caller graph for this function:

bool IsPrintable ( const PyWString str)

Checks whether string is printable.

Parameters
[in]strString to be checked.
Return values
trueThe string is printable.
falseThe string is not printable.

Definition at line 36 of file EVEUtils.cpp.

References PyWString::content(), and IsPrintable().

37 {
38  // how to do it correctly?
39  return IsPrintable( str->content() );
40 }
const std::string & content() const
Get the PyWString content.
Definition: PyRep.h:499
bool IsPrintable(const PyString *str)
Checks whether string is printable.
Definition: EVEUtils.cpp:31

Here is the call graph for this function: