plain framework 1 參考手冊 入門指引之 代碼風格

代碼風格

介紹

框架自身採用了google的C++風格,做者也鼓勵在你的應用中使用此風格,有關此風格你能夠查閱相關資料瞭解。下面是一段plain framework中的代碼,以便你們參考:html

你能夠在此處下載到本項目使用的 風格指南:git

連接:http://pan.baidu.com/s/1bneYgI7 密碼:0ox1github

 

base/global.h服務器

/**
 * PLAIN FRAMEWORK ( https://github.com/viticm/plainframework )
 * $Id global.h
 * @link https://github.com/viticm/plainframework for the canonical source repository
 * @copyright Copyright (c) 2014- viticm( viticm.ti@gmail.com )
 * @license
 * @user viticm<viticm.ti@gmail.com>
 * @date 2014/07/28 15:57
 * @uses the base module for global defines
 */
#ifndef PF_BASE_GLOBAL_H_
#define PF_BASE_GLOBAL_H_

#include "pf/base/config.h"

namespace pf_base {

namespace global {

extern char net_modulename[FILENAME_MAX];
extern char script_modulename[FILENAME_MAX];
extern char performance_modulename[FILENAME_MAX];
extern char db_modulename[FILENAME_MAX];
extern char engine_modulename[FILENAME_MAX];
extern char applicationname[FILENAME_MAX]; //應用全局名稱
extern uint8_t applicationtype; //應用的類型 0 服務器 1 客戶端

PF_API const char *get_net_modulename();
PF_API const char *get_script_modulename();
PF_API const char *get_performanace_modulename();
PF_API const char *get_db_modulename();
PF_API const char *get_engine_modulename();
PF_API const char *get_applicationname();
PF_API void set_applicationname(const char *name);
PF_API uint8_t get_applicationtype();
PF_API void set_applicationtype(uint8_t type);

}; //namespace global

}; //namespace ps_base

#define NET_MODULENAME pf_base::global::get_net_modulename()
#define SCRIPT_MODULENAME pf_base::global::get_script_modulename()
#define PERFORMANCE_MODULENAME pf_base::global::get_performanace_modulename()
#define DB_MODULENAME pf_base::global::get_db_modulename()
#define ENGINE_MODULENAME pf_base::global::get_engine_modulename()
#define APPLICATION_NAME pf_base::global::get_applicationname()
#define APPLICATION_TYPE pf_base::global::get_applicationtype()

#endif //PF_BASE_GLOBAL_H_

base/global.cc網絡

#include "pf/base/string.h"
#include "pf/base/global.h"

namespace pf_base {

namespace global {

char net_modulename[FILENAME_MAX] = {0};
char script_modulename[FILENAME_MAX] = {0};
char performance_modulename[FILENAME_MAX] = {0};
char db_modulename[FILENAME_MAX] =  {0};
char engine_modulename[FILENAME_MAX] = {0};
char applicationname[FILENAME_MAX] = {0};
uint8_t applicationtype = 0;

const char *get_net_modulename() {
  __ENTER_FUNCTION
    if (strlen(net_modulename) > 0) return net_modulename;
    snprintf(net_modulename, 
             sizeof(net_modulename) - 1, 
             "net_%s", 
             APPLICATION_NAME);
    return net_modulename;
  __LEAVE_FUNCTION
    return NULL;
}

const char *get_script_modulename() {
  __ENTER_FUNCTION
    if (strlen(script_modulename) > 0) return script_modulename;
    snprintf(script_modulename, 
             sizeof(script_modulename) - 1, 
             "script_%s", 
             APPLICATION_NAME);
    return script_modulename;
  __LEAVE_FUNCTION
    return NULL;
}

const char *get_performanace_modulename() {
  __ENTER_FUNCTION
    if (strlen(performance_modulename) > 0) return performance_modulename;
    snprintf(performance_modulename, 
             sizeof(performance_modulename) - 1, 
             "performance_%s", 
             APPLICATION_NAME);
    return performance_modulename;
  __LEAVE_FUNCTION
    return NULL;
}

const char *get_db_modulename() {
  __ENTER_FUNCTION
    if (strlen(db_modulename) > 0) return db_modulename;
    snprintf(db_modulename, 
             sizeof(db_modulename) - 1, 
             "db_%s", 
             APPLICATION_NAME);
    return db_modulename;
  __LEAVE_FUNCTION
    return NULL;
}

const char *get_engine_modulename() {
  __ENTER_FUNCTION
    if (strlen(engine_modulename) > 0) return engine_modulename;
    snprintf(engine_modulename, 
             sizeof(engine_modulename) - 1, 
             "engine_%s", 
             APPLICATION_NAME);
    return engine_modulename;
  __LEAVE_FUNCTION
    return NULL;
}

const char *get_applicationname() {
  __ENTER_FUNCTION
    if (0 == strlen(applicationname)) {
      snprintf(applicationname,
               sizeof(applicationname) - 1,
               "%s",
               "unknown");
    }
    return applicationname;
  __LEAVE_FUNCTION
    return NULL;
}

void set_applicationname(const char *name) {
  string::safecopy(applicationname, name, sizeof(applicationname));  
}

uint8_t get_applicationtype() {
  return applicationtype;
}

void set_applicationtype(uint8_t type) {
  applicationtype = type;
}

}; //namespace global

} //namespace pf_base

模塊 | 協議app

 成員招募(長期有效)

  若是你也對開源知識比較感興趣,若是也對網絡應用或者網絡遊戲感興趣,若是你也對該框架感興趣,你能夠加入咱們的QQ羣(348477824)。框架

  歡迎你們進羣相互交流學習,同時也歡迎各位朋友對該框架供出本身的一份心力。學習

相關文章
相關標籤/搜索