ps-lite源码分析: include/ps/internal/utils.h

/**
* Copyright (c) 2015 by Contributors
*/
#ifndef PS_INTERNAL_UTILS_H_
#define PS_INTERNAL_UTILS_H_
#include "dmlc/logging.h"
#include "ps/internal/env.h"
namespace ps {
/** 如果使用了微软C编译器(不支持C99标准类型),则使用其支持类型,否则使用C99标准库跨平台类型 */
#ifdef _MSC_VER
typedef signed char int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned char uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else
#include
#endif

/** 获取环境变量值(整型),如果不存在使用默认值 */
/*
* Get environment variable as int with default.
* key: the name of environment variable.
* default_val: the default value of environment vriable.
* return The value received
*/
template
inline V GetEnv(const char *key, V default_val) {
const char *val = Environment::Get()->find(key);
if (val == nullptr) {
return default_val;
} else {
return V(val);
}
}

inline int GetEnv(const char *key, int default_val) {
const char *val = Environment::Get()->find(key);
if (val == nullptr) {
return default_val;
} else {
return atoi(val);
}
}

/** 禁止类型支持拷贝与赋值的宏 */
#ifndef DISALLOW_COPY_AND_ASSIGN
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName(const TypeName&);
void operator=(const TypeName&)
#endif

/** LOG错误的简易宏 */
#define LL LOG(ERROR)

} // namespace ps
#endif // PS_INTERNAL_UTILS_H_

你可能感兴趣的:(ps-lite源码分析: include/ps/internal/utils.h)