plain framework 1 参考手册 入门指引之 代码风格

代码风格

介绍

框架自身采用了google的C++风格,作者也鼓励在你的应用中使用此风格,有关此风格你可以查阅相关资料了解。下面是一段plain framework中的代码,以便大家参考:

你可以在此处下载到本项目使用的 风格指南:

链接:http://pan.baidu.com/s/1bneYgI7 密码:0ox1

 

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( [email protected] )

 * @license

 * @user viticm<[email protected]>

 * @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

模块 | 协议

 成员招募(长期有效)

  如果你也对开源知识比较感兴趣,如果也对网络应用或者网络游戏感兴趣,如果你也对该框架感兴趣,你可以加入我们的QQ群(348477824)。

  欢迎大家进群相互交流学习,同时也欢迎各位朋友对该框架供出自己的一份心力。

你可能感兴趣的:(framework)