repo_name
stringlengths 5
122
| path
stringlengths 3
232
| text
stringlengths 6
1.05M
|
|---|---|---|
jonrood/simulations
|
smoke/viewer.h
|
#ifndef _VIEWER_H
#define _VIEWER_H
#include <stdlib.h>
#include <vector>
#include "vec3.hpp"
class Fluid;
class Viewer
{
private:
int _sx, _sy; // screen width and height
int _ax, _ay; // mouse movement anchor
float _quat[4]; // view rotation quaternion
float _lquat[4]; // light orientation quaternion (bit of a hack...)
float _dist; // viewer distance to origin
int _N; // data resolution
int _nframes; // number of frames in data file
int _cur_frame;
unsigned char* _texture_data;
unsigned int _txt[3]; // texture handles
unsigned int _prog[2]; // program handles
unsigned int _font_base; // first display list for font
double _persp_m[16], _ortho_m[16]; // projection matrices
float _light_dir[3];
int _ray_templ[4096][3];
void draw_cube(void);
// draw the slices. m must be the current rotation matrix.
// if frame==true, the outline of the slices will be drawn as well
void draw_slices(float m[][4], bool frame);
// intersect a plane with the cube, helper function for draw_slices()
std::vector<Vec3> intersect_edges(float a, float b, float c, float d);
void gen_ray_templ(int edgelen);
void cast_light(int edgelen, float* dens, unsigned char* intensity);
inline void light_ray(int x, int y, int z, int n, float decay, float* dens, unsigned char* intensity);
void init_GL(void);
public:
Viewer();
~Viewer();
bool _draw_cube, _draw_slice_outline;
void viewport(int w, int h); // adjust viewport
void anchor(int x, int y); // store given coordinates as transformation anchor
void rotate(int x, int y); // rotate according to given coordinates (trackball)
void rotate_light(int x, int y); // set light orientation according to given coordinates (trackball)
void dolly(int y);
void frame_from_sim(Fluid* fluid); // generate data from simulation
void draw(void); // draw the volume
};
#endif
|
jonrood/simulations
|
smoke64/viewer.h
|
#ifndef _VIEWER_H
#define _VIEWER_H
#include <stdlib.h>
#include <vector>
#include "vec3.hpp"
class Fluid; // forward definition
class Viewer
{
private:
int _sx, _sy; // screen width and height
int _ax, _ay; // mouse movement anchor
float _quat[4]; // view rotation quaternion
float _lquat[4]; // light orientation quaternion (bit of a hack...)
float _dist; // viewer distance to origin
FILE* _fp; // data file
int _N; // data resolution
int _nframes; // number of frames in data file
int _cur_frame;
// OpenGL variables
unsigned char* _texture_data;
unsigned int _txt[3]; // texture handles
unsigned int _prog[2]; // program handles
unsigned int _font_base; // first display list for font
double _persp_m[16], _ortho_m[16]; // projection matrices
float _light_dir[3];
int _ray_templ[4096][3];
// draw the outline of the cube
void draw_cube(void);
// draw the slices. m must be the current rotation matrix.
// if frame==true, the outline of the slices will be drawn as well
void draw_slices(float m[][4], bool frame);
// intersect a plane with the cube, helper function for draw_slices()
std::vector<Vec3> intersect_edges(float a, float b, float c, float d);
void gen_ray_templ(int edgelen);
void cast_light(int edgelen, float* dens, unsigned char* intensity);
inline void light_ray(int x, int y, int z, int n, float decay, float* dens, unsigned char* intensity);
void print_string(char* s);
void init_GL(void);
bool init_font(void);
public:
Viewer();
~Viewer();
bool _draw_cube, _draw_slice_outline;
char* _dispstring;
void viewport(int w, int h); // adjust viewport
void anchor(int x, int y); // store given coordinates as transformation anchor
void rotate(int x, int y); // rotate according to given coordinates (trackball)
void rotate_light(int x, int y); // set light orientation according to given coordinates (trackball)
void dolly(int y);
bool open(char* filename);
void load_frame(); // load one frame from data file
void frame_from_sim(Fluid* fluid); // generate data from simulation
void draw(void); // draw the volume
};
#endif
|
jonrood/simulations
|
smoke64/genfunc.h
|
#ifndef _GENFUNC_H
#define _GENFUNC_H
extern float* genparams;
float* randfloats(int n);
float genfunc(int x, int y, int sx, int sy, float t, float* p);
#endif
|
caoliver/tft
|
cpiofns.c
|
<filename>cpiofns.c<gh_stars>0
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <limits.h>
#include <err.h>
#include "lua_head.h"
// Process files in 16MB clumps.
#define FILE_CLUMP (16 * 1024 * 1024)
typedef unsigned int UINT;
/*
* Original work by <NAME>
*
* External file lists, symlink, pipe and fifo support by <NAME>
* Hard link support by <NAME>
*/
static unsigned int offset;
static unsigned int ino = 721;
static luaL_Buffer outbuf;
struct file_handler {
const char *type;
int (*handler)(const char *line);
};
static void emit_pad (void)
{
while (offset & 3) {
luaL_addchar(&outbuf, 0);
offset++;
}
}
static void emit_rest(const char *name)
{
unsigned int name_len = strlen(name) + 1;
unsigned int tmp_ofs;
luaL_addstring(&outbuf, name);
luaL_addchar(&outbuf, 0);
offset += name_len;
tmp_ofs = name_len + 110;
while (tmp_ofs & 3) {
luaL_addchar(&outbuf, 0);
offset++;
tmp_ofs++;
}
}
static void emit_hdr(const char *s)
{
luaL_addstring(&outbuf, s);
offset += 110;
}
LUAFN(emit_trailer)
{
char s[256];
const char name[] = "TRAILER!!!";
luaL_buffinit(L, &outbuf);
sprintf(s, "%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
0, /* ino */
0, /* mode */
(long) 0, /* uid */
(long) 0, /* gid */
1, /* nlink */
(long) 0, /* mtime */
0, /* filesize */
0, /* major */
0, /* minor */
0, /* rmajor */
0, /* rminor */
(unsigned)strlen(name)+1, /* namesize */
0); /* chksum */
emit_hdr(s);
emit_rest(name);
while (offset % 512) {
luaL_addchar(&outbuf, 0);
offset++;
}
luaL_pushresult(&outbuf);
return 1;
}
LUAFN(emit_directory)
{
const char *name = luaL_checkstring(L, 1);
char s[256];
luaL_buffinit(L, &outbuf);
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
"%08X%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino++, /* ino */
0700 | S_IFDIR, /* mode */
(long) 0, /* uid */
(long) 0, /* gid */
2, /* nlink */
(long) time(NULL), /* mtime */
0, /* filesize */
3, /* major */
1, /* minor */
0, /* rmajor */
0, /* rminor */
(UINT)strlen(name) + 1, /* namesize */
0); /* chksum */
emit_hdr(s);
emit_rest(name);
luaL_pushresult(&outbuf);
return 1;
}
LUAFN(emit_file)
{
const char *name = luaL_checkstring(L, 1);
const char *data = luaL_checkstring(L, 2);
char s[256];
size_t size = lua_objlen(L, 2);
luaL_buffinit(L, &outbuf);
if (name[0] == '/')
name++;
sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX"
"%08lX%08X%08X%08X%08X%08X%08X",
"070701", /* magic */
ino, /* ino */
0600 | S_IFREG, /* mode */
(long) 0, /* uid */
(long) 0, /* gid */
1, /* nlink */
(long) time(NULL), /* mtime */
size, /* filesize */
3, /* major */
1, /* minor */
0, /* rmajor */
0, /* rminor */
(UINT)strlen(name)+1, /* namesize */
0); /* chksum */
emit_hdr(s);
luaL_addstring(&outbuf, name);
luaL_addchar(&outbuf, 0);
offset += strlen(name) + 1;
emit_pad();
offset += size;
luaL_addlstring(&outbuf, data, size);
emit_pad();
ino++;
luaL_pushresult(&outbuf);
return 1;
}
LUALIB_API int luaopen_cpiofns(lua_State *L)
{
static const luaL_Reg funcptrs[] = {
FN_ENTRY(emit_directory),
FN_ENTRY(emit_file),
FN_ENTRY(emit_trailer),
{ NULL, NULL }
};
luaL_register(L, "cpiofns", funcptrs);
return 1;
};
|
caoliver/tft
|
ljcurses.c
|
<filename>ljcurses.c
#include "lua_head.h"
#include <ncurses.h>
#include <ctype.h>
#include <termios.h>
#include <unistd.h>
// Milliseconds
#define ESC_DELAY 50
static WINDOW *curwin;
static int curtimeout;
static int which_window(lua_State *L, WINDOW **w)
{
if (lua_islightuserdata(L, 1)) {
*w = (WINDOW *)lua_topointer(L, 1);
return 1;
}
if (!lua_isnone(L,1) && lua_isnil(L, 1)) {
*w = stdscr;
return 1;
}
*w = curwin;
return 0;
}
LUAFN(init_curses)
{
initscr();
set_escdelay(ESC_DELAY);
curwin = stdscr;
noecho();
raw();
keypad(stdscr,TRUE);
lua_getglobal(L, "ljcurses");
lua_getfield(L, -1, "boxes");
// These aren't constants at compile time. :-(
AT_NAME_PUT_INT(vline, ACS_VLINE);
AT_NAME_PUT_INT(hline, ACS_HLINE);
AT_NAME_PUT_INT(urcorner, ACS_URCORNER);
AT_NAME_PUT_INT(ulcorner, ACS_ULCORNER);
AT_NAME_PUT_INT(lrcorner, ACS_LRCORNER);
AT_NAME_PUT_INT(llcorner, ACS_LLCORNER);
AT_NAME_PUT_INT(ltee, ACS_LTEE);
AT_NAME_PUT_INT(rtee, ACS_RTEE);
AT_NAME_PUT_INT(ttee, ACS_TTEE);
AT_NAME_PUT_INT(btee, ACS_BTEE);
AT_NAME_PUT_INT(plus, ACS_PLUS);
AT_NAME_PUT_INT(diamond, ACS_DIAMOND);
return 0;
}
LUAFN(endwin)
{
endwin();
return 0;
}
LUAFN(getch)
{
int key;
int escape_seen = 0;
char escape_sequence[32];
int sequence_end = 0;
for (;;) {
key=getch();
if (key < 0 && escape_seen) {
key = 27;
goto done;
}
if (!escape_seen) {
if (key != 27)
goto done;
escape_seen=1;
timeout(ESC_DELAY);
} else if (sequence_end < sizeof(escape_sequence))
escape_sequence[sequence_end++] = key;
}
done:
timeout(curtimeout);
if (sequence_end == 0) {
lua_pushinteger(L, key);
return 1;
} else {
lua_pushinteger(L, 27);
lua_pushlstring(L, escape_sequence, sequence_end);
return 2;
}
}
LUAFN(keyname)
{
lua_pushstring(L, keyname(luaL_checkinteger(L, 1)));
return 1;
}
LUAFN(timeout)
{
curtimeout = luaL_checkinteger(L, 1);
timeout(curtimeout);
return 0;
}
LUAFN(curs_set)
{
lua_pushinteger(L, curs_set(luaL_checkinteger(L, 1)));
return 1;
}
LUAFN(doupdate)
{
doupdate();
return 0;
}
LUAFN(refresh)
{
WINDOW *w;
which_window(L, &w);
wrefresh(w);
return 0;
}
LUAFN(noutrefresh)
{
WINDOW *w;
which_window(L, &w);
wnoutrefresh(w);
return 0;
}
LUAFN(redrawwin)
{
WINDOW *w;
which_window(L, &w);
redrawwin(w);
return 0;
}
LUAFN(newwin)
{
WINDOW *w = newwin(luaL_checkinteger(L,1),
luaL_checkinteger(L,2),
luaL_checkinteger(L,3),
luaL_checkinteger(L,4));
lua_pushlightuserdata(L, w);
return 1;
}
LUAFN(delwin)
{
WINDOW *w = (WINDOW *)lua_topointer(L, 1);
if (w != stdscr) {
if (w == curwin)
curwin = stdscr;
delwin(w);
}
return 0;
}
LUAFN(setwin)
{
lua_pushlightuserdata(L, curwin);
if (!lua_isnone(L, 1) && lua_isnil(L, 1))
curwin = stdscr;
else if (lua_islightuserdata(L,1)) {
WINDOW *w = (WINDOW *)lua_topointer(L, 1);
if (w != curwin)
curwin = w;
}
return 1;
}
LUAFN(getdims)
{
WINDOW *w;
which_window(L, &w);
int r = 0,c = 0;
getbegyx(w,r,c);
lua_pushinteger(L, r);
lua_pushinteger(L, c);
getmaxyx(w,r,c);
lua_pushinteger(L, r);
lua_pushinteger(L, c);
return 4;
}
LUAFN(getyx)
{
WINDOW *w;
which_window(L, &w);
int r = 0,c = 0;
getyx(w,r,c);
lua_pushinteger(L, r);
lua_pushinteger(L, c);
return 2;
}
LUAFN(mvwin)
{
WINDOW *w;
int i = which_window(L, &w);
mvwin(w, luaL_checkinteger(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
LUAFN(resize)
{
WINDOW *w;
int i = which_window(L, &w);
wresize(w, luaL_checkinteger(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
LUAFN(start_color)
{
int flag;
if ((flag = has_colors()))
start_color();
lua_pushboolean(L, flag);
return 1;
}
LUAFN(init_pair)
{
init_pair(luaL_checkinteger(L, 1),
luaL_checkinteger(L, 2),
luaL_checkinteger(L, 3));
return 0;
}
LUAFN(color_pair)
{
lua_pushinteger(L, COLOR_PAIR(luaL_checkinteger(L,1)));
return 1;
}
LUAFN(attron)
{
WINDOW *w;
int i = which_window(L, &w);
wattron(w, luaL_checkinteger(L, 1 + i));
return 0;
}
LUAFN(attroff)
{
WINDOW *w;
int i = which_window(L, &w);
wattroff(w, luaL_checkinteger(L, 1 + i));
return 0;
}
LUAFN(bkgd)
{
WINDOW *w;
int i = which_window(L, &w);
wbkgd(w, luaL_checkinteger(L, 1 + i));
return 0;
}
LUAFN(move)
{
WINDOW *w;
int i = which_window(L, &w);
wmove(w, luaL_checkinteger(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
LUAFN(addch)
{
WINDOW *w;
int i = which_window(L, &w);
waddch(w, luaL_checkinteger(L, i + 1));
return 0;
}
LUAFN(addstr)
{
WINDOW *w;
int i = which_window(L, &w);
waddstr(w, luaL_checkstring(L, i + 1));
return 0;
}
LUAFN(addnstr)
{
WINDOW *w;
int i = which_window(L, &w);
waddnstr(w, luaL_checkstring(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
LUAFN(insstr)
{
WINDOW *w;
int i = which_window(L, &w);
winsstr(w, luaL_checkstring(L, i + 1));
return 0;
}
LUAFN(insnstr)
{
WINDOW *w;
int i = which_window(L, &w);
winsnstr(w, luaL_checkstring(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
LUAFN(insdelln)
{
WINDOW *w;
int i = which_window(L, &w);
winsdelln(w, luaL_checkinteger(L, 1 + i));
return 0;
}
LUAFN(clrtoeol)
{
WINDOW *w;
which_window(L, &w);
wclrtoeol(w);
return 0;
}
LUAFN(clrtobot)
{
WINDOW *w;
which_window(L, &w);
wclrtobot(w);
return 0;
}
LUAFN(delch)
{
WINDOW *w;
which_window(L, &w);
wdelch(w);
return 0;
}
LUAFN(vline)
{
WINDOW *w;
int i = which_window(L, &w);
wvline(w, luaL_checkinteger(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
LUAFN(hline)
{
WINDOW *w;
int i = which_window(L, &w);
whline(w, luaL_checkinteger(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
LUAFN(box)
{
WINDOW *w;
int i = which_window(L, &w);
box(w, luaL_checkinteger(L, 1 + i), luaL_checkinteger(L, 2 + i));
return 0;
}
typedef struct { const char *name; int value; } intconst;
LUALIB_API int luaopen_ljcurses(lua_State *L)
{
static const luaL_Reg funcptrs[] = {
FN_ENTRY(init_curses),
FN_ENTRY(endwin),
FN_ENTRY(getch),
FN_ENTRY(keyname),
FN_ENTRY(timeout),
FN_ENTRY(curs_set),
FN_ENTRY(doupdate),
FN_ENTRY(refresh),
FN_ENTRY(noutrefresh),
FN_ENTRY(redrawwin),
FN_ENTRY(newwin),
FN_ENTRY(delwin),
FN_ENTRY(resize),
FN_ENTRY(setwin),
FN_ENTRY(getdims),
FN_ENTRY(getyx),
FN_ENTRY(mvwin),
FN_ENTRY(start_color),
FN_ENTRY(init_pair),
FN_ENTRY(color_pair),
FN_ENTRY(attron),
FN_ENTRY(attroff),
FN_ENTRY(bkgd),
FN_ENTRY(move),
FN_ENTRY(addch),
FN_ENTRY(addstr),
FN_ENTRY(addnstr),
FN_ENTRY(insstr),
FN_ENTRY(insnstr),
FN_ENTRY(insdelln),
FN_ENTRY(clrtoeol),
FN_ENTRY(clrtobot),
FN_ENTRY(delch),
FN_ENTRY(vline),
FN_ENTRY(hline),
FN_ENTRY(box),
{ NULL, NULL }
};
static intconst attribute_const[] = {
{"black", COLOR_BLACK},
{"white", COLOR_WHITE},
{"red", COLOR_RED},
{"blue", COLOR_BLUE},
{"green", COLOR_GREEN},
{"cyan", COLOR_CYAN},
{"magenta", COLOR_MAGENTA},
{"yellow", COLOR_YELLOW},
{"normal", A_NORMAL},
{"standout", A_STANDOUT},
{"underline", A_UNDERLINE},
{"reverse", A_REVERSE},
{"blink", A_BLINK},
{"dim", A_DIM},
{"bold", A_BOLD},
{"protect", A_PROTECT},
{"invis", A_INVIS},
{"altcharset", A_ALTCHARSET},
{"chartext", A_CHARTEXT},
{NULL, 0}
};
static intconst keys_const[] = {
{"ctrl_space", 0},
{"delete", 127},
{"escape", 27}, /* Ctrl [ */
{"grpsep", 28}, /* Ctrl \ */
{"fldsep", 29}, /* Ctrl ] */
{"recsep", 30}, /* Ctrl ^ */
{"unitsep", 31}, /* Ctrl - */
{"resize", KEY_RESIZE},
{NULL, 0}
};
luaL_register(L, "ljcurses", funcptrs);
lua_pushstring(L, "attributes");
lua_newtable(L);
for (int i = 0; attribute_const[i].name; i++) {
lua_pushstring(L, attribute_const[i].name);
lua_pushinteger(L, attribute_const[i].value);
lua_rawset(L, -3);
}
lua_rawset(L, -3);
lua_pushstring(L, "boxes");
lua_newtable(L);
lua_rawset(L, -3);
lua_pushstring(L, "keys");
lua_newtable(L);
for (int i = 0; i < 26; i++) {
char name[7] = "ctrl_?";
name[5] = i+'a';
lua_pushstring(L, name);
lua_pushinteger(L, i+1);
lua_rawset(L, -3);
}
for (int i = 0; keys_const[i].name; i++) {
lua_pushstring(L, keys_const[i].name);
lua_pushinteger(L, keys_const[i].value);
lua_rawset(L, -3);
}
lua_rawset(L, -3);
return 1;
}
|
caoliver/tft
|
lua_head.h
|
<filename>lua_head.h<gh_stars>0
#ifndef __LUA_HEAD__
#define __LUA_HEAD__
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#define LUAFN(NAME) static int lua_fn_##NAME(lua_State *L)
#define FN_ENTRY(NAME) { #NAME, lua_fn_##NAME }
#define AT_NAME_PUT(NAME, VALUE, TYPE) \
lua_pushstring(L, #NAME); \
lua_push##TYPE(L, VALUE); \
lua_rawset(L, -3)
#define AT_NAME_PUT_INT(NAME, VALUE) AT_NAME_PUT(NAME, VALUE, integer)
#endif
|
caoliver/tft
|
util.c
|
<filename>util.c<gh_stars>0
// Needed for clock_gettime() and friends.
#define _POSIX_C_SOURCE 199309
#include <signal.h>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#include <time.h>
#include "lua_head.h"
#include <errno.h>
#include <glob.h>
#include <termios.h>
#include <sys/time.h>
#include <sys/types.h>
uint64_t xxhfd(int fd, uint64_t seed);
LUAFN(getchar)
{
struct termios new, old;
char inbuf[16];
char *ptr=inbuf;
if (tcgetattr(0, &old) < 0)
return 0;
new=old;
tcflush(0, TCIFLUSH);
new.c_lflag &= ~(ECHO | ICANON);
tcsetattr(0, TCSANOW, &new);
for (int i=0; ++i <= sizeof(inbuf); ++ptr) {
struct timeval timeout = {0,50000};
fd_set infds;
FD_ZERO(&infds);
FD_SET(0, &infds);
if (select(1, &infds, NULL, NULL, i == 1 ? NULL : &timeout) != 1 ||
read(0, ptr, 1) < 1)
break;
}
tcsetattr(0, TCSANOW, &old);
tcflush(0, TCIFLUSH);
lua_pushlstring(L, inbuf, ptr - inbuf);
return 1;
}
LUAFN(readable)
{
const char *filename = lua_tostring(L, 1);
if (access(filename, R_OK) == 0) {
lua_pushboolean(L, 1);
return 1;
}
lua_pushnil(L);
lua_pushinteger(L, errno);
return 2;
}
LUAFN(cputime)
{
struct timespec result;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &result);
lua_pushnumber(L, (double)result.tv_sec + 1E-9 * (double)result.tv_nsec);
return 1;
}
LUAFN(realtime)
{
struct timespec result;
clock_gettime(CLOCK_REALTIME, &result);
lua_pushnumber(L, (double)result.tv_sec + 1E-9 * (double)result.tv_nsec);
return 1;
}
LUAFN(usleep)
{
usleep(luaL_checkinteger(L, 1));
return 0;
}
LUAFN(glob)
{
glob_t resultglob;
const char *pattern = lua_tostring(L, 1);
int rc;
rc = glob(pattern, GLOB_ERR, NULL, &resultglob);
if (rc != 0 && rc != GLOB_NOMATCH) {
lua_pushnil(L);
lua_pushinteger(L, rc == GLOB_NOSPACE ? ENOMEM : errno);
return 2;
}
lua_newtable(L);
if (rc == 0)
{
int i = 0;
while (i < resultglob.gl_pathc) {
lua_pushstring(L, resultglob.gl_pathv[i++]);
lua_rawseti(L, -2, i);
}
globfree(&resultglob);
}
return 1;
}
LUAFN(xxhsum_file)
{
int fd;
uint64_t result;
char outbuf[24];
if ((fd = open(luaL_checkstring(L, 1), O_RDONLY)) == -1) {
lua_pushstring(L, "0");
return 1;
}
result = xxhfd(fd, lua_tointeger(L, 2));
close(fd);
sprintf(outbuf, "%llX", (unsigned long long)result);
lua_pushstring(L, outbuf);
return 1;
}
LUAFN(lib_exists)
{
lua_pushboolean(L, access(lua_tostring(L, 1), R_OK|X_OK) == 0);
return 1;
}
typedef struct { const char *name; int value; } intconst;
LUALIB_API int luaopen_util(lua_State *L)
{
static const luaL_Reg funcptrs[] = {
FN_ENTRY(getchar),
FN_ENTRY(readable),
FN_ENTRY(realtime),
FN_ENTRY(cputime),
FN_ENTRY(usleep),
FN_ENTRY(glob),
FN_ENTRY(xxhsum_file),
FN_ENTRY(lib_exists),
{ NULL, NULL }
};
luaL_register(L, "util", funcptrs);
return 1;
}
|
caoliver/tft
|
xxhash.c
|
<gh_stars>0
/*
* xxHash - Fast Hash algorithm
* Copyright (C) 2012-2016, <NAME>
*
* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* You can contact the author at :
* - xxHash homepage: http://www.xxhash.com
* - xxHash source repository : https://github.com/Cyan4973/xxHash
*/
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
static const uint64_t PRIME64_1 = 11400714785074694791ULL;
static const uint64_t PRIME64_2 = 14029467366897019727ULL;
static const uint64_t PRIME64_3 = 1609587929392839161ULL;
static const uint64_t PRIME64_4 = 9650029242287828579ULL;
static const uint64_t PRIME64_5 = 2870177450012600261ULL;
static inline uint64_t rot64(uint64_t x, int8_t r)
{
return (x << r) | (x >> (64 - r));
}
#define round(ACC, INPUT) \
rot64(ACC + INPUT * PRIME64_2, 31) * PRIME64_1
#define mergeRound(ACC, VAL) \
PRIME64_1 * (ACC ^ (rot64(VAL * PRIME64_2, 31) * PRIME64_1)) + PRIME64_4
/* Input is assumed to be aligned to an eight byte boundary. */
uint64_t xxh(const void* input, size_t len, uint64_t seed)
{
const uint8_t* p = (const uint8_t*)input;
const uint8_t* const bEnd = p + len;
uint64_t h64;
if (len>=32) {
const uint8_t* const limit = bEnd - 32;
uint64_t v1 = seed + PRIME64_1 + PRIME64_2;
uint64_t v2 = seed + PRIME64_2;
uint64_t v3 = seed + 0;
uint64_t v4 = seed - PRIME64_1;
do {
v1 = round(v1, *(const uint64_t *)p); p+=8;
v2 = round(v2, *(const uint64_t *)p); p+=8;
v3 = round(v3, *(const uint64_t *)p); p+=8;
v4 = round(v4, *(const uint64_t *)p); p+=8;
} while (p<=limit);
h64 = rot64(v1, 1) + rot64(v2, 7) + rot64(v3, 12) + rot64(v4, 18);
h64 = mergeRound(h64, v1);
h64 = mergeRound(h64, v2);
h64 = mergeRound(h64, v3);
h64 = mergeRound(h64, v4);
} else {
h64 = seed + PRIME64_5;
}
h64 += (uint64_t) len;
while (p+8<=bEnd) {
h64 ^= round(0, *(const uint64_t *)p);
h64 = rot64(h64,27) * PRIME64_1 + PRIME64_4;
p+=8;
}
if (p+4<=bEnd) {
h64 ^= (uint64_t)(*(const uint32_t*)p) * PRIME64_1;
h64 = rot64(h64, 23) * PRIME64_2 + PRIME64_3;
p+=4;
}
while (p<bEnd) {
h64 ^= (*p) * PRIME64_5;
h64 = rot64(h64, 11) * PRIME64_1;
p++;
}
h64 ^= h64 >> 33;
h64 *= PRIME64_2;
h64 ^= h64 >> 29;
h64 *= PRIME64_3;
h64 ^= h64 >> 32;
return h64;
}
uint64_t xxhfd(int fd, uint64_t seed)
{
struct stat sb;
if (fstat(fd, &sb) < 0 || !S_ISREG(sb.st_mode))
return 0;
uint64_t result = 0 ;
void *map = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (map != MAP_FAILED) {
result = xxh(map, sb.st_size, seed);
munmap(map, sb.st_size);
}
return result;
}
|
caoliver/tft
|
elfutil.c
|
#include "lua_head.h"
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <gelf.h>
#include <errno.h>
#include <alloca.h>
char *realpath(const char *path, char *resolved_path);
#define PT_INTERP 3
#define SHT_DYNAMIC 6
static int architecture = 0;
LUAFN(filter_on_machine)
{
if (lua_isnoneornil(L,1)) {
architecture = 0;
return 0;
}
int newarch = luaL_checkinteger(L, 1);
if (newarch < 0 || newarch > 110) {
lua_pushstring(L, "Invalid architecture!");
lua_error(L);
}
architecture = newarch;
return 0;
}
static int read_at(int fd, char *buffer, size_t len, size_t where)
{
size_t old = lseek(fd, SEEK_CUR, 0);
if (old == -1 ||
lseek(fd, where, SEEK_SET) == -1 ||
read(fd, buffer, len) == -1 ||
lseek(fd, old, SEEK_SET) == -1)
return -1;
return 0;
}
/* Note: since this function will get randoms from find, silently
* return nil for non-elfs and wrong size/architecture.
*/
LUAFN(scan_elf)
{
const char *filename = luaL_checkstring(L, 1);
int fd = -1;
Elf *handle = NULL;
const char *errmsg = NULL;
GElf_Ehdr ehdr;
int return_items = 0;
if (elf_version(EV_CURRENT) == EV_NONE)
goto bugout;
if ((fd = open(filename, O_RDONLY)) < 0) {
errmsg = strerror(errno);
goto bugout;
}
if ((handle = elf_begin(fd, ELF_C_READ, NULL)) == NULL)
goto bugout;
if (elf_kind(handle) != ELF_K_ELF)
goto done;
lua_newtable(L);
lua_pushstring(L, "class");
switch (gelf_getclass(handle)) {
case ELFCLASS32:
lua_pushinteger(L, 32);
break;
case ELFCLASS64:
lua_pushinteger(L, 64);
break;
default:
errmsg = "Unknown ELF class";
goto bugout;
}
lua_rawset(L, -3);
if (gelf_getehdr(handle, &ehdr) == NULL)
goto bugout;
// The caller specified an architecture, but we don't match,
// then skip this.
if (architecture && ehdr.e_machine != architecture)
goto done;
lua_pushstring(L, "machine");
lua_pushinteger(L, ehdr.e_machine);
lua_rawset(L, -3);
lua_pushstring(L, "type");
switch (ehdr.e_type) {
case 2:
lua_pushstring(L, "executable");
break;
case 3:
lua_pushstring(L, "shared library");
break;
default:
errmsg = "Unexpected elf type";
goto bugout;
}
lua_rawset(L, -3);
// Find the interpreter (loader)
size_t n;
if (elf_getphdrnum(handle, &n))
goto bugout;
GElf_Phdr phdr;
for (size_t i=0; i < n; i++) {
if (gelf_getphdr(handle, i, &phdr) != &phdr)
goto bugout;
if (phdr.p_type == PT_INTERP) {
char *tempbuf = alloca(phdr.p_filesz);
if (read_at(fd, tempbuf, phdr.p_filesz, phdr.p_offset)) {
errmsg = strerror(errno);
goto bugout;
}
lua_pushstring(L, "interp");
lua_pushstring(L, tempbuf);
lua_rawset(L, -3);
break;
}
}
size_t shstrndx;
if (elf_getshdrstrndx(handle, &shstrndx))
goto bugout;
char *name;
Elf_Scn *scn = NULL;
char *strtab = NULL;
Elf_Data *edata = NULL;
int strtablen;
while ((scn = elf_nextscn(handle, scn)) != NULL) {
static GElf_Shdr shdr;
if (gelf_getshdr(scn, &shdr) != &shdr)
goto bugout;
if (shdr.sh_type == SHT_STRTAB) {
if (!(name = elf_strptr(handle, shstrndx, shdr.sh_name )))
goto bugout;
if (strcmp(name, ".dynstr"))
continue;
strtab = alloca(shdr.sh_size);
read_at(fd, strtab, strtablen = shdr.sh_size, shdr.sh_offset);
}
if (shdr.sh_type == SHT_DYNAMIC) {
if (!(name = elf_strptr(handle, shstrndx, shdr.sh_name )))
goto bugout;
if (strcmp(name, ".dynamic"))
continue;
if (!(edata = elf_getdata(scn, NULL)))
goto bugout;
}
}
// No dynamic section? No worries.
if (!edata)
goto done;
GElf_Dyn gdyn;
lua_pushstring(L, "needed");
lua_newtable(L);
int libnum = 1;
for (int i = 0; gelf_getdyn(edata, i, &gdyn) == &gdyn; i++) {
switch(gdyn.d_tag) {
case DT_NEEDED:
lua_pushstring(L, strtab + gdyn.d_un.d_val);
// STACK: dt_value needed_table "needed" elf_table
lua_rawseti(L, -2, libnum++);
continue;
case DT_SONAME:
lua_pushstring(L, "soname");
lua_pushstring(L, strtab + gdyn.d_un.d_val);
// STACK: dt_value dt_name needed_table "needed" elf_table
lua_rawset(L, -5);
continue;
case DT_RPATH:
lua_pushstring(L, "rpath");
break;
case DT_RUNPATH:
lua_pushstring(L, "runpath");
break;
default:
continue;
}
lua_newtable(L);
char *pathptr = strtab + gdyn.d_un.d_val;
char *next;
int i; // Shadows loopvar.
for (i = 1;
next = strchr(pathptr, ':');
i++, pathptr = next+1) {
lua_pushlstring(L, pathptr, next - pathptr);
lua_rawseti(L, -2, i);
}
lua_pushstring(L, pathptr);
lua_rawseti(L, -2, i);
lua_rawset(L, -5);
}
lua_rawset(L, -3);
return_items = 1;
done:
elf_end(handle);
close(fd);
return return_items;
bugout:
if (!errmsg)
errmsg = elf_errmsg(-1);
if (handle)
elf_end(handle);
if (fd >= 0)
close(fd);
lua_pushnil(L);
lua_pushstring(L, errmsg);
return 2;
}
#define DT_REG 8
#define DT_LNK 10
static void inode_in_table(lua_State *L, int dev, int inode)
{
char buf[128];
sprintf(buf, "%d,%d", dev, inode);
lua_newtable(L);
lua_pushstring(L, buf);
lua_rawseti(L, -2, 1);
return;
}
// candidate_table, prefix
LUAFN(get_candidates)
{
char *curdir = NULL;
if (lua_isnoneornil(L, 1) ||
!(curdir = getcwd(NULL, 0)) ||
chdir(lua_toboolean(L, 2) ? luaL_checkstring(L, 2) : "/") == -1) {
free(curdir);
lua_newtable(L);
return 1;
}
// Single value becomes a one-entry table.
if (lua_istable(L, 1))
lua_pushvalue(L,1);
else {
lua_newtable(L);
lua_pushvalue(L,1);
lua_rawseti(L,-2,1);
}
// Stat results go here.
lua_newtable(L);
lua_pushnil(L);
int place = 1;
while (lua_next(L, -3)) {
struct stat statb;
const char *name = lua_tostring(L, -1);
if (*name != '/' || stat(&name[1], &statb) == -1)
goto done;
if (S_ISREG(statb.st_mode)) {
inode_in_table(L, statb.st_dev, statb.st_ino);
lua_pushstring(L, name);
lua_rawseti(L, -2, 2);
lua_rawseti(L, -4, place++);
goto done;
}
if (S_ISDIR(statb.st_mode)) {
DIR *dirp;
char *olddir = getcwd(NULL, 0);
if (chdir(&name[1]) == 0 && (dirp = opendir("."))) {
struct dirent *dent;
while (dent = readdir(dirp)) {
// Exclude some obviously wrong files.
if (dent->d_type != DT_REG && dent->d_type != DT_LNK)
continue;
char *ext=strrchr(dent->d_name, '.');
if (ext && (!strcmp(ext, ".a") || !strcmp(ext, ".la")))
continue;
if (stat(dent->d_name, &statb) == -1 ||
!S_ISREG(statb.st_mode))
continue;
inode_in_table(L, statb.st_dev, statb.st_ino);
lua_pushfstring(L, "%s/%s", name, dent->d_name);
lua_rawseti(L, -2, 2);
lua_rawseti(L, -4, place++);
}
closedir(dirp);
}
if (olddir)
chdir(olddir);
free(olddir);
}
done:
lua_pop(L, 1);
}
chdir(curdir);
free(curdir);
return 1;
}
// Look through a table of synonyms for a given file and yield the directories
// for which the synonym with an absolute path is a hardlink.
LUAFN(get_origins)
{
char *curdir = NULL;
if (!(curdir = getcwd(NULL, 0)) ||
chdir(lua_toboolean(L, 2) ? luaL_checkstring(L, 2) : "/") == -1) {
free(curdir);
lua_newtable(L);
return 1;
}
lua_newtable(L);
lua_pushnil(L);
while (lua_next(L, 1)) {
struct stat statb;
const char *filename = lua_tostring(L, -2);
lua_pop(L, 1);
if (*filename != '/' || lstat(&filename[1], &statb) != 0 ||
!S_ISREG(statb.st_mode)) {
continue;
}
char *dirend = strrchr(filename, '/');
if (dirend) {
int len = dirend - filename;
lua_pushlstring(L, filename, len > 0 ? len : 1);
} else
lua_pushstring(L, filename);
lua_pushboolean(L, 1);
lua_rawset(L, -4);
}
chdir(curdir);
free(curdir);
return 1;
}
LUAFN(canonicalize)
{
char *path = realpath(lua_tostring(L, 1), NULL);
if (path) {
lua_pushstring(L, path);
free(path);
} else
lua_pushnil(L);
return 1;
}
typedef struct { const char *name; int value; } intconst;
LUALIB_API int luaopen_elfutil(lua_State *L)
{
static const luaL_Reg funcptrs[] = {
FN_ENTRY(filter_on_machine),
FN_ENTRY(scan_elf),
FN_ENTRY(get_candidates),
FN_ENTRY(get_origins),
FN_ENTRY(canonicalize),
{NULL, NULL}
};
static intconst machines[] = {
{"AMD64", 62},
{"X86", 3},
{NULL, 0}
};
luaL_register(L, "elfutil", funcptrs);
for (int i = 0; machines[i].name; i++) {
lua_pushstring(L, machines[i].name);
lua_pushinteger(L, machines[i].value);
lua_rawset(L, -3);
}
return 1;
}
|
VictorHaine/r-packages-itau
|
Windows/Rcpp/include/Rcpp/vector/Matrix.h
|
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// Matrix.h: Rcpp R/C++ interface class library -- matrices
//
// Copyright (C) 2010 - 2016 <NAME> and <NAME>
//
// This file is part of Rcpp.
//
// Rcpp is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Rcpp is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
#ifndef Rcpp__vector__Matrix_h
#define Rcpp__vector__Matrix_h
namespace Rcpp{
template <int RTYPE, template <class> class StoragePolicy = PreserveStorage >
class Matrix : public Vector<RTYPE, StoragePolicy>, public MatrixBase<RTYPE, true, Matrix<RTYPE,StoragePolicy> > {
int nrows ;
public:
using Vector<RTYPE, StoragePolicy>::size; // disambiguate diamond pattern for g++-6 and later
struct r_type : traits::integral_constant<int,RTYPE>{} ;
struct can_have_na : traits::true_type{} ;
typedef MatrixRow<RTYPE> Row ;
typedef ConstMatrixRow<RTYPE> ConstRow ;
typedef MatrixColumn<RTYPE> Column ;
typedef ConstMatrixColumn<RTYPE> ConstColumn ;
typedef SubMatrix<RTYPE> Sub ;
typedef StoragePolicy<Matrix> Storage ;
typedef Vector<RTYPE, StoragePolicy> VECTOR ;
typedef typename VECTOR::iterator iterator ;
typedef typename VECTOR::const_iterator const_iterator ;
typedef typename VECTOR::converter_type converter_type ;
typedef typename VECTOR::stored_type stored_type ;
typedef typename VECTOR::Proxy Proxy ;
typedef typename VECTOR::const_Proxy const_Proxy ;
Matrix() : VECTOR(Dimension(0, 0)), nrows(0) {}
Matrix(SEXP x) : VECTOR( r_cast<RTYPE>( x ) ), nrows( VECTOR::dims()[0] ) {}
Matrix( const Dimension& dims) : VECTOR( Rf_allocMatrix( RTYPE, dims[0], dims[1] ) ), nrows(dims[0]) {
if( dims.size() != 2 ) throw not_a_matrix();
VECTOR::init() ;
}
Matrix( const int& nrows_, const int& ncols) : VECTOR( Dimension( nrows_, ncols ) ),
nrows(nrows_)
{}
template <typename Iterator>
Matrix( const int& nrows_, const int& ncols, Iterator start ) :
VECTOR( start, start + (static_cast<R_xlen_t>(nrows_)*ncols) ),
nrows(nrows_)
{
VECTOR::attr( "dim" ) = Dimension( nrows, ncols ) ;
}
Matrix( const int& n) : VECTOR( Dimension( n, n ) ), nrows(n) {}
Matrix( const Matrix& other) : VECTOR( other.get__() ), nrows(other.nrows) {}
template <bool NA, typename MAT>
Matrix( const MatrixBase<RTYPE,NA,MAT>& other ) : VECTOR( Rf_allocMatrix( RTYPE, other.nrow(), other.ncol() ) ), nrows(other.nrow()) {
import_matrix_expression<NA,MAT>( other, nrows, ncol() ) ;
}
Matrix( const SubMatrix<RTYPE>& ) ;
Matrix& operator=(const Matrix& other) {
SEXP x = other.get__() ;
if( ! ::Rf_isMatrix(x) ) throw not_a_matrix();
VECTOR::set__( x ) ;
nrows = other.nrows ;
return *this ;
}
Matrix& operator=( const SubMatrix<RTYPE>& ) ;
explicit Matrix( const no_init_matrix& obj) : VECTOR(Rf_allocMatrix(RTYPE, obj.nrow(), obj.ncol())), nrows(obj.nrow()) {}
inline int ncol() const {
return VECTOR::dims()[1];
}
inline int nrow() const {
return nrows ;
}
inline int cols() const {
return VECTOR::dims()[1];
}
inline int rows() const {
return nrows ;
}
inline Row row( int i ){ return Row( *this, i ) ; }
inline ConstRow row( int i ) const{ return ConstRow( *this, i ) ; }
inline Column column( int i ){ return Column(*this, i ) ; }
inline ConstColumn column( int i ) const{ return ConstColumn( *this, i ) ; }
inline const_iterator begin() const{ return VECTOR::begin() ; }
inline const_iterator end() const{ return VECTOR::end() ; }
inline const_iterator cbegin() const{ return VECTOR::begin() ; }
inline const_iterator cend() const{ return VECTOR::end() ; }
inline iterator begin() { return VECTOR::begin() ; }
inline iterator end() { return VECTOR::end() ; }
template <typename U>
void fill_diag( const U& u) {
fill_diag__dispatch( typename traits::is_trivial<RTYPE>::type(), u ) ;
}
template <typename U> static Matrix diag( int size, const U& diag_value ) {
Matrix res(size,size) ;
res.fill_diag( diag_value ) ;
return res ;
}
inline Proxy operator[]( R_xlen_t i ) {
return static_cast< Vector<RTYPE>* >( this )->operator[]( i ) ;
}
inline const_Proxy operator[]( R_xlen_t i ) const {
return static_cast< const Vector<RTYPE>* >( this )->operator[]( i ) ;
}
inline Proxy operator()( const size_t& i, const size_t& j) {
return static_cast< Vector<RTYPE>* >( this )->operator[]( offset( i, j ) ) ;
}
inline const_Proxy operator()( const size_t& i, const size_t& j) const {
return static_cast< const Vector<RTYPE>* >( this )->operator[]( offset( i, j ) ) ;
}
inline Proxy at( const size_t& i, const size_t& j) {
return static_cast< Vector<RTYPE>* >( this )->operator()( i, j ) ;
}
inline const_Proxy at( const size_t& i, const size_t& j) const {
return static_cast< const Vector<RTYPE>* >( this )->operator()( i, j ) ;
}
inline Row operator()( int i, internal::NamedPlaceHolder ) {
return Row( *this, i ) ;
}
inline ConstRow operator()( int i, internal::NamedPlaceHolder ) const {
return ConstRow( *this, i ) ;
}
inline Column operator()( internal::NamedPlaceHolder, int i ) {
return Column( *this, i ) ;
}
inline ConstColumn operator()( internal::NamedPlaceHolder, int i ) const {
return ConstColumn( *this, i ) ;
}
inline Sub operator()( const Range& row_range, const Range& col_range) {
return Sub( const_cast<Matrix&>(*this), row_range, col_range ) ;
}
inline Sub operator()( internal::NamedPlaceHolder, const Range& col_range) {
return Sub( const_cast<Matrix&>(*this), Range(0,nrow()-1) , col_range ) ;
}
inline Sub operator()( const Range& row_range, internal::NamedPlaceHolder ) {
return Sub( const_cast<Matrix&>(*this), row_range, Range(0,ncol()-1) ) ;
}
private:
inline R_xlen_t offset(const int i, const int j) const { return i + static_cast<R_xlen_t>(nrows) * j ; }
template <typename U>
void fill_diag__dispatch( traits::false_type, const U& u) {
Shield<SEXP> elem( converter_type::get( u ) );
R_xlen_t bounds = std::min(Matrix::nrow(), Matrix::ncol());
for (R_xlen_t i = 0; i < bounds; ++i) {
(*this)(i, i) = elem;
}
}
template <typename U>
void fill_diag__dispatch( traits::true_type, const U& u) {
stored_type elem = converter_type::get( u );
R_xlen_t bounds = std::min(Matrix::nrow(), Matrix::ncol());
for (R_xlen_t i = 0; i < bounds; ++i) {
(*this)(i, i) = elem;
}
}
template <bool NA, typename MAT>
void import_matrix_expression( const MatrixBase<RTYPE,NA,MAT>& other, int nr, int nc ) {
iterator start = VECTOR::begin() ;
for( int j=0; j<nc; j++){
for( int i=0; i<nr; i++, ++start){
*start = other(i,j) ;
}
}
}
};
inline internal::DimNameProxy rownames(SEXP x) {
return internal::DimNameProxy(x, 0);
}
inline internal::DimNameProxy colnames(SEXP x) {
return internal::DimNameProxy(x, 1);
}
template<template <class> class StoragePolicy >
inline std::ostream &operator<<(std::ostream & s, const Matrix<REALSXP, StoragePolicy> & rhs) {
typedef Matrix<REALSXP, StoragePolicy> MATRIX;
std::ios::fmtflags flags = s.flags();
s.unsetf(std::ios::floatfield);
std::streamsize precision = s.precision();
const int rows = rhs.rows();
for (int i = 0; i < rows; ++i) {
typename MATRIX::Row row = const_cast<MATRIX &>(rhs).row(i);
typename MATRIX::Row::iterator j = row.begin();
typename MATRIX::Row::iterator jend = row.end();
if (j != jend) {
s << std::showpoint << std::setw(precision + 1) << (*j);
j++;
for ( ; j != jend; j++) {
s << " " << std::showpoint << std::setw(precision + 1) << (*j);
}
}
s << std::endl;
}
s.flags(flags);
return s;
}
#ifndef RCPP_NO_SUGAR
#define RCPP_GENERATE_MATRIX_SCALAR_OPERATOR(__OPERATOR__) \
template <int RTYPE, template <class> class StoragePolicy, typename T > \
inline typename traits::enable_if< traits::is_convertible< typename traits::remove_const_and_reference< T >::type, \
typename Matrix<RTYPE, StoragePolicy>::stored_type >::value, Matrix<RTYPE, StoragePolicy> >::type \
operator __OPERATOR__ (const Matrix<RTYPE, StoragePolicy> &lhs, const T &rhs) { \
Vector<RTYPE, StoragePolicy> v = static_cast<const Vector<RTYPE, StoragePolicy> &>(lhs) __OPERATOR__ rhs; \
v.attr("dim") = Vector<INTSXP>::create(lhs.nrow(), lhs.ncol()); \
return as< Matrix<RTYPE, StoragePolicy> >(v); \
}
RCPP_GENERATE_MATRIX_SCALAR_OPERATOR(+)
RCPP_GENERATE_MATRIX_SCALAR_OPERATOR(-)
RCPP_GENERATE_MATRIX_SCALAR_OPERATOR(*)
RCPP_GENERATE_MATRIX_SCALAR_OPERATOR(/)
#undef RCPP_GENERATE_MATRIX_SCALAR_OPERATOR
#define RCPP_GENERATE_SCALAR_MATRIX_OPERATOR(__OPERATOR__) \
template <int RTYPE, template <class> class StoragePolicy, typename T > \
inline typename traits::enable_if< traits::is_convertible< typename traits::remove_const_and_reference< T >::type, \
typename Matrix<RTYPE, StoragePolicy>::stored_type >::value, Matrix<RTYPE, StoragePolicy> >::type \
operator __OPERATOR__ (const T &lhs, const Matrix<RTYPE, StoragePolicy> &rhs) { \
Vector<RTYPE, StoragePolicy> v = static_cast<const Vector<RTYPE, StoragePolicy> &>(rhs); \
v = lhs __OPERATOR__ v; \
v.attr("dim") = Vector<INTSXP>::create(rhs.nrow(), rhs.ncol()); \
return as< Matrix<RTYPE, StoragePolicy> >(v); \
}
RCPP_GENERATE_SCALAR_MATRIX_OPERATOR(+)
RCPP_GENERATE_SCALAR_MATRIX_OPERATOR(-)
RCPP_GENERATE_SCALAR_MATRIX_OPERATOR(*)
RCPP_GENERATE_SCALAR_MATRIX_OPERATOR(/)
#undef RCPP_GENERATE_SCALAR_MATRIX_OPERATOR
#endif
template<template <class> class StoragePolicy >
inline std::ostream &operator<<(std::ostream & s, const Matrix<INTSXP, StoragePolicy> & rhs) {
typedef Matrix<INTSXP, StoragePolicy> MATRIX;
typedef Vector<INTSXP, StoragePolicy> VECTOR;
std::ios::fmtflags flags = s.flags();
s << std::dec;
int min = std::numeric_limits<int>::max();
int max = std::numeric_limits<int>::min();
typename VECTOR::iterator j = static_cast<VECTOR &>(const_cast<MATRIX &>(rhs)).begin();
typename VECTOR::iterator jend = static_cast<VECTOR &>(const_cast<MATRIX &>(rhs)).end();
for ( ; j != jend; ++j) {
if (*j < min) {
min = *j;
}
if (*j > max) {
max = *j;
}
}
int digitsMax = (max >= 0) ? 0 : 1;
int digitsMin = (min >= 0) ? 0 : 1;
while (min != 0)
{
++digitsMin;
min /= 10;
}
while (max != 0)
{
++digitsMax;
max /= 10;
}
int digits = std::max(digitsMin, digitsMax);
const int rows = rhs.rows();
for (int i = 0; i < rows; ++i) {
typename MATRIX::Row row = const_cast<MATRIX &>(rhs).row(i);
typename MATRIX::Row::iterator j = row.begin();
typename MATRIX::Row::iterator jend = row.end();
if (j != jend) {
s << std::setw(digits) << (*j);
++j;
for ( ; j != jend; ++j) {
s << " " << std::setw(digits) << (*j);
}
}
s << std::endl;
}
s.flags(flags);
return s;
}
template<template <class> class StoragePolicy >
inline std::ostream &operator<<(std::ostream & s, const Matrix<STRSXP, StoragePolicy> & rhs) {
typedef Matrix<STRSXP, StoragePolicy> MATRIX;
const int rows = rhs.rows();
for (int i = 0; i < rows; ++i) {
typename MATRIX::Row row = const_cast<MATRIX &>(rhs).row(i);
typename MATRIX::Row::iterator j = row.begin();
typename MATRIX::Row::iterator jend = row.end();
if (j != jend) {
s << "\"" << (*j) << "\"";
j++;
for ( ; j != jend; j++) {
s << " \"" << (*j) << "\"";
}
}
s << std::endl;
}
return s;
}
template<int RTYPE, template <class> class StoragePolicy >
inline std::ostream &operator<<(std::ostream & s, const Matrix<RTYPE, StoragePolicy> & rhs) {
typedef Matrix<RTYPE, StoragePolicy> MATRIX;
const int rows = rhs.rows();
for (int i = 0; i < rows; ++i) {
typename MATRIX::Row row = const_cast<MATRIX &>(rhs).row(i);
typename MATRIX::Row::iterator j = row.begin();
typename MATRIX::Row::iterator jend = row.end();
if (j != jend) {
s << (*j);
j++;
for ( ; j != jend; j++) {
s << (*j);
}
}
s << std::endl;
}
return s;
}
template<int RTYPE, template <class> class StoragePolicy >
Matrix<RTYPE, StoragePolicy> tranpose_impl(const Matrix<RTYPE, StoragePolicy> & x) {
typedef Matrix<RTYPE, StoragePolicy> MATRIX;
typedef Vector<RTYPE, StoragePolicy> VECTOR;
Vector<INTSXP, StoragePolicy> dims = ::Rf_getAttrib(x, R_DimSymbol);
int nrow = dims[0], ncol = dims[1];
MATRIX r(Dimension(ncol, nrow)); // new Matrix with reversed dimension
R_xlen_t len = XLENGTH(x), len2 = XLENGTH(x)-1;
// similar approach as in R: fill by in column, "accessing row-wise"
VECTOR s = VECTOR(r.get__());
for (R_xlen_t i = 0, j = 0; i < len; i++, j += nrow) {
if (j > len2) j -= len2;
s[i] = x[j];
}
// there must be a simpler, more C++-ish way for this ...
SEXP dimNames = Rf_getAttrib(x, R_DimNamesSymbol);
if (!Rf_isNull(dimNames)) {
// do we need dimnamesnames ?
Shield<SEXP> newDimNames(Rf_allocVector(VECSXP, 2));
SET_VECTOR_ELT(newDimNames, 0, VECTOR_ELT(dimNames, 1));
SET_VECTOR_ELT(newDimNames, 1, VECTOR_ELT(dimNames, 0));
Rf_setAttrib(r, R_DimNamesSymbol, newDimNames);
}
return r;
}
template<template <class> class StoragePolicy>
Matrix<REALSXP, StoragePolicy> transpose(const Matrix<REALSXP, StoragePolicy> & x) {
return tranpose_impl<REALSXP, StoragePolicy>(x);
}
template<template <class> class StoragePolicy>
Matrix<INTSXP, StoragePolicy> transpose(const Matrix<INTSXP, StoragePolicy> & x) {
return tranpose_impl<INTSXP, StoragePolicy>(x);
}
template<template <class> class StoragePolicy>
Matrix<STRSXP, StoragePolicy> transpose(const Matrix<STRSXP, StoragePolicy> & x) {
return tranpose_impl<STRSXP, StoragePolicy>(x);
}
}
#endif
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/Result/Var.h
|
#ifndef dplyr_Result_Var_H
#define dplyr_Result_Var_H
#include <dplyr/Result/Processor.h>
namespace dplyr {
namespace internal {
inline double square(double x) {
return x * x;
}
}
template <int RTYPE, bool NA_RM>
class Var : public Processor<REALSXP, Var<RTYPE, NA_RM> > {
public:
typedef Processor<REALSXP, Var<RTYPE, NA_RM> > Base;
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
Var(SEXP x) :
Base(x),
data_ptr(Rcpp::internal::r_vector_start<RTYPE>(x))
{}
~Var() {}
inline double process_chunk(const SlicingIndex& indices) {
int n = indices.size();
if (n <= 1) return NA_REAL;
double m = internal::Mean_internal<RTYPE, NA_RM, SlicingIndex>::process(data_ptr, indices);
if (!R_FINITE(m)) return m;
double sum = 0.0;
int count = 0;
for (int i = 0; i < n; i++) {
STORAGE current = data_ptr[indices[i]];
if (NA_RM && Rcpp::Vector<RTYPE>::is_na(current)) continue;
sum += internal::square(current - m);
count++;
}
if (count <= 1) return NA_REAL;
return sum / (count - 1);
}
private:
STORAGE* data_ptr;
};
}
#endif
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/Result/Mean.h
|
<gh_stars>1-10
#ifndef dplyr_Result_Mean_H
#define dplyr_Result_Mean_H
#include <dplyr/Result/Processor.h>
namespace dplyr {
namespace internal {
template <int RTYPE, bool NA_RM, typename Index>
struct Mean_internal {
static double process(typename Rcpp::traits::storage_type<RTYPE>::type* ptr, const Index& indices) {
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
long double res = 0.0;
int n = indices.size();
int m = n;
for (int i = 0; i < n; i++) {
STORAGE value = ptr[ indices[i] ];
// REALSXP and !NA_RM: we don't test for NA here because += NA will give NA
// this is faster in the most common case where there are no NA
// if there are NA, we could return quicker as in the version for
// INTSXP, but we would penalize the most common case
//
// INTSXP: no shortcut, need to test
if (NA_RM || RTYPE == INTSXP) {
if (Rcpp::traits::is_na<RTYPE>(value)) {
if (!NA_RM) {
return NA_REAL;
}
--m;
continue;
}
}
res += value;
}
if (m == 0) return R_NaN;
res /= m;
// Correcting accuracy of result, see base R implementation
if (R_FINITE(res)) {
long double t = 0.0;
for (int i = 0; i < n; i++) {
STORAGE value = ptr[indices[i]];
if (!NA_RM || ! Rcpp::traits::is_na<RTYPE>(value)) {
t += value - res;
}
}
res += t / m;
}
return (double)res;
}
};
} // namespace internal
template <int RTYPE, bool NA_RM>
class Mean : public Processor< REALSXP, Mean<RTYPE, NA_RM> > {
public:
typedef Processor< REALSXP, Mean<RTYPE, NA_RM> > Base;
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
Mean(SEXP x) :
Base(x),
data_ptr(Rcpp::internal::r_vector_start<RTYPE>(x))
{}
~Mean() {}
inline double process_chunk(const SlicingIndex& indices) {
return internal::Mean_internal<RTYPE, NA_RM, SlicingIndex>::process(data_ptr, indices);
}
private:
STORAGE* data_ptr;
};
}
#endif
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/Result/Processor.h
|
#ifndef dplyr_Result_Processor_H
#define dplyr_Result_Processor_H
#include <tools/utils.h>
#include <dplyr/GroupedDataFrame.h>
#include <dplyr/RowwiseDataFrame.h>
#include <dplyr/Result/Result.h>
namespace dplyr {
// if we derive from this instead of deriving from Result, all we have to
// do is implement a process_chunk method that takes a SlicingIndex& as
// input and returns the suitable type (i.e. storage_type<OUTPUT>)
// all the builtin result implementation (Mean, ...) use this.
template <int OUTPUT, typename CLASS>
class Processor : public Result {
public:
typedef typename Rcpp::traits::storage_type<OUTPUT>::type STORAGE;
Processor() : data(R_NilValue) {}
Processor(SEXP data_) : data(data_) {}
virtual SEXP process(const Rcpp::GroupedDataFrame& gdf) {
return process_grouped<GroupedDataFrame>(gdf);
}
virtual SEXP process(const Rcpp::RowwiseDataFrame& gdf) {
return process_grouped<RowwiseDataFrame>(gdf);
}
virtual SEXP process(const SlicingIndex& index) {
CLASS* obj = static_cast<CLASS*>(this);
Rcpp::Vector<OUTPUT> res = Rcpp::Vector<OUTPUT>::create(obj->process_chunk(index));
copy_attributes(res, data);
return res;
}
private:
template <typename Data>
SEXP process_grouped(const Data& gdf) {
int n = gdf.ngroups();
Rcpp::Shield<SEXP> res(Rf_allocVector(OUTPUT, n));
STORAGE* ptr = Rcpp::internal::r_vector_start<OUTPUT>(res);
CLASS* obj = static_cast<CLASS*>(this);
typename Data::group_iterator git = gdf.group_begin();
for (int i = 0; i < n; i++, ++git)
ptr[i] = obj->process_chunk(*git);
copy_attributes(res, data);
return res;
}
inline SEXP promote(SEXP obj) {
RObject res(obj);
copy_attributes(res, data);
return res;
}
SEXP data;
};
template <typename CLASS>
class Processor<STRSXP, CLASS> : public Result {
public:
Processor(SEXP data_): data(data_) {}
virtual SEXP process(const Rcpp::GroupedDataFrame& gdf) {
return process_grouped<GroupedDataFrame>(gdf);
}
virtual SEXP process(const Rcpp::RowwiseDataFrame& gdf) {
return process_grouped<RowwiseDataFrame>(gdf);
}
virtual SEXP process(const SlicingIndex& index) {
CLASS* obj = static_cast<CLASS*>(this);
return CharacterVector::create(obj->process_chunk(index));
}
private:
template <typename Data>
SEXP process_grouped(const Data& gdf) {
int n = gdf.ngroups();
Rcpp::Shield<SEXP> res(Rf_allocVector(STRSXP, n));
CLASS* obj = static_cast<CLASS*>(this);
typename Data::group_iterator git = gdf.group_begin();
for (int i = 0; i < n; i++, ++git)
SET_STRING_ELT(res, i, obj->process_chunk(*git));
return res;
}
SEXP data;
};
}
#endif
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/Result/GroupedHybridCall.h
|
<gh_stars>0
#ifndef dplyr_GroupedHybridCall_H
#define dplyr_GroupedHybridCall_H
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <tools/Call.h>
#include <tools/utils.h>
#include <dplyr/Result/Result.h>
#include <bindrcpp.h>
namespace dplyr {
SEXP dplyr_object(const char* name);
class IHybridCallback {
public:
virtual ~IHybridCallback();
public:
virtual SEXP get_subset(const SymbolString& name) const = 0;
};
// The GroupedHybridEnv class provides the overscope/data mask upon request,
// which forwards accesses to variables to IHybridCallback::get_subset()
// for an IHybridCallback object provided externally via a shared_ptr<>.
class GroupedHybridEnv {
// Objects of class HybridCallbackWeakProxy are owned by an XPtr that is
// buried in a closure maintained by bindr. We have no control of their
// lifetime. They are connected to an IHybridCallback via a weak_ptr<>
// constructed from a shared_ptr<>), to which all calls to get_subset()
// are forwarded. If the underlying object has been destroyed (which can
// happen if the data mask leaks and survives the dplyr verb,
// sometimes unintentionally), the weak pointer cannot be locked, and
// get_subset() returns NULL with a warning (#3318).
class HybridCallbackWeakProxy : public IHybridCallback {
public:
HybridCallbackWeakProxy(boost::shared_ptr<const IHybridCallback> real_);
public:
SEXP get_subset(const SymbolString& name) const;
virtual ~HybridCallbackWeakProxy();
private:
boost::weak_ptr<const IHybridCallback> real;
};
public:
GroupedHybridEnv(const CharacterVector& names_, const Environment& env_, boost::shared_ptr<const IHybridCallback> callback_);
~GroupedHybridEnv();
public:
const Environment& get_overscope() const;
private:
void provide_overscope() const;
static SEXP hybrid_get_callback(const String& name, List payload);
private:
const CharacterVector names;
const Environment env;
boost::shared_ptr<const IHybridCallback> callback;
mutable Environment overscope;
mutable Environment mask_active;
mutable Environment mask_bottom;
mutable bool has_overscope;
};
// This class replaces calls to hybrid handlers by literals representing the result.
class GroupedHybridCall {
public:
GroupedHybridCall(const Call& call_, const ILazySubsets& subsets_, const Environment& env_);
public:
Call simplify(const SlicingIndex& indices) const;
private:
bool simplified(Call& call) const;
bool replace(SEXP p) const;
const SlicingIndex& get_indices() const;
void set_indices(const SlicingIndex& indices_) const;
void clear_indices() const;
private:
// Initialization
const Call original_call;
const ILazySubsets& subsets;
const Environment env;
private:
// State
mutable const SlicingIndex* indices;
};
// The GroupedHybridEval class evaluates expressions for each group.
// It implements IHybridCallback to handle requests for the value of
// a variable.
class GroupedHybridEval : public IHybridCallback {
// Objects of HybridCallbackProxy are owned by GroupedHybridEval and
// held with a shared_ptr<> to support weak references. They simply
// forward to the enclosing GroupedHybridEval via the IHybridCallback
// interface.
class HybridCallbackProxy : public IHybridCallback {
public:
HybridCallbackProxy(const IHybridCallback* real_);
virtual ~HybridCallbackProxy();
public:
SEXP get_subset(const SymbolString& name) const;
private:
const IHybridCallback* real;
};
public:
GroupedHybridEval(const Call& call_, const ILazySubsets& subsets_, const Environment& env_);
const SlicingIndex& get_indices() const;
public: // IHybridCallback
SEXP get_subset(const SymbolString& name) const;
public:
SEXP eval(const SlicingIndex& indices_);
private:
void set_indices(const SlicingIndex& indices_);
void clear_indices();
SEXP eval_with_indices();
private:
const SlicingIndex* indices;
const ILazySubsets& subsets;
Environment env;
boost::shared_ptr<IHybridCallback> proxy;
const GroupedHybridEnv hybrid_env;
const GroupedHybridCall hybrid_call;
};
} // namespace dplyr
#endif
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/tools/Quosure.h
|
<reponame>VictorHaine/r-packages-itau<gh_stars>1-10
#ifndef dplyr__Quosure_h
#define dplyr__Quosure_h
#include <tools/SymbolString.h>
#include <tools/utils.h>
#include "SymbolVector.h"
namespace dplyr {
inline SEXP quosure(SEXP expr, SEXP env) {
return internal::rlang_api().new_quosure(expr, env);
}
class NamedQuosure {
public:
NamedQuosure(SEXP data_, SymbolString name__ = "") :
data(data_),
name_(name__)
{}
NamedQuosure(const Formula& data_, SymbolString name__ = "") :
data(data_),
name_(name__)
{}
NamedQuosure(const NamedQuosure& other) :
data(other.data),
name_(other.name_)
{}
SEXP expr() const {
return Rf_duplicate(internal::rlang_api().quo_get_expr(data));
}
SEXP env() const {
return internal::rlang_api().quo_get_env(data);
}
SymbolString name() const {
return name_;
}
private:
RObject data;
SymbolString name_;
};
} // namespace dplyr
namespace Rcpp {
using namespace dplyr;
template <>
inline bool is<NamedQuosure>(SEXP x) {
return dplyr::internal::rlang_api().is_quosure(x);
}
} // namespace Rcpp
namespace dplyr {
class QuosureList {
public:
QuosureList(const List& data_) : data() {
int n = data_.size();
if (n == 0) return;
CharacterVector names = data_.names();
for (int i = 0; i < n; i++) {
SEXP x = data_[i];
if (!is<NamedQuosure>(x)) {
stop("corrupt tidy quote");
}
data.push_back(NamedQuosure(x, SymbolString(names[i])));
}
}
const NamedQuosure& operator[](int i) const {
return data[i];
}
int size() const {
return data.size();
}
bool single_env() const {
if (data.size() <= 1) return true;
SEXP env = data[0].env();
for (size_t i = 1; i < data.size(); i++) {
if (data[i].env() != env) return false;
}
return true;
}
SymbolVector names() const {
CharacterVector out(data.size());
for (size_t i = 0; i < data.size(); ++i) {
out[i] = data[i].name().get_string();
}
return SymbolVector(out);
}
private:
std::vector<NamedQuosure> data;
};
} // namespace dplyr
#endif
|
VictorHaine/r-packages-itau
|
Windows/RcppParallel/include/RcppParallel/TinyThread.h
|
#ifndef __RCPP_PARALLEL_TINYTHREAD__
#define __RCPP_PARALLEL_TINYTHREAD__
#include <cstdlib>
#include "Common.h"
#include <tthread/tinythread.h>
#include <stdio.h>
#include <vector>
namespace RcppParallel {
namespace {
// Class which represents a range of indexes to perform work on
// (worker functions are passed this range so they know which
// elements are safe to read/write to)
class IndexRange {
public:
// Initizlize with a begin and (exclusive) end index
IndexRange(std::size_t begin, std::size_t end)
: begin_(begin), end_(end)
{
}
// Access begin() and end()
std::size_t begin() const { return begin_; }
std::size_t end() const { return end_; }
std::size_t size() const { return end_ - begin_ ; }
private:
std::size_t begin_;
std::size_t end_;
};
// Because tinythread allows us to pass only a plain C function
// we need to pass our worker and range within a struct that we
// can cast to/from void*
struct Work {
Work(IndexRange range, Worker& worker)
: range(range), worker(worker)
{
}
IndexRange range;
Worker& worker;
};
// Thread which performs work (then deletes the work object
// when it's done)
extern "C" inline void workerThread(void* data) {
try
{
Work* pWork = static_cast<Work*>(data);
pWork->worker(pWork->range.begin(), pWork->range.end());
delete pWork;
}
catch(...)
{
}
}
// Function to calculate the ranges for a given input
std::vector<IndexRange> splitInputRange(const IndexRange& range,
std::size_t grainSize) {
// determine max number of threads
std::size_t threads = tthread::thread::hardware_concurrency();
char* numThreads = ::getenv("RCPP_PARALLEL_NUM_THREADS");
if (numThreads != NULL) {
int parsedThreads = ::atoi(numThreads);
if (parsedThreads > 0)
threads = parsedThreads;
}
// compute grainSize (including enforcing requested minimum)
std::size_t length = range.end() - range.begin();
if (threads == 1)
grainSize = length;
else if ((length % threads) == 0) // perfect division
grainSize = std::max(length / threads, grainSize);
else // imperfect division, divide by threads - 1
grainSize = std::max(length / (threads-1), grainSize);
// allocate ranges
std::vector<IndexRange> ranges;
std::size_t begin = range.begin();
while (begin < range.end()) {
std::size_t end = std::min(begin + grainSize, range.end());
ranges.push_back(IndexRange(begin, end));
begin = end;
}
// return ranges
return ranges;
}
} // anonymous namespace
// Execute the Worker over the IndexRange in parallel
inline void ttParallelFor(std::size_t begin, std::size_t end,
Worker& worker, std::size_t grainSize = 1) {
using namespace tthread;
// split the work
IndexRange inputRange(begin, end);
std::vector<IndexRange> ranges = splitInputRange(inputRange, grainSize);
// create threads
std::vector<thread*> threads;
for (std::size_t i = 0; i<ranges.size(); ++i) {
threads.push_back(new thread(workerThread, new Work(ranges[i], worker)));
}
// join and delete them
for (std::size_t i = 0; i<threads.size(); ++i) {
threads[i]->join();
delete threads[i];
}
}
// Execute the IWorker over the range in parallel then join results
template <typename Reducer>
inline void ttParallelReduce(std::size_t begin, std::size_t end,
Reducer& reducer, std::size_t grainSize = 1) {
using namespace tthread;
// split the work
IndexRange inputRange(begin, end);
std::vector<IndexRange> ranges = splitInputRange(inputRange, grainSize);
// create threads (split for each thread and track the allocated workers)
std::vector<thread*> threads;
std::vector<Worker*> workers;
for (std::size_t i = 0; i<ranges.size(); ++i) {
Reducer* pReducer = new Reducer(reducer, RcppParallel::Split());
workers.push_back(pReducer);
threads.push_back(new thread(workerThread, new Work(ranges[i], *pReducer)));
}
// wait for each thread, join it's results, then delete the worker & thread
for (std::size_t i = 0; i<threads.size(); ++i) {
// wait for thread
threads[i]->join();
// join the results
reducer.join(static_cast<Reducer&>(*workers[i]));
// delete the worker (which we split above) and the thread
delete workers[i];
delete threads[i];
}
}
} // namespace RcppParallel
#endif // __RCPP_PARALLEL_TINYTHREAD__
|
VictorHaine/r-packages-itau
|
Windows/RcppParallel/include/RcppParallel.h
|
#ifndef __RCPP_PARALLEL__
#define __RCPP_PARALLEL__
// TinyThread implementation
#include "RcppParallel/TinyThread.h"
// Use TBB only where it's known to compile and work correctly
// (NOTE: Windows TBB is temporarily opt-in for packages for
// compatibility with CRAN packages not previously configured
// to link to TBB in Makevars.win)
#ifndef RCPP_PARALLEL_USE_TBB
#if defined(__APPLE__) || defined(__gnu_linux__) || ((defined(__sun) && defined(__SVR4) && !defined(__sparc)))
#define RCPP_PARALLEL_USE_TBB 1
#include "RcppParallel/TBB.h"
#else
#define RCPP_PARALLEL_USE_TBB 0
#endif
#endif
#if RCPP_PARALLEL_USE_TBB
#include "RcppParallel/TBB.h"
#endif
#include "RcppParallel/RVector.h"
#include "RcppParallel/RMatrix.h"
namespace RcppParallel {
inline void parallelFor(std::size_t begin, std::size_t end,
Worker& worker, std::size_t grainSize = 1) {
#if RCPP_PARALLEL_USE_TBB
tbbParallelFor(begin, end, worker, grainSize);
#else
ttParallelFor(begin, end, worker, grainSize);
#endif
}
template <typename Reducer>
inline void parallelReduce(std::size_t begin, std::size_t end,
Reducer& reducer, std::size_t grainSize = 1) {
#if RCPP_PARALLEL_USE_TBB
tbbParallelReduce(begin, end, reducer, grainSize);
#else
ttParallelReduce(begin, end, reducer, grainSize);
#endif
}
} // namespace RcppParallel
#endif // __RCPP_PARALLEL__
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/dplyr.h
|
<filename>Windows/dplyr/include/dplyr/dplyr.h
#ifndef dplyr_dplyr_dplyr_H
#define dplyr_dplyr_dplyr_H
#include <dplyr/registration.h>
#include <dplyr/CharacterVectorOrderer.h>
#include <dplyr/white_list.h>
#include <dplyr/checks.h>
#include <dplyr/visitor_set/visitor_set.h>
#include <dplyr/BoolResult.h>
#include <dplyr/GroupedDataFrame.h>
#include <dplyr/RowwiseDataFrame.h>
#include <dplyr/tbl_cpp.h>
#include <dplyr/comparisons.h>
#include <dplyr/join_match.h>
#include <dplyr/MultipleVectorVisitors.h>
#include <dplyr/DataFrameSubsetVisitors.h>
#include <dplyr/subset_visitor.h>
#include <dplyr/subset_visitor_impl.h>
#include <dplyr/visitor.h>
#include <dplyr/visitor_impl.h>
#include <dplyr/OrderVisitorImpl.h>
#include <dplyr/JoinVisitor.h>
#include <dplyr/JoinVisitorImpl.h>
#include <dplyr/DataFrameJoinVisitors.h>
#include <dplyr/Order.h>
#include <dplyr/Hybrid.h>
#include <dplyr/default_value.h>
#include <dplyr/Result/all.h>
#include <dplyr/Gatherer.h>
#include <dplyr/Replicator.h>
#include <dplyr/Collecter.h>
#include <dplyr/NamedListAccumulator.h>
#include <dplyr/train.h>
#include <dplyr/Groups.h>
#endif // #ifndef dplyr_dplyr_dplyr_H
|
VictorHaine/r-packages-itau
|
Windows/Rcpp/include/Rcpp/sugar/functions/cbind.h
|
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// cbind.h: Rcpp R/C++ interface class library -- cbind
//
// Copyright (C) 2016 <NAME>
//
// This file is part of Rcpp.
//
// Rcpp is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Rcpp is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
#ifndef Rcpp__sugar__cbind_h
#define Rcpp__sugar__cbind_h
namespace Rcpp {
namespace sugar {
namespace cbind_impl {
// override r_sexptype_traits<SEXP> for STRSXP
template <typename T>
struct cbind_sexptype_traits
: public Rcpp::traits::r_sexptype_traits<T> {};
template <>
struct cbind_sexptype_traits<SEXP> {
enum { rtype = STRSXP };
};
// override storage_type<LGLSXP> (int)
template <int RTYPE>
struct cbind_storage_type
: public Rcpp::traits::storage_type<RTYPE> {};
template <>
struct cbind_storage_type<LGLSXP> {
typedef bool type;
};
// CRTP base
template <int RTYPE, typename E>
class BindableExpression {
public:
typedef typename cbind_storage_type<RTYPE>::type stored_type;
inline stored_type operator[](R_xlen_t i) const {
return static_cast<const E&>(*this)[i];
}
inline stored_type operator()(R_xlen_t i, R_xlen_t j) const {
return static_cast<const E&>(*this)(i, j);
}
inline R_xlen_t size() const {
return static_cast<const E&>(*this).size();
}
inline R_xlen_t nrow() const {
return static_cast<const E&>(*this).nrow();
}
inline R_xlen_t ncol() const {
return static_cast<const E&>(*this).ncol();
}
operator E&() { return static_cast<E&>(*this); }
operator const E&() const { return static_cast<const E&>(*this); }
};
// Matrix, Vector interface to BindableExpression
template <int RTYPE, typename T>
class ContainerBindable
: public BindableExpression<RTYPE, ContainerBindable<RTYPE, T> > {
public:
typedef typename cbind_storage_type<RTYPE>::type stored_type;
private:
T vec;
R_xlen_t len, nr, nc;
public:
ContainerBindable(const Rcpp::Matrix<RTYPE>& vec_)
: vec(vec_), len(vec.ncol() * vec.nrow()),
nr(vec.nrow()), nc(vec.ncol())
{}
ContainerBindable(const Rcpp::Vector<RTYPE>& vec_)
: vec(vec_), len(vec.size()),
nr(vec.size()), nc(1)
{}
template <typename S>
ContainerBindable(const BindableExpression<RTYPE, S>& e)
: vec(e.size()), len(e.size()),
nr(e.nrow()), nc(e.ncol())
{
for (R_xlen_t i = 0; i < len; i++) {
vec[i] = e[i];
}
}
inline R_xlen_t size() const { return len; }
inline R_xlen_t nrow() const { return nr; }
inline R_xlen_t ncol() const { return nc; }
inline stored_type operator[](R_xlen_t i) const {
return vec[i];
}
inline stored_type operator()(R_xlen_t i, R_xlen_t j) const {
return vec[i + nr * j];
}
};
template <int RTYPE>
struct scalar {
typedef typename cbind_storage_type<RTYPE>::type type;
};
// scalar interface to BindableExpression
template <typename T>
class ScalarBindable
: public BindableExpression<
cbind_sexptype_traits<T>::rtype, ScalarBindable<T> > {
public:
typedef T stored_type;
enum { RTYPE = cbind_sexptype_traits<T>::rtype };
private:
T t;
public:
ScalarBindable(const T& t_) : t(t_) {}
inline R_xlen_t size() const { return 1; }
inline R_xlen_t nrow() const { return 1; }
inline R_xlen_t ncol() const { return 1; }
inline stored_type operator[](R_xlen_t i) const {
return t;
}
inline stored_type operator()(R_xlen_t i, R_xlen_t j) const {
return t;
}
};
// binding logic; non-scalar operands
template <int RTYPE, typename E1, typename E2>
class JoinOp
: public BindableExpression<RTYPE, JoinOp<RTYPE, E1, E2> >,
public Rcpp::MatrixBase<RTYPE, true, JoinOp<RTYPE, E1, E2> > {
public:
typedef typename cbind_storage_type<RTYPE>::type stored_type;
private:
const E1& e1;
const E2& e2;
public:
JoinOp(const BindableExpression<RTYPE, E1>& e1_,
const BindableExpression<RTYPE, E2>& e2_)
: e1(e1_), e2(e2_)
{
if (e1.nrow() != e2.nrow()) {
std::string msg =
"Error in cbind: "
"Matrix and Vector operands "
"must have equal "
"number of rows (length).";
Rcpp::stop(msg);
}
}
inline R_xlen_t size() const { return e1.size() + e2.size(); }
inline R_xlen_t nrow() const { return e1.nrow(); }
inline R_xlen_t ncol() const { return e1.ncol() + e2.ncol(); }
inline stored_type operator[](R_xlen_t i) const {
return (i < e1.size()) ? e1[i] : e2[i - e1.size()];
}
inline stored_type operator()(R_xlen_t i, R_xlen_t j) const {
R_xlen_t index = i + nrow() * j;
return (*this)[index];
}
};
// binding logic; rhs scalar
template <int RTYPE, typename E1>
class JoinOp<RTYPE, E1, ScalarBindable<typename scalar<RTYPE>::type> >
: public BindableExpression<RTYPE,
JoinOp<RTYPE, E1,
ScalarBindable<typename scalar<RTYPE>::type> > >,
public Rcpp::MatrixBase<RTYPE, true,
JoinOp<RTYPE, E1,
ScalarBindable<typename scalar<RTYPE>::type> > > {
public:
typedef typename cbind_storage_type<RTYPE>::type stored_type;
typedef ScalarBindable<typename scalar<RTYPE>::type> E2;
private:
const E1& e1;
const E2& e2;
public:
JoinOp(const BindableExpression<RTYPE, E1>& e1_,
const BindableExpression<RTYPE, E2>& e2_)
: e1(e1_), e2(e2_)
{}
inline R_xlen_t size() const { return e1.size() + e1.nrow(); }
inline R_xlen_t nrow() const { return e1.nrow(); }
inline R_xlen_t ncol() const { return e1.ncol() + 1; }
inline stored_type operator[](R_xlen_t i) const {
return (i < e1.size()) ? e1[i] : e2[i];
}
inline stored_type operator()(R_xlen_t i, R_xlen_t j) const {
R_xlen_t index = i + nrow() * j;
return (*this)[index];
}
};
// binding logic; lhs scalar
template <int RTYPE, typename E2>
class JoinOp<RTYPE, ScalarBindable<typename scalar<RTYPE>::type>, E2>
: public BindableExpression<RTYPE,
JoinOp<RTYPE,
ScalarBindable<typename scalar<RTYPE>::type>, E2> >,
public Rcpp::MatrixBase<RTYPE, true,
JoinOp<RTYPE,
ScalarBindable<typename scalar<RTYPE>::type>, E2> > {
public:
typedef typename cbind_storage_type<RTYPE>::type stored_type;
typedef ScalarBindable<typename scalar<RTYPE>::type> E1;
private:
const E1& e1;
const E2& e2;
public:
JoinOp(const BindableExpression<RTYPE, E1>& e1_,
const BindableExpression<RTYPE, E2>& e2_)
: e1(e1_), e2(e2_)
{}
inline R_xlen_t size() const { return e2.size() + e2.nrow(); }
inline R_xlen_t nrow() const { return e2.nrow(); }
inline R_xlen_t ncol() const { return e2.ncol() + 1; }
inline stored_type operator[](R_xlen_t i) const {
return (i < e2.nrow()) ? e1[i] : e2[i - e2.nrow()];
}
inline stored_type operator()(R_xlen_t i, R_xlen_t j) const {
R_xlen_t index = i + nrow() * j;
return (*this)[index];
}
};
// binding logic; both scalar
template <int RTYPE>
class JoinOp<RTYPE, ScalarBindable<typename scalar<RTYPE>::type>,
ScalarBindable<typename scalar<RTYPE>::type> >
: public BindableExpression<RTYPE,
JoinOp<RTYPE,
ScalarBindable<typename scalar<RTYPE>::type>,
ScalarBindable<typename scalar<RTYPE>::type> > >,
public Rcpp::MatrixBase<RTYPE, true,
JoinOp<RTYPE,
ScalarBindable<typename scalar<RTYPE>::type>,
ScalarBindable<typename scalar<RTYPE>::type> > > {
public:
typedef typename cbind_storage_type<RTYPE>::type stored_type;
typedef ScalarBindable<typename scalar<RTYPE>::type> E1;
typedef ScalarBindable<typename scalar<RTYPE>::type> E2;
private:
const E1& e1;
const E2& e2;
public:
JoinOp(const BindableExpression<RTYPE, E1>& e1_,
const BindableExpression<RTYPE, E2>& e2_)
: e1(e1_), e2(e2_)
{}
inline R_xlen_t size() const { return e2.size() + e2.nrow(); }
inline R_xlen_t nrow() const { return e2.nrow(); }
inline R_xlen_t ncol() const { return e2.ncol() + 1; }
inline stored_type operator[](R_xlen_t i) const {
return (i < e2.nrow()) ? e1[i] : e2[i];
}
inline stored_type operator()(R_xlen_t i, R_xlen_t j) const {
R_xlen_t index = i + nrow() * j;
return (*this)[index];
}
};
// for template argument deduction
template <int RTYPE>
inline ContainerBindable<RTYPE, Rcpp::Matrix<RTYPE> >
MakeContainerBindable(const Rcpp::Matrix<RTYPE>& x) {
return ContainerBindable<RTYPE, Rcpp::Matrix<RTYPE> >(x);
}
template <int RTYPE>
inline ContainerBindable<RTYPE, Rcpp::Vector<RTYPE> >
MakeContainerBindable(const Rcpp::Vector<RTYPE>& x) {
return ContainerBindable<RTYPE, Rcpp::Vector<RTYPE> >(x);
}
template <>
inline ContainerBindable<LGLSXP, Rcpp::Matrix<LGLSXP> >
MakeContainerBindable(const Rcpp::Matrix<LGLSXP>& x) {
return ContainerBindable<LGLSXP, Rcpp::Matrix<LGLSXP> >(x);
}
template <>
inline ContainerBindable<LGLSXP, Rcpp::Vector<LGLSXP> >
MakeContainerBindable(const Rcpp::Vector<LGLSXP>& x) {
return ContainerBindable<LGLSXP, Rcpp::Vector<LGLSXP> >(x);
}
template <typename T>
inline ScalarBindable<T>
MakeScalarBindable(const T& t) {
return ScalarBindable<T>(t);
}
// for expressions of arbitrary length
template <int RTYPE, typename E1, typename E2>
inline JoinOp<RTYPE, E1, E2> operator,(
const BindableExpression<RTYPE, E1>& e1,
const BindableExpression<RTYPE, E2>& e2)
{
return JoinOp<RTYPE, E1, E2>(e1, e2);
}
// helpers
namespace detail {
// distinguish Matrix/Vector from scalar
template <typename T>
class has_stored_type {
private:
typedef char yes;
typedef struct {
char array[2];
} no;
template <typename C>
static yes test(typename C::stored_type*);
template <typename C>
static no test(...);
public:
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
};
// functor to dispatch appropriate Make*Bindable() call
template <typename T, bool is_container = has_stored_type<T>::value>
struct MakeBindableCall {};
template <typename T>
struct MakeBindableCall<T, true> {
typedef typename cbind_storage_type<
cbind_sexptype_traits<typename T::stored_type>::rtype
>::type stored_type;
enum { RTYPE = cbind_sexptype_traits<stored_type>::rtype };
ContainerBindable<RTYPE, T> operator()(const T& t) const {
return MakeContainerBindable(t);
}
};
// specialize for LGLSXP
template <>
struct MakeBindableCall<Rcpp::Matrix<LGLSXP>, true> {
typedef Rcpp::Matrix<LGLSXP> T;
typedef bool stored_type;
enum { RTYPE = cbind_sexptype_traits<stored_type>::rtype };
ContainerBindable<LGLSXP, T> operator()(const T& t) const {
return MakeContainerBindable(t);
}
};
template <>
struct MakeBindableCall<Rcpp::Vector<LGLSXP>, true> {
typedef Rcpp::Vector<LGLSXP> T;
typedef bool stored_type;
enum { RTYPE = cbind_sexptype_traits<stored_type>::rtype };
ContainerBindable<LGLSXP, T> operator()(const T& t) const {
return MakeContainerBindable(t);
}
};
template <typename T>
struct MakeBindableCall<T, false> {
enum { RTYPE = cbind_sexptype_traits<T>::rtype };
ScalarBindable<T> operator()(const T& t) const {
return MakeScalarBindable(t);
}
};
template <typename T>
inline typename Rcpp::traits::enable_if<
has_stored_type<T>::value,
MakeBindableCall<T, true>
>::type
MakeBindable(const T& t) {
return MakeBindableCall<T, true>();
}
template <typename T>
inline typename Rcpp::traits::enable_if<
!has_stored_type<T>::value,
MakeBindableCall<T, false>
>::type
MakeBindable(const T& t) {
return MakeBindableCall<T, false>();
}
// determine cbind return type from first template
// parameter, agnostic of Matrix/Vector/scalar
template <typename T, bool is_container = has_stored_type<T>::value>
struct matrix_return {};
template <typename T>
struct matrix_return<T, true> {
typedef typename cbind_storage_type<
cbind_sexptype_traits<typename T::stored_type>::rtype
>::type stored_type;
enum { RTYPE = cbind_sexptype_traits<stored_type>::rtype };
typedef Rcpp::Matrix<RTYPE> type;
};
// specialize for LGLSXP
// normally would default to IntegerMatrix
template <>
struct matrix_return<Rcpp::Matrix<LGLSXP>, true> {
typedef Rcpp::Matrix<LGLSXP> type;
};
template <>
struct matrix_return<Rcpp::Vector<LGLSXP>, true> {
typedef Rcpp::Matrix<LGLSXP> type;
};
template <>
struct matrix_return<bool, false> {
typedef Rcpp::Matrix<LGLSXP> type;
};
template <typename T>
struct matrix_return<T, false> {
enum { RTYPE = cbind_sexptype_traits<T>::rtype };
typedef Rcpp::Matrix<RTYPE> type;
};
} // detail
template <typename T, bool B = detail::has_stored_type<T>::value>
struct matrix_return
: public detail::matrix_return<T, B> {};
template <typename T>
struct matrix_return<T, false>
: public detail::matrix_return<T, false> {};
} // cbind_impl
#define MakeBindable(x) (cbind_impl::detail::MakeBindable(x)(x))
// begin cbind overloads
template<typename T1, typename T2>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2) {
return (MakeBindable(t1), MakeBindable(t2));
}
template<typename T1, typename T2, typename T3>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3));
}
template<typename T1, typename T2, typename T3, typename T4>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4));
}
// 5
template<typename T1, typename T2, typename T3, typename T4, typename T5>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9));
}
// 10
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14));
}
// 15
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19));
}
// 20
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24));
}
// 25
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29));
}
// 30
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34));
}
// 35
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39));
}
// 40
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43, typename T44>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43, const T44& t44) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43), MakeBindable(t44));
}
// 45
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43, typename T44, typename T45>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43, const T44& t44, const T45& t45) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43), MakeBindable(t44), MakeBindable(t45));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43, typename T44, typename T45, typename T46>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43, const T44& t44, const T45& t45, const T46& t46) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43), MakeBindable(t44), MakeBindable(t45), MakeBindable(t46));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43, typename T44, typename T45, typename T46, typename T47>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43, const T44& t44, const T45& t45, const T46& t46, const T47& t47) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43), MakeBindable(t44), MakeBindable(t45), MakeBindable(t46), MakeBindable(t47));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43, typename T44, typename T45, typename T46, typename T47, typename T48>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43, const T44& t44, const T45& t45, const T46& t46, const T47& t47, const T48& t48) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43), MakeBindable(t44), MakeBindable(t45), MakeBindable(t46), MakeBindable(t47), MakeBindable(t48));
}
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43, typename T44, typename T45, typename T46, typename T47, typename T48, typename T49>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43, const T44& t44, const T45& t45, const T46& t46, const T47& t47, const T48& t48, const T49& t49) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43), MakeBindable(t44), MakeBindable(t45), MakeBindable(t46), MakeBindable(t47), MakeBindable(t48), MakeBindable(t49));
}
// 50
template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename T21, typename T22, typename T23, typename T24, typename T25, typename T26, typename T27, typename T28, typename T29, typename T30, typename T31, typename T32, typename T33, typename T34, typename T35, typename T36, typename T37, typename T38, typename T39, typename T40, typename T41, typename T42, typename T43, typename T44, typename T45, typename T46, typename T47, typename T48, typename T49, typename T50>
inline typename cbind_impl::matrix_return<T1>::type
cbind(const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5, const T6& t6, const T7& t7, const T8& t8, const T9& t9, const T10& t10, const T11& t11, const T12& t12, const T13& t13, const T14& t14, const T15& t15, const T16& t16, const T17& t17, const T18& t18, const T19& t19, const T20& t20, const T21& t21, const T22& t22, const T23& t23, const T24& t24, const T25& t25, const T26& t26, const T27& t27, const T28& t28, const T29& t29, const T30& t30, const T31& t31, const T32& t32, const T33& t33, const T34& t34, const T35& t35, const T36& t36, const T37& t37, const T38& t38, const T39& t39, const T40& t40, const T41& t41, const T42& t42, const T43& t43, const T44& t44, const T45& t45, const T46& t46, const T47& t47, const T48& t48, const T49& t49, const T50& t50) {
return (MakeBindable(t1), MakeBindable(t2), MakeBindable(t3), MakeBindable(t4), MakeBindable(t5), MakeBindable(t6), MakeBindable(t7), MakeBindable(t8), MakeBindable(t9), MakeBindable(t10), MakeBindable(t11), MakeBindable(t12), MakeBindable(t13), MakeBindable(t14), MakeBindable(t15), MakeBindable(t16), MakeBindable(t17), MakeBindable(t18), MakeBindable(t19), MakeBindable(t20), MakeBindable(t21), MakeBindable(t22), MakeBindable(t23), MakeBindable(t24), MakeBindable(t25), MakeBindable(t26), MakeBindable(t27), MakeBindable(t28), MakeBindable(t29), MakeBindable(t30), MakeBindable(t31), MakeBindable(t32), MakeBindable(t33), MakeBindable(t34), MakeBindable(t35), MakeBindable(t36), MakeBindable(t37), MakeBindable(t38), MakeBindable(t39), MakeBindable(t40), MakeBindable(t41), MakeBindable(t42), MakeBindable(t43), MakeBindable(t44), MakeBindable(t45), MakeBindable(t46), MakeBindable(t47), MakeBindable(t48), MakeBindable(t49), MakeBindable(t50));
}
// end cbind overloads
#undef MakeBindable
} // sugar
namespace {
using sugar::cbind;
}
} // Rcpp
#endif // Rcpp__sugar__cbind_h
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/HybridHandler.h
|
<reponame>VictorHaine/r-packages-itau
#ifndef dplyr_dplyr_HybridHandler_H
#define dplyr_dplyr_HybridHandler_H
namespace dplyr {
class ILazySubsets;
class Result;
struct HybridHandler {
typedef dplyr::Result* (*HybridHandlerFun)(SEXP, const dplyr::ILazySubsets&, int);
enum Origin { DPLYR, STATS, BASE };
HybridHandlerFun handler ;
SEXP reference ;
Origin origin ;
HybridHandler():
handler(0),
reference(R_NilValue),
origin(DPLYR)
{}
HybridHandler(HybridHandlerFun handler_, Origin origin_, SEXP reference_):
handler(handler_),
reference(reference_),
origin(origin_)
{}
bool hybrid(SEXP symbol, SEXP rho) const;
};
}
void build_index_cpp_by_ref(DataFrame& data);
#endif // dplyr_dplyr_HybridHandlerMap_H
|
VictorHaine/r-packages-itau
|
Windows/RcppParallel/include/RcppParallel/Common.h
|
<filename>Windows/RcppParallel/include/RcppParallel/Common.h
#ifndef __RCPP_PARALLEL_COMMON__
#define __RCPP_PARALLEL_COMMON__
#include <cstddef>
namespace RcppParallel {
// Work executed within a background thread. We implement dynamic
// dispatch using vtables so we can have a stable type to cast
// to from the void* passed to the worker thread (required because
// the tinythreads interface allows to pass only a void* to the
// thread main rather than a generic type / template)
struct Worker
{
// construct and destruct (delete virtually)
Worker() {}
virtual ~Worker() {}
// dispatch work over a range of values
virtual void operator()(std::size_t begin, std::size_t end) = 0;
// disable copying and assignment
private:
Worker(const Worker&);
void operator=(const Worker&);
};
// Tag type used for disambiguating splitting constructors
struct Split {};
} // namespace RcppParallel
#endif // __RCPP_PARALLEL_COMMON__
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/Result/Sum.h
|
<reponame>VictorHaine/r-packages-itau<filename>Windows/dplyr/include/dplyr/Result/Sum.h
#ifndef dplyr_Result_Sum_H
#define dplyr_Result_Sum_H
#include <dplyr/Result/Processor.h>
namespace dplyr {
namespace internal {
template <int RTYPE, bool NA_RM, typename Index>
struct Sum {
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
static STORAGE process(typename Rcpp::traits::storage_type<RTYPE>::type* ptr, const Index& indices) {
long double res = 0;
int n = indices.size();
for (int i = 0; i < n; i++) {
double value = ptr[indices[i]];
// !NA_RM: we don't test for NA here because += NA will give NA
// this is faster in the most common case where there are no NA
// if there are NA, we could return quicker as in the version for
// INTSXP, but we would penalize the most common case
if (NA_RM && Rcpp::traits::is_na<RTYPE>(value)) {
continue;
}
res += value;
}
return (STORAGE)res;
}
};
// Special case for INTSXP:
template <bool NA_RM, typename Index>
struct Sum<INTSXP, NA_RM, Index> {
enum { RTYPE = INTSXP };
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
static STORAGE process(typename Rcpp::traits::storage_type<RTYPE>::type* ptr, const Index& indices) {
long double res = 0;
int n = indices.size();
for (int i = 0; i < n; i++) {
double value = ptr[indices[i]];
if (Rcpp::traits::is_na<RTYPE>(value)) {
if (NA_RM) {
continue;
}
return Rcpp::traits::get_na<RTYPE>();
}
res += value;
}
if (res > INT_MAX || res <= INT_MIN) {
warning("integer overflow - use sum(as.numeric(.))");
return Rcpp::traits::get_na<RTYPE>();
}
return (STORAGE)res;
}
};
} // namespace internal
template <int RTYPE, bool NA_RM>
class Sum : public Processor< RTYPE, Sum<RTYPE, NA_RM> > {
public:
typedef Processor< RTYPE, Sum<RTYPE, NA_RM> > Base;
typedef typename Rcpp::traits::storage_type<RTYPE>::type STORAGE;
Sum(SEXP x) :
Base(x),
data_ptr(Rcpp::internal::r_vector_start<RTYPE>(x))
{}
~Sum() {}
inline STORAGE process_chunk(const SlicingIndex& indices) {
return internal::Sum<RTYPE, NA_RM, SlicingIndex>::process(data_ptr, indices);
}
STORAGE* data_ptr;
};
}
#endif
|
VictorHaine/r-packages-itau
|
Windows/RcppParallel/include/RcppParallel/TBB.h
|
<filename>Windows/RcppParallel/include/RcppParallel/TBB.h
#ifndef __RCPP_PARALLEL_TBB__
#define __RCPP_PARALLEL_TBB__
#include "Common.h"
#include <tbb/tbb.h>
#include <tbb/scalable_allocator.h>
namespace RcppParallel {
namespace {
struct TBBWorker
{
explicit TBBWorker(Worker& worker) : worker_(worker) {}
void operator()(const tbb::blocked_range<size_t>& r) const {
worker_(r.begin(), r.end());
}
private:
Worker& worker_;
};
template <typename Reducer>
struct TBBReducer
{
explicit TBBReducer(Reducer& reducer)
: pSplitReducer_(NULL), reducer_(reducer)
{
}
TBBReducer(TBBReducer& tbbReducer, tbb::split)
: pSplitReducer_(new Reducer(tbbReducer.reducer_, RcppParallel::Split())),
reducer_(*pSplitReducer_)
{
}
virtual ~TBBReducer() { delete pSplitReducer_; }
void operator()(const tbb::blocked_range<size_t>& r) {
reducer_(r.begin(), r.end());
}
void join(const TBBReducer& tbbReducer) {
reducer_.join(tbbReducer.reducer_);
}
private:
Reducer* pSplitReducer_;
Reducer& reducer_;
};
} // anonymous namespace
inline void tbbParallelFor(std::size_t begin, std::size_t end,
Worker& worker, std::size_t grainSize = 1) {
TBBWorker tbbWorker(worker);
tbb::parallel_for(tbb::blocked_range<size_t>(begin, end, grainSize),
tbbWorker);
}
template <typename Reducer>
inline void tbbParallelReduce(std::size_t begin, std::size_t end,
Reducer& reducer, std::size_t grainSize = 1) {
TBBReducer<Reducer> tbbReducer(reducer);
tbb::parallel_reduce(tbb::blocked_range<size_t>(begin, end, grainSize),
tbbReducer);
}
} // namespace RcppParallel
#endif // __RCPP_PARALLEL_TBB__
|
VictorHaine/r-packages-itau
|
Windows/dplyr/include/dplyr/Result/Sd.h
|
<filename>Windows/dplyr/include/dplyr/Result/Sd.h
#ifndef dplyr_Result_Sd_H
#define dplyr_Result_Sd_H
#include <dplyr/Result/Processor.h>
namespace dplyr {
template <int RTYPE, bool NA_RM>
class Sd : public Processor<REALSXP, Sd<RTYPE, NA_RM> > {
public:
typedef Processor<REALSXP, Sd<RTYPE, NA_RM> > Base;
Sd(SEXP x) :
Base(x),
var(x)
{}
~Sd() {}
inline double process_chunk(const SlicingIndex& indices) {
return sqrt(var.process_chunk(indices));
}
private:
Var<RTYPE, NA_RM> var;
};
}
#endif
|
superwofy/F-ZBE-TO-E
|
src/mcp_can.h
|
<reponame>superwofy/F-ZBE-TO-E
/*
mcp_can_dfs.h
2012 Copyright (c) Seeed Technology Inc. All right reserved.
2017 Copyright (c) <NAME> All Rights Reserved.
Author:Loovee
Contributor: <NAME>
2017-09-25
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-
1301 USA
*/
#ifndef _MCP2515DFS_H_
#define _MCP2515DFS_H_
#include <Arduino.h>
#include <SPI.h>
#include <inttypes.h>
#ifndef INT32U
#define INT32U unsigned long
#endif
#ifndef INT8U
#define INT8U byte
#endif
/*
* Begin mt
*/
#define TIMEOUTVALUE 50
#define MCP_SIDH 0
#define MCP_SIDL 1
#define MCP_EID8 2
#define MCP_EID0 3
#define MCP_TXB_EXIDE_M 0x08 /* In TXBnSIDL */
#define MCP_DLC_MASK 0x0F /* 4 LSBits */
#define MCP_RTR_MASK 0x40 /* (1<<6) Bit 6 */
#define MCP_RXB_RX_ANY 0x60
#define MCP_RXB_RX_EXT 0x40
#define MCP_RXB_RX_STD 0x20
#define MCP_RXB_RX_STDEXT 0x00
#define MCP_RXB_RX_MASK 0x60
#define MCP_RXB_BUKT_MASK (1<<2)
/*
** Bits in the TXBnCTRL registers.
*/
#define MCP_TXB_TXBUFE_M 0x80
#define MCP_TXB_ABTF_M 0x40
#define MCP_TXB_MLOA_M 0x20
#define MCP_TXB_TXERR_M 0x10
#define MCP_TXB_TXREQ_M 0x08
#define MCP_TXB_TXIE_M 0x04
#define MCP_TXB_TXP10_M 0x03
#define MCP_TXB_RTR_M 0x40 /* In TXBnDLC */
#define MCP_RXB_IDE_M 0x08 /* In RXBnSIDL */
#define MCP_RXB_RTR_M 0x40 /* In RXBnDLC */
#define MCP_STAT_RXIF_MASK (0x03)
#define MCP_STAT_RX0IF (1<<0)
#define MCP_STAT_RX1IF (1<<1)
#define MCP_EFLG_RX1OVR (1<<7)
#define MCP_EFLG_RX0OVR (1<<6)
#define MCP_EFLG_TXBO (1<<5)
#define MCP_EFLG_TXEP (1<<4)
#define MCP_EFLG_RXEP (1<<3)
#define MCP_EFLG_TXWAR (1<<2)
#define MCP_EFLG_RXWAR (1<<1)
#define MCP_EFLG_EWARN (1<<0)
#define MCP_EFLG_ERRORMASK (0xF8) /* 5 MS-Bits */
#define MCP_BxBFS_MASK 0x30
#define MCP_BxBFE_MASK 0x0C
#define MCP_BxBFM_MASK 0x03
#define MCP_BxRTS_MASK 0x38
#define MCP_BxRTSM_MASK 0x07
/*
* Define MCP2515 register addresses
*/
#define MCP_RXF0SIDH 0x00
#define MCP_RXF0SIDL 0x01
#define MCP_RXF0EID8 0x02
#define MCP_RXF0EID0 0x03
#define MCP_RXF1SIDH 0x04
#define MCP_RXF1SIDL 0x05
#define MCP_RXF1EID8 0x06
#define MCP_RXF1EID0 0x07
#define MCP_RXF2SIDH 0x08
#define MCP_RXF2SIDL 0x09
#define MCP_RXF2EID8 0x0A
#define MCP_RXF2EID0 0x0B
#define MCP_BFPCTRL 0x0C
#define MCP_TXRTSCTRL 0x0D
#define MCP_CANSTAT 0x0E
#define MCP_CANCTRL 0x0F
#define MCP_RXF3SIDH 0x10
#define MCP_RXF3SIDL 0x11
#define MCP_RXF3EID8 0x12
#define MCP_RXF3EID0 0x13
#define MCP_RXF4SIDH 0x14
#define MCP_RXF4SIDL 0x15
#define MCP_RXF4EID8 0x16
#define MCP_RXF4EID0 0x17
#define MCP_RXF5SIDH 0x18
#define MCP_RXF5SIDL 0x19
#define MCP_RXF5EID8 0x1A
#define MCP_RXF5EID0 0x1B
#define MCP_TEC 0x1C
#define MCP_REC 0x1D
#define MCP_RXM0SIDH 0x20
#define MCP_RXM0SIDL 0x21
#define MCP_RXM0EID8 0x22
#define MCP_RXM0EID0 0x23
#define MCP_RXM1SIDH 0x24
#define MCP_RXM1SIDL 0x25
#define MCP_RXM1EID8 0x26
#define MCP_RXM1EID0 0x27
#define MCP_CNF3 0x28
#define MCP_CNF2 0x29
#define MCP_CNF1 0x2A
#define MCP_CANINTE 0x2B
#define MCP_CANINTF 0x2C
#define MCP_EFLG 0x2D
#define MCP_TXB0CTRL 0x30
#define MCP_TXB1CTRL 0x40
#define MCP_TXB2CTRL 0x50
#define MCP_RXB0CTRL 0x60
#define MCP_RXB0SIDH 0x61
#define MCP_RXB1CTRL 0x70
#define MCP_RXB1SIDH 0x71
#define MCP_TX_INT 0x1C /* Enable all transmit interrup ts */
#define MCP_TX01_INT 0x0C /* Enable TXB0 and TXB1 interru pts */
#define MCP_RX_INT 0x03 /* Enable receive interrupts */
#define MCP_NO_INT 0x00 /* Disable all interrupts */
#define MCP_TX01_MASK 0x14
#define MCP_TX_MASK 0x54
/*
* Define SPI Instruction Set
*/
#define MCP_WRITE 0x02
#define MCP_READ 0x03
#define MCP_BITMOD 0x05
#define MCP_LOAD_TX0 0x40
#define MCP_LOAD_TX1 0x42
#define MCP_LOAD_TX2 0x44
#define MCP_RTS_TX0 0x81
#define MCP_RTS_TX1 0x82
#define MCP_RTS_TX2 0x84
#define MCP_RTS_ALL 0x87
#define MCP_READ_RX0 0x90
#define MCP_READ_RX1 0x94
#define MCP_READ_STATUS 0xA0
#define MCP_RX_STATUS 0xB0
#define MCP_RESET 0xC0
/*
* CANCTRL Register Values
*/
#define MCP_NORMAL 0x00
#define MCP_SLEEP 0x20
#define MCP_LOOPBACK 0x40
#define MCP_LISTENONLY 0x60
#define MODE_CONFIG 0x80
#define MODE_POWERUP 0xE0
#define MODE_MASK 0xE0
#define ABORT_TX 0x10
#define MODE_ONESHOT 0x08
#define CLKOUT_ENABLE 0x04
#define CLKOUT_DISABLE 0x00
#define CLKOUT_PS1 0x00
#define CLKOUT_PS2 0x01
#define CLKOUT_PS4 0x02
#define CLKOUT_PS8 0x03
/*
* CNF1 Register Values
*/
#define SJW1 0x00
#define SJW2 0x40
#define SJW3 0x80
#define SJW4 0xC0
/*
* CNF2 Register Values
*/
#define BTLMODE 0x80
#define SAMPLE_1X 0x00
#define SAMPLE_3X 0x40
/*
* CNF3 Register Values
*/
#define SOF_ENABLE 0x80
#define SOF_DISABLE 0x00
#define WAKFIL_ENABLE 0x40
#define WAKFIL_DISABLE 0x00
/*
* CANINTF Register Bits
*/
#define MCP_RX0IF 0x01
#define MCP_RX1IF 0x02
#define MCP_TX0IF 0x04
#define MCP_TX1IF 0x08
#define MCP_TX2IF 0x10
#define MCP_ERRIF 0x20
#define MCP_WAKIF 0x40
#define MCP_MERRF 0x80
/*
* Speed 8M
*/
#define MCP_8MHz_1000kBPS_CFG1 (0x00)
#define MCP_8MHz_1000kBPS_CFG2 (0xC0) /* Enabled SAM bit */
#define MCP_8MHz_1000kBPS_CFG3 (0x80) /* Sample point at 75% */
#define MCP_8MHz_500kBPS_CFG1 (0x00)
#define MCP_8MHz_500kBPS_CFG2 (0xD1) /* Enabled SAM bit */
#define MCP_8MHz_500kBPS_CFG3 (0x81) /* Sample point at 75% */
#define MCP_8MHz_250kBPS_CFG1 (0x80) /* Increased SJW */
#define MCP_8MHz_250kBPS_CFG2 (0xE5) /* Enabled SAM bit */
#define MCP_8MHz_250kBPS_CFG3 (0x83) /* Sample point at 75% */
#define MCP_8MHz_200kBPS_CFG1 (0x80) /* Increased SJW */
#define MCP_8MHz_200kBPS_CFG2 (0xF6) /* Enabled SAM bit */
#define MCP_8MHz_200kBPS_CFG3 (0x84) /* Sample point at 75% */
#define MCP_8MHz_125kBPS_CFG1 (0x81) /* Increased SJW */
#define MCP_8MHz_125kBPS_CFG2 (0xE5) /* Enabled SAM bit */
#define MCP_8MHz_125kBPS_CFG3 (0x83) /* Sample point at 75% */
#define MCP_8MHz_100kBPS_CFG1 (0x81) /* Increased SJW */
#define MCP_8MHz_100kBPS_CFG2 (0xF6) /* Enabled SAM bit */
#define MCP_8MHz_100kBPS_CFG3 (0x84) /* Sample point at 75% */
/*
* speed 16M
*/
#define MCP_16MHz_1000kBPS_CFG1 (0x00)
#define MCP_16MHz_1000kBPS_CFG2 (0xCA)
#define MCP_16MHz_1000kBPS_CFG3 (0x81) /* Sample point at 75% */
#define MCP_16MHz_500kBPS_CFG1 (0x40) /* Increased SJW */
#define MCP_16MHz_500kBPS_CFG2 (0xE5)
#define MCP_16MHz_500kBPS_CFG3 (0x83) /* Sample point at 75% */
#define MCP_16MHz_250kBPS_CFG1 (0x41)
#define MCP_16MHz_250kBPS_CFG2 (0xE5)
#define MCP_16MHz_250kBPS_CFG3 (0x83) /* Sample point at 75% */
#define MCP_16MHz_200kBPS_CFG1 (0x41) /* Increased SJW */
#define MCP_16MHz_200kBPS_CFG2 (0xF6)
#define MCP_16MHz_200kBPS_CFG3 (0x84) /* Sample point at 75% */
#define MCP_16MHz_125kBPS_CFG1 (0x43) /* Increased SJW */
#define MCP_16MHz_125kBPS_CFG2 (0xE5)
#define MCP_16MHz_125kBPS_CFG3 (0x83) /* Sample point at 75% */
#define MCP_16MHz_100kBPS_CFG1 (0x44) /* Increased SJW */
#define MCP_16MHz_100kBPS_CFG2 (0xE5)
#define MCP_16MHz_100kBPS_CFG3 (0x83) /* Sample point at 75% */
#define MCPDEBUG (0)
#define MCPDEBUG_TXBUF (0)
#define MCP_N_TXBUFFERS (3)
#define MCP_RXBUF_0 (MCP_RXB0SIDH)
#define MCP_RXBUF_1 (MCP_RXB1SIDH)
#define MCP2515_SELECT() digitalWrite(MCPCS, LOW)
#define MCP2515_UNSELECT() digitalWrite(MCPCS, HIGH)
#define MCP2515_OK (0)
#define MCP2515_FAIL (1)
#define MCP_ALLTXBUSY (2)
#define CANDEBUG 1
#define CANUSELOOP 0
#define CANSENDTIMEOUT (200) /* milliseconds */
/*
* initial value of gCANAutoProcess
*/
#define CANAUTOPROCESS (1)
#define CANAUTOON (1)
#define CANAUTOOFF (0)
#define CAN_STDID (0)
#define CAN_EXTID (1)
#define CANDEFAULTIDENT (0x55CC)
#define CANDEFAULTIDENTEXT (CAN_EXTID)
#define MCP_STDEXT 0 /* Standard and Extended */
#define MCP_STD 1 /* Standard IDs ONLY */
#define MCP_EXT 2 /* Extended IDs ONLY */
#define MCP_ANY 3 /* Disables Masks and Filters */
#define MCP_16MHZ 1
#define MCP_8MHZ 2
#define CAN_100KBPS 9
#define CAN_125KBPS 10
#define CAN_200KBPS 11
#define CAN_250KBPS 12
#define CAN_500KBPS 13
#define CAN_1000KBPS 14
#define CAN_OK (0)
#define CAN_FAILINIT (1)
#define CAN_FAILTX (2)
#define CAN_MSGAVAIL (3)
#define CAN_NOMSG (4)
#define CAN_CTRLERROR (5)
#define CAN_GETTXBFTIMEOUT (6)
#define CAN_SENDMSGTIMEOUT (7)
#define CAN_FAIL (0xff)
#define CAN_MAX_CHAR_IN_MESSAGE (8)
#define CAN_IS_EXTENDED 0x80000000
#define CAN_IS_REMOTE_REQUEST 0x40000000
#define CAN_EXTENDED_ID 0x1FFFFFFF
#endif
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
/*
mcp_can.h
2012 Copyright (c) Seeed Technology Inc. All right reserved.
2017 Copyright (c) <NAME> All Rights Reserved.
Author:Loovee
Contributor: <NAME>ler
2017-09-25
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-
1301 USA
*/
#ifndef _MCP2515_H_
#define _MCP2515_H_
#define MAX_CHAR_IN_MESSAGE 8
class MCP_CAN
{
private:
INT8U m_nExtFlg; // Identifier Type
// Extended (29 bit) or Standard (11 bit)
INT32U m_nID; // CAN ID
INT8U m_nDlc; // Data Length Code
INT8U m_nDta[MAX_CHAR_IN_MESSAGE]; // Data array
INT8U m_nRtr; // Remote request flag
INT8U m_nfilhit; // The number of the filter that matched the message
INT8U MCPCS; // Chip Select pin number
INT8U mcpMode; // Mode to return to after configurations are performed.
/*********************************************************************************************************
* mcp2515 driver function
*********************************************************************************************************/
// private:
private:
void mcp2515_reset(void); // Soft Reset MCP2515
INT8U mcp2515_readRegister(const INT8U address); // Read MCP2515 register
void mcp2515_readRegisterS(const INT8U address, // Read MCP2515 successive registers
INT8U values[],
const INT8U n);
void mcp2515_setRegister(const INT8U address, // Set MCP2515 register
const INT8U value);
void mcp2515_setRegisterS(const INT8U address, // Set MCP2515 successive registers
const INT8U values[],
const INT8U n);
void mcp2515_initCANBuffers(void);
void mcp2515_modifyRegister(const INT8U address, // Set specific bit(s) of a register
const INT8U mask,
const INT8U data);
INT8U mcp2515_readStatus(void); // Read MCP2515 Status
INT8U mcp2515_setCANCTRL_Mode(const INT8U newmode); // Set mode
INT8U mcp2515_requestNewMode(const INT8U newmode); // Set mode
INT8U mcp2515_configRate(const INT8U canSpeed, // Set baudrate
const INT8U canClock);
INT8U mcp2515_init(const INT8U canIDMode, // Initialize Controller
const INT8U canSpeed,
const INT8U canClock);
void mcp2515_write_mf( const INT8U mcp_addr, // Write CAN Mask or Filter
const INT8U ext,
const INT32U id );
void mcp2515_write_id( const INT8U mcp_addr, // Write CAN ID
const INT8U ext,
const INT32U id );
void mcp2515_read_id( const INT8U mcp_addr, // Read CAN ID
INT8U* ext,
INT32U* id );
void mcp2515_write_canMsg( const INT8U buffer_sidh_addr ); // Write CAN message
void mcp2515_read_canMsg( const INT8U buffer_sidh_addr); // Read CAN message
INT8U mcp2515_getNextFreeTXBuf(INT8U *txbuf_n); // Find empty transmit buffer
/*********************************************************************************************************
* CAN operator function
*********************************************************************************************************/
INT8U setMsg(INT32U id, INT8U rtr, INT8U ext, INT8U len, INT8U *pData); // Set message
INT8U clearMsg(); // Clear all message to zero
INT8U readMsg(); // Read message
INT8U sendMsg(); // Send message
public:
MCP_CAN(INT8U _CS);
INT8U begin(INT8U idmodeset, INT8U speedset, INT8U clockset); // Initilize controller prameters
INT8U init_Mask(INT8U num, INT8U ext, INT32U ulData); // Initilize Mask(s)
INT8U init_Mask(INT8U num, INT32U ulData); // Initilize Mask(s)
INT8U init_Filt(INT8U num, INT8U ext, INT32U ulData); // Initilize Filter(s)
INT8U init_Filt(INT8U num, INT32U ulData); // Initilize Filter(s)
void setSleepWakeup(INT8U enable); // Enable or disable the wake up interrupt (If disabled the MCP2515 will not be woken up by CAN bus activity)
INT8U setMode(INT8U opMode); // Set operational mode
INT8U sendMsgBuf(INT32U id, INT8U ext, INT8U len, INT8U *buf); // Send message to transmit buffer
INT8U sendMsgBuf(INT32U id, INT8U len, INT8U *buf); // Send message to transmit buffer
INT8U readMsgBuf(INT32U *id, INT8U *ext, INT8U *len, INT8U *buf); // Read message from receive buffer
INT8U readMsgBuf(INT32U *id, INT8U *len, INT8U *buf); // Read message from receive buffer
INT8U checkReceive(void); // Check for received data
INT8U checkError(void); // Check for errors
INT8U getError(void); // Check for errors
INT8U errorCountRX(void); // Get error count
INT8U errorCountTX(void); // Get error count
INT8U enOneShotTX(void); // Enable one-shot transmission
INT8U disOneShotTX(void); // Disable one-shot transmission
INT8U abortTX(void); // Abort queued transmission(s)
INT8U setGPO(INT8U data); // Sets GPO
INT8U getGPI(void); // Reads GPI
};
#endif
/*********************************************************************************************************
* END FILE
*********************************************************************************************************/
|
countingCrow/ph_fetch_hash
|
php_pHash.h
|
// insert the following before PHP_FUNCTION(ph_texthash);
#if HAVE_IMAGE_HASH
PHP_FUNCTION(ph_fetch_hash);
#if (PHP_MAJOR_VERSION >= 5)
ZEND_BEGIN_ARG_INFO_EX(ph_fetch_hash_arg_info, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
ZEND_ARG_INFO(0, h1)
ZEND_END_ARG_INFO()
#else /* PHP 4.x */
#define ph_fetch_hash_arg_info NULL
#endif
#endif /* HAVE_IMAGE_HASH */
|
Banananaman91/voxels
|
Voxelcpp/FReader/FileReader.h
|
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
namespace freader {
class FileReader{
public:
std::string ReadFile(std::string filePath);
};
}
|
Banananaman91/voxels
|
Voxelcpp/Renderer/Shader.h
|
#include "../ProjectMain/MainHeader.h"
namespace renderer{
class Shader{
public:
unsigned int ID;
//Constructor to generate the shader
Shader(std::string vertexPath, std::string fragmentPath);
//Activate the shader
void use() const;
//utility uniform functions
void SetBool(const std::string &name, bool value) const;
void SetInt(const std::string &name, int value) const;
void SetFloat(const std::string &name, float value) const;
void SetVec2(const std::string &name, const glm::vec2 &value) const;
void SetVec2(const std::string &name, float x, float y) const;
void SetVec3(const std::string &name, const glm::vec3 &value) const;
void SetVec3(const std::string &name, float x, float y, float z) const;
void SetVec4(const std::string &name, const glm::vec4 &value) const;
void SetVec4(const std::string &name, float x, float y, float z, float w) const;
void SetMat2(const std::string &name, const glm::mat2 &mat) const;
void SetMat3(const std::string &name, const glm::mat3 &mat) const;
void SetMat4(const std::string &name, const glm::mat4 &mat) const;
private:
void CheckCompileErrors(GLuint shader, std::string type);
};
}
|
Banananaman91/voxels
|
Voxelcpp/ProjectMain/MainHeader.h
|
<reponame>Banananaman91/voxels
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
|
Banananaman91/voxels
|
Voxelcpp/Renderer/RenderCube.h
|
#include "Vertex.h"
#include <array>
namespace renderer{
class RenderCube{
public:
const std::array<glm::vec3, 8> cubeVertices {
glm::vec3(0, 0, 0), //0
glm::vec3(1, 0, 0), //1
glm::vec3(1, 1, 0), //2
glm::vec3(0, 1, 0), //3
glm::vec3(0, 1, 1), //4
glm::vec3(1, 1, 1), //5
glm::vec3(1, 0, 1), //6
glm::vec3(0, 0, 1) //7
};
const std::array<glm::vec3, 6> cubeNormals {
glm::vec3(0.0f, 1.0f, 0.0f),
glm::vec3(0.0f, 0.0f, 1.0f),
glm::vec3(-1.0f, 0.0f, 0.0f),
glm::vec3(0.0f, -1.0f, 0.0f),
glm::vec3(1.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 0.0f, -1.0f)
};
std::array<unsigned int, 36> indices{
// Front
0, 2, 1,
0, 3, 2,
// Top
2, 3, 4,
2, 4, 5,
// Right
1, 2, 5,
1, 5, 6,
// Left
0, 7, 4,
0, 4, 3,
// Back
5, 4, 7,
5, 7, 6,
// Bottom
0, 6, 7,
0, 1, 6
};
const std::array<Vertex, 36> vertices = {
Vertex { cubeVertices[1], cubeNormals[0] },
Vertex { cubeVertices[2], cubeNormals[0] },
Vertex { cubeVertices[5], cubeNormals[0] },
Vertex { cubeVertices[6], cubeNormals[0] },
Vertex { cubeVertices[7], cubeNormals[1] },
Vertex { cubeVertices[4], cubeNormals[1] },
Vertex { cubeVertices[3], cubeNormals[1] },
Vertex { cubeVertices[0], cubeNormals[1] },
Vertex { cubeVertices[3], cubeNormals[2] },
Vertex { cubeVertices[4], cubeNormals[2] },
Vertex { cubeVertices[5], cubeNormals[2] },
Vertex { cubeVertices[2], cubeNormals[2] },
Vertex { cubeVertices[0], cubeNormals[3] },
Vertex { cubeVertices[1], cubeNormals[3] },
Vertex { cubeVertices[6], cubeNormals[3] },
Vertex { cubeVertices[7], cubeNormals[3] },
Vertex { cubeVertices[6], cubeNormals[3] },
Vertex { cubeVertices[5], cubeNormals[3] },
Vertex { cubeVertices[4], cubeNormals[3] },
Vertex { cubeVertices[7], cubeNormals[3] },
Vertex { cubeVertices[0], cubeNormals[3] },
Vertex { cubeVertices[3], cubeNormals[3] },
Vertex { cubeVertices[2], cubeNormals[3] },
Vertex { cubeVertices[1], cubeNormals[3] },
};
unsigned int VBO;
unsigned int VAO;
unsigned int EBO;
unsigned int NBO;
void CreateCube();
};
}
|
Banananaman91/voxels
|
Voxelcpp/ProjectMain/WindowRender.h
|
<filename>Voxelcpp/ProjectMain/WindowRender.h
#include "../Renderer/RenderCube.h"
#include "Camera.h"
#include <iostream>
#include <array>
using namespace renderer;
namespace ProjectMain {
class WindowRender{
public:
const float _width = 1920.0f;
const float _height = 1080.0f;
// glm::mat4 origin = glm::mat4(1.0f);
glm::mat4 model = glm::mat4(1.0f);
glm::mat4 view = glm::mat4(1.0f);
glm::mat4 projection = glm::mat4(1.0f);
glm::mat4 lightModel = glm::mat4(1.0f);
float scale = 1.0f;
glm::vec3 lightPos = glm::vec3(1.0f, 1.0f, 1.0f);
std::array<glm::vec3, 10> cubePositions = {
glm::vec3( 0.0f, 0.0f, 0.0f),
glm::vec3( 2.0f, 5.0f, -15.0f),
glm::vec3(-1.5f, -2.2f, -2.5f),
glm::vec3(-3.8f, -2.0f, -12.3f),
glm::vec3( 2.4f, -0.4f, -3.5f),
glm::vec3(-1.7f, 3.0f, -7.5f),
glm::vec3( 1.3f, -2.0f, -2.5f),
glm::vec3( 1.5f, 2.0f, -2.5f),
glm::vec3( 1.5f, 0.2f, -1.5f),
glm::vec3(-1.3f, 1.0f, -1.5f)
};
std::array<glm::mat4, 10> cubeMatrices = {
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
glm::mat4(1.0f),
};
//colours
glm::vec3 boxColour = glm::vec3(1.0f, 0.5f, 0.31f);
glm::vec3 lightColour = glm::vec3(1.0f, 1.0f, 1.0f);
//timing
float deltaTime = 0.0f;
float lastFrame = 0.0f;
float currentFrame = 0.0f;
//shader program
std::string vertPath = "../Shaders/VertexShader.glsl";
std::string fragPath = "../Shaders/FragmentShader.glsl";
std::string lightPath = "../Shaders/LightFragment.glsl";
std::shared_ptr<Shader> shaderProgram;
std::shared_ptr<Shader> lightProgram;
//methods
void processInput(GLFWwindow* window);
void Display();
void InitialiseShaders();
};
}
|
Banananaman91/voxels
|
Voxelcpp/Renderer/Vertex.h
|
<gh_stars>0
#include "Shader.h"
struct Vertex {
glm::vec3 pos;
glm::vec3 normal;
};
|
WalinnsAnalytics/walinns-ios-sdk
|
WalinnsAPI.framework/Headers/WalinnsSDK.h
|
<reponame>WalinnsAnalytics/walinns-ios-sdk<filename>WalinnsAPI.framework/Headers/WalinnsSDK.h
//
// WalinnsAnalytics.h
// WalinnsAnalytics
//
// Created by Walinns Innovation on 09/02/18.
// Copyright © 2018 Walinns Innovation. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <WalinnsSDK.h>
#import <WalinnsAPI.h>
#import <WAARCMacros.h>
#import <WAApiClient.h>
#import <WADefaultConst.h>
#import <WAUtils.h>
#import <UserDefaultsHelper.h>
#import <Reachability.h>
#import <WADeviceInfo.h>
#import <WAARCMacros.h>
//! Project version number for WalinnsAnalytics.
FOUNDATION_EXPORT double WalinnsAnalyticsVersionNumber;
//! Project version string for WalinnsAnalytics.
FOUNDATION_EXPORT const unsigned char WalinnsAnalyticsVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <WalinnsAnalytics/PublicHeader.h>
|
WalinnsAnalytics/walinns-ios-sdk
|
WalinnsAPI_Swift.framework/Headers/WalinnsAPI.h
|
//
// WalinnsAPI.h
// WalinnsAPI
//
// Created by Walinns Innovation on 22/02/18.
// Copyright © 2018 Walinns Innovation. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for WalinnsAPI.
FOUNDATION_EXPORT double WalinnsAPIVersionNumber;
//! Project version string for WalinnsAPI.
FOUNDATION_EXPORT const unsigned char WalinnsAPIVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <WalinnsAPI/PublicHeader.h>
|
WalinnsAnalytics/walinns-ios-sdk
|
StarterProject-ObjC/StarterProject-ObjC/AppDelegate.h
|
//
// AppDelegate.h
// StarterProject-ObjC
//
// Created by Walinns Innovation on 28/02/18.
// Copyright © 2018 Walinns Innovation. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
|
WalinnsAnalytics/walinns-ios-sdk
|
StarterProject-Swift/Pods/Target Support Files/WalinnsAPI-Swift/WalinnsAPI-Swift-umbrella.h
|
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#import "WalinnsAPI.h"
FOUNDATION_EXPORT double WalinnsAPI_SwiftVersionNumber;
FOUNDATION_EXPORT const unsigned char WalinnsAPI_SwiftVersionString[];
|
WalinnsAnalytics/walinns-ios-sdk
|
StarterProject-ObjC/StarterProject-ObjC/ViewController.h
|
//
// ViewController.h
// StarterProject-ObjC
//
// Created by Walinns Innovation on 28/02/18.
// Copyright © 2018 Walinns Innovation. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
|
hculpan/winprotz
|
src/mainpaint.c
|
#include "mainpaint.h"
#include <string.h>
#include <commctrl.h>
#include <stdio.h>
int cxClient = 0;
int cyClient = 0;
HWND childHwnd = NULL;
HWND reportHwnd = NULL;
HWND startPushButtonHwnd;
HWND stopPushButtonHwnd;
HWND writeLogHwnd;
HWND startingBacteriaHwnd;
HWND delayTrackHwnd;
HWND delayLabelHwnd;
HWND pauseButtonHwnd;
HWND resumeButtonHwnd;
HWND reseedTrackHwnd;
HWND reseedLabelHwnd;
HWND initBacteriaTrackHwnd;
HWND initBacteriaLabelHwnd;
HWND initBugsTrackHwnd;
HWND initBugsLabelHwnd;
char *delayText[] = {
"None",
"1 ms",
"2 ms",
"3 ms",
"5 ms",
"10 ms",
"50 ms",
"1/4 sec",
"1 sec"
};
char *reseedText[] = {
"1/10",
"2/5",
"1/3",
"1/2",
"2/3",
"3/4",
"1/1",
"2/1",
"3/1",
"5/1"
};
char *initBacteriaText[] = {
"1k",
"2.5k",
"5k",
"7.5k",
"10k",
"15k",
"20k",
"25k",
"50k",
"100k"
};
char *initBugsText[] = {
"1",
"5",
"10",
"20",
"50",
"100",
"150",
"200",
"300",
"500"
};
TEXTMETRIC tm;
VOID SimStopped() {
EnableWindow(startPushButtonHwnd, TRUE);
EnableWindow(stopPushButtonHwnd, FALSE);
EnableWindow(pauseButtonHwnd, FALSE);
EnableWindow(resumeButtonHwnd, FALSE);
EnableWindow(writeLogHwnd, TRUE);
EnableWindow(delayTrackHwnd, TRUE);
EnableWindow(reseedTrackHwnd, TRUE);
EnableWindow(initBacteriaTrackHwnd, TRUE);
EnableWindow(initBugsTrackHwnd, TRUE);
}
VOID SimRunning() {
EnableWindow(startPushButtonHwnd, FALSE);
EnableWindow(stopPushButtonHwnd, TRUE);
EnableWindow(pauseButtonHwnd, TRUE);
EnableWindow(resumeButtonHwnd, FALSE);
EnableWindow(writeLogHwnd, FALSE);
EnableWindow(delayTrackHwnd, FALSE);
EnableWindow(reseedTrackHwnd, FALSE);
EnableWindow(initBacteriaTrackHwnd, FALSE);
EnableWindow(initBugsTrackHwnd, FALSE);
}
VOID SimPaused() {
EnableWindow(startPushButtonHwnd, FALSE);
EnableWindow(stopPushButtonHwnd, TRUE);
EnableWindow(pauseButtonHwnd, FALSE);
EnableWindow(resumeButtonHwnd, TRUE);
EnableWindow(writeLogHwnd, FALSE);
EnableWindow(delayTrackHwnd, TRUE);
EnableWindow(reseedTrackHwnd, TRUE);
EnableWindow(initBacteriaTrackHwnd, FALSE);
EnableWindow(initBugsTrackHwnd, FALSE);
}
int getDelaySetting() {
return (int)SendMessage(delayTrackHwnd, TBM_GETPOS, 0, 0);
}
int getReseedSetting() {
return (int)SendMessage(reseedTrackHwnd, TBM_GETPOS, 0, 0);
}
int getInitBacteriaSetting() {
return (int)SendMessage(initBacteriaTrackHwnd, TBM_GETPOS, 0, 0);
}
int getInitBugsSetting() {
return (int)SendMessage(initBugsTrackHwnd, TBM_GETPOS, 0, 0);
}
// CreateTrackbar - creates and initializes a trackbar.
//
// Global variable
// g_hinst - instance handle
//
HWND WINAPI CreateTrackbar(
HWND hwnd, // handle of dialog box (parent window)
UINT iMin, // minimum value in trackbar range
UINT iMax, // maximum value in trackbar range
UINT iPos, // Initial value
UINT xPos,
UINT yPos,
UINT trackbarId,
HWND *trackHwnd,
HWND *labelHwnd) {
InitCommonControls(); // loads common control's DLL
*labelHwnd = CreateWindow("static", "ST_U",
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
xPos, yPos, 115, 30,
hwnd, (HMENU)(501),
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
*trackHwnd = CreateWindowEx(
0, // no extended styles
TRACKBAR_CLASS, // class name
"Trackbar Control", // title (caption)
WS_CHILD |
WS_VISIBLE |
TBS_AUTOTICKS, // style
xPos + 120, yPos, // position
160, 30, // size
hwnd, // parent window
(HMENU)trackbarId, // control identifier
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL // no WM_CREATE parameter
);
SendMessage(*trackHwnd, TBM_SETRANGE,
(WPARAM) TRUE, // redraw flag
(LPARAM) MAKELONG(iMin, iMax)); // min. & max. positions
SendMessage(*trackHwnd, TBM_SETPAGESIZE,
0, (LPARAM) 4); // new page size
SendMessage(*trackHwnd, TBM_SETPOS, TRUE, (LPARAM)iPos);
return *trackHwnd;
}
void handleDelayTrack(HWND hwnd) {
int pos;
char msg[50];
pos = getDelaySetting();
sprintf(msg, "Delay: %s", delayText[pos]);
SetWindowText(delayLabelHwnd, msg);
}
void handleReseedTrack(HWND hwnd) {
int pos;
char msg[50];
pos = getReseedSetting();
sprintf(msg, "Reseed: %s", reseedText[pos]);
SetWindowText(reseedLabelHwnd, msg);
}
void handleInitBacteriaTrack(HWND hwnd) {
int pos;
char msg[50];
pos = getInitBacteriaSetting();
sprintf(msg, "Bacteria: %s", initBacteriaText[pos]);
SetWindowText(initBacteriaLabelHwnd, msg);
}
void handleInitBugsTrack(HWND hwnd) {
int pos;
char msg[50];
pos = getInitBugsSetting();
sprintf(msg, "Bugs: %s", initBugsText[pos]);
SetWindowText(initBugsLabelHwnd, msg);
}
void onCreate(HWND hwnd, char *ChildWndClass, char *ReportWndClass) {
childHwnd = CreateWindow(
ChildWndClass,
NULL,
WS_CHILDWINDOW | WS_VISIBLE,
5, 5,
CHILD_WND_WIDTH, CHILD_WND_HEIGHT,
hwnd,
NULL,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
reportHwnd = CreateWindow(
ReportWndClass,
NULL,
WS_CHILDWINDOW | WS_VISIBLE,
CHILD_WND_WIDTH + 10, (CHILD_WND_HEIGHT + 5) - 100,
305, 100,
hwnd,
NULL,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL
);
startPushButtonHwnd = CreateWindow("button", "Start", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CHILD_WND_WIDTH + 30, 15, 60, 26, hwnd, (HMENU)IDC_START_BUTTON, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
pauseButtonHwnd = CreateWindow("button", "Pause", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CHILD_WND_WIDTH + 100, 15, 60, 26, hwnd, (HMENU)IDC_PAUSE_BUTTON, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
EnableWindow(pauseButtonHwnd, FALSE);
resumeButtonHwnd = CreateWindow("button", "Resume", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CHILD_WND_WIDTH + 170, 15, 60, 26, hwnd, (HMENU)IDC_RESUME_BUTTON, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
EnableWindow(resumeButtonHwnd, FALSE);
stopPushButtonHwnd = CreateWindow("button", "Stop", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
CHILD_WND_WIDTH + 240, 15, 60, 26, hwnd, (HMENU)IDC_STOP_BUTTON, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
EnableWindow(stopPushButtonHwnd, FALSE);
writeLogHwnd = CreateWindow("button", "Write log", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
CHILD_WND_WIDTH + 5 + 25, 55, 100, 26, hwnd, (HMENU)0, (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
CreateTrackbar(hwnd, 0, 8, 0, CHILD_WND_WIDTH + 30, 105, IDC_DELAY_TRACK, &delayTrackHwnd, &delayLabelHwnd);
handleDelayTrack(hwnd);
CreateTrackbar(hwnd, 0, 9, 6, CHILD_WND_WIDTH + 30, 150, IDC_DELAY_TRACK, &reseedTrackHwnd, &reseedLabelHwnd);
handleReseedTrack(hwnd);
CreateTrackbar(hwnd, 0, 9, 6, CHILD_WND_WIDTH + 30, 195, IDC_DELAY_TRACK, &initBacteriaTrackHwnd, &initBacteriaLabelHwnd);
handleInitBacteriaTrack(hwnd);
CreateTrackbar(hwnd, 0, 9, 3, CHILD_WND_WIDTH + 30, 240, IDC_DELAY_TRACK, &initBugsTrackHwnd, &initBugsLabelHwnd);
handleInitBugsTrack(hwnd);
InvalidateRect(childHwnd, NULL, TRUE);
InvalidateRect(reportHwnd, NULL, TRUE);
}
void paintMain(HDC hdc, HWND hwnd, PAINTSTRUCT *ps) {
}
|
hculpan/winprotz
|
src/boardpaint.h
|
#ifndef __BOARDPAINT_H__
#define __BOARDPAINT_H__
#include <windows.h>
void paintBoard(HDC hdc);
VOID Thread(PVOID pvoid);
VOID reportStuff(HWND hwnd, HDC hdc);
VOID rereadSimParams();
extern BOOL ThreadRun;
extern BOOL ThreadPaused;
extern long cycle;
extern int bugCount;
enum GeneModel {
dewdney,
simplified_ga,
};
typedef struct SimParams {
int toroidal;
int worldWidth;
int worldHeight;
int startingBacteria;
int startingBugs;
int reseedRate;
int delay;
enum GeneModel geneModel;
} SimParams;
#endif
|
hculpan/winprotz
|
src/main.c
|
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include <process.h>
//#include <stdio.h>
#include "mainpaint.h"
#include "boardpaint.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ReportWndProc(HWND, UINT, WPARAM, LPARAM);
static char szAppName[] = "WinProtz";
static char szChildName[] = "WinProtzChild";
static char szReportName[] = "WinProtzReport";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
// if(AllocConsole()) {
// freopen("CONOUT$", "w", stdout);
// }
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wndclass);
wndclass.lpfnWndProc = ChildWndProc;
wndclass.hIconSm = NULL;
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszClassName = szChildName;
wndclass.hIconSm = NULL;
RegisterClassEx(&wndclass);
wndclass.lpfnWndProc = ReportWndProc;
wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndclass.lpszClassName = szReportName;
RegisterClassEx(&wndclass);
hwnd = CreateWindow(szAppName,
"Win Protozoa",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_BORDER | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
1024,
738,
NULL,
NULL,
hInstance,
NULL );
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
switch (iMsg) {
case WM_CREATE:
onCreate(hwnd, szChildName, szReportName);
SimStopped();
return 0;
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
paintMain(hdc, hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
case WM_HSCROLL:
if ((HWND)lParam == delayTrackHwnd) {
handleDelayTrack(delayTrackHwnd);
} else if ((HWND)lParam == reseedTrackHwnd) {
handleReseedTrack(reseedTrackHwnd);
} else if ((HWND)lParam == initBacteriaTrackHwnd) {
handleInitBacteriaTrack(initBacteriaTrackHwnd);
} else if ((HWND)lParam == initBugsTrackHwnd) {
handleInitBugsTrack(initBugsTrackHwnd);
}
return 0;
case WM_COMMAND:
if (wParam == IDC_START_BUTTON) {
ThreadRun = TRUE;
SimRunning();
_beginthread(Thread, 0, NULL);
} else if (wParam == IDC_STOP_BUTTON) {
SimStopped();
ThreadRun = FALSE;
} else if (wParam == IDC_PAUSE_BUTTON) {
ThreadPaused = TRUE;
SimPaused();
} else if (wParam == IDC_RESUME_BUTTON) {
rereadSimParams();
ThreadPaused = FALSE;
SimRunning();
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
switch (iMsg) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
if (!ThreadRun) {
paintBoard(hdc);
}
EndPaint(hwnd, &ps);
return 0;
// case WM_ERASEBKGND:
// return 1;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
LRESULT CALLBACK ReportWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
HDC hdc;
PAINTSTRUCT ps;
switch (iMsg) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
reportStuff(hwnd, hdc);
EndPaint(hwnd, &ps);
return 0;
// case WM_ERASEBKGND:
// return 1;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
|
hculpan/winprotz
|
src/boardpaint.c
|
#include "boardpaint.h"
#include "mainpaint.h"
#include <stdlib.h>
#include <process.h>
#include <time.h>
#include <stdio.h>
#include <math.h>
HBITMAP backbuffer = NULL;
HDC backbuffDC = NULL;
COLORREF bacteriaColor = RGB(0, 255, 0);
int maxGeneValue = 6;
BOOL ThreadRun = FALSE;
BOOL ThreadPaused = FALSE;
FILE *outf;
SimParams simParams;
int delayChoices[] = {0, 1, 2, 3, 5, 10, 50, 250, 1000};
int reseedChoices[] = {10, 20, 33, 50, 66, 75, 100, 200, 300, 500};
int initBacteriaChoices[] = {1000, 2500, 5000, 7500, 10000, 15000, 20000, 25000, 50000, 100000};
int initBugChoices[] = {1, 5, 10, 20, 50, 100, 150, 200, 300, 500};
struct Bug {
int id;
int x;
int y;
int dir;
int health;
int age;
int parentId;
int geneTotal;
int brushIndex;
// For Dewdney gene model
int gene[6];
int geneWeight[6];
// For simplified_ga gene model
char *ga_genes;
int ga_genes_length;
int ga_op_index;
struct Bug *next;
struct Bug *prev;
};
COLORREF bugColor[] = {
RGB(100, 100, 255), // blue
RGB(255, 100, 100), // red
RGB(60, 196, 191), // cyan
RGB(255, 255, 255) // white
};
HBRUSH bugBrush[4];
struct Bug *firstBug;
struct Bug *currentBug;
int bugCount = 0;
int lastBugId = 1;
HBRUSH backgroundBrush;
long cycle;
// forward declarations
VOID assignBrushToBug(struct Bug *bug);
VOID startBugLoop() {
currentBug = firstBug;
}
struct Bug *nextBug() {
struct Bug *result = currentBug;
if (result) currentBug = result->next;
return result;
}
void updateBoard(HDC hdc) {
if (backbuffer) {
SelectObject(backbuffDC, backbuffer);
BitBlt(hdc, 0, 0, CHILD_WND_WIDTH, CHILD_WND_HEIGHT, backbuffDC, 0, 0, SRCCOPY);
}
}
void paintBoard(HDC hdc) {
HDC tempDC;
if (ThreadRun || backbuffer == NULL) return;
tempDC = CreateCompatibleDC(hdc);
SelectObject(tempDC, backbuffer);
BitBlt(hdc, 0, 0, CHILD_WND_WIDTH, CHILD_WND_HEIGHT, tempDC, 0, 0, SRCCOPY);
DeleteDC(tempDC);
}
VOID AddRandomBacteria() {
int x, y;
while (TRUE) {
x = rand()%CHILD_WND_WIDTH;
y = rand()%CHILD_WND_HEIGHT;
if (GetPixel(backbuffDC, x, y) != bacteriaColor) {
SetPixel(backbuffDC, x, y, bacteriaColor);
break;
}
}
}
VOID paintInitialBacteria(HDC hdc, int count) {
int i;
RECT rect;
if (!backbuffer) {
DeleteObject(backbuffer);
}
backbuffer = CreateCompatibleBitmap(hdc, CHILD_WND_WIDTH, CHILD_WND_HEIGHT);
rect.left = 0;
rect.right = CHILD_WND_WIDTH;
rect.top = 0;
rect.bottom = CHILD_WND_HEIGHT;
SelectObject(backbuffDC, backbuffer);
for (i = 0; i < count; i++) {
AddRandomBacteria();
}
}
VOID removeBacteria(int x, int y, struct Bug *bug) {
bug->health += 40;
if (bug->health > 1500) {
bug->health = 1500;
}
}
int px(int vx) {
if (vx < 0) {
return vx + simParams.worldWidth;
} else if (vx >= simParams.worldWidth - 1) {
return vx % simParams.worldWidth;
} else {
return vx;
}
}
int py(int vy) {
if (vy < 0) {
return vy + simParams.worldHeight;
} else if (vy >= simParams.worldHeight - 1) {
return vy % simParams.worldHeight;
} else {
return vy;
}
}
VOID bugsEatBacteria() {
int x, y;
struct Bug *bug;
startBugLoop();
while (bug = nextBug()) {
x = bug->x;
y = bug->y;
if (GetPixel(backbuffDC, px(x - 1), py(y - 1)) == bacteriaColor)
removeBacteria(px(x - 1), py(y - 1), bug);
if (GetPixel(backbuffDC, px(x ), py(y - 1)) == bacteriaColor)
removeBacteria(px(x ), py(y - 1), bug);
if (GetPixel(backbuffDC, px(x + 1), py(y - 1)) == bacteriaColor)
removeBacteria(px(x + 1), py(y - 1), bug);
if (GetPixel(backbuffDC, px(x - 1), py(y )) == bacteriaColor)
removeBacteria(px(x - 1), py(y ), bug);
if (GetPixel(backbuffDC, px(x ), py(y )) == bacteriaColor)
removeBacteria(px(x ), py(y ), bug);
if (GetPixel(backbuffDC, px(x + 1), py(y )) == bacteriaColor)
removeBacteria(px(x + 1), py(y ), bug);
if (GetPixel(backbuffDC, px(x - 1), py(y + 1)) == bacteriaColor)
removeBacteria(px(x - 1), py(y + 1), bug);
if (GetPixel(backbuffDC, px(x ), py(y + 1)) == bacteriaColor)
removeBacteria(px(x ), py(y + 1), bug);
if (GetPixel(backbuffDC, px(x + 1), py(y + 1)) == bacteriaColor)
removeBacteria(px(x + 1), py(y + 1), bug);
}
}
VOID writeOutBugInfo(struct Bug* bug) {
if (!outf) return;
fprintf(outf, "Bug %4d [parent: %4d, age: %8d, health: %4d, x: %3d, y: %3d]\n",
bug->id, bug->parentId, bug->age, bug->health, bug->x, bug->y);
if (simParams.geneModel == dewdney) {
fprintf(outf, " Genetics: %4d %4d %4d %4d %4d %4d\n",
bug->gene[0], bug->gene[1], bug->gene[2], bug->gene[3], bug->gene[4], bug->gene[5]);
fprintf(outf, " Weights : %4d %4d %4d %4d %4d %4d\n",
bug->geneWeight[0], bug->geneWeight[1], bug->geneWeight[2],
bug->geneWeight[3], bug->geneWeight[4], bug->geneWeight[5]);
} else {
fprintf(outf, " Genetics: %s [%d]\n", bug->ga_genes, bug->ga_genes_length);
}
}
VOID calculateBugWeights(struct Bug *bug) {
int i;
int gpow[6];
if (simParams.geneModel == simplified_ga) return;
bug->geneTotal = 0;
for (i = 0; i < 6; i++) {
gpow[i] = (int)pow(2, bug->gene[i]);
bug->geneTotal += gpow[i];
}
for (i = 0; i < 6; i++) {
bug->geneWeight[i] = (int)(((double)gpow[i] / (double)bug->geneTotal) * 100);
}
}
struct Bug *createNewBug() {
int x, y;
struct Bug *result = malloc(sizeof(struct Bug));
while (TRUE) {
x = rand()%CHILD_WND_WIDTH;
y = rand()%CHILD_WND_HEIGHT;
if (x > 0 && x < CHILD_WND_WIDTH - 1 && y > 0 && y < CHILD_WND_HEIGHT - 1) {
result->x = x;
result->y = y;
break;
}
}
result->ga_genes = NULL;
result->ga_genes_length = 0;
result->id = lastBugId++;
result->parentId = 0;
result->dir = rand()%6;
result->health = 800;
result->age = 0;
if (simParams.geneModel == dewdney) {
result->gene[0] = rand()%maxGeneValue;
result->gene[1] = rand()%maxGeneValue;
result->gene[2] = rand()%maxGeneValue;
result->gene[3] = rand()%maxGeneValue;
result->gene[4] = rand()%maxGeneValue;
result->gene[5] = rand()%maxGeneValue;
calculateBugWeights(result);
assignBrushToBug(result);
} else if (simParams.geneModel == simplified_ga) {
result->ga_genes_length = rand()%20 + 1;
result->ga_genes = (char *)malloc(result->ga_genes_length + 1);
for (x = 0; x < result->ga_genes_length; x++) {
result->ga_genes[x] = 48 + rand()%maxGeneValue;
}
result->ga_genes[result->ga_genes_length] = '\0';
result->ga_op_index = 0;
}
return result;
}
VOID moveBugs() {
struct Bug *bug;
startBugLoop();
while (bug = nextBug()) {
switch (bug->dir) {
case 0: bug->y += 2; break;
case 1: bug->x += 2; bug->y += 1; break;
case 2: bug->x += 2; bug->y -= 1; break;
case 3: bug->y -= 2; break;
case 4: bug->x -= 2; bug->y -= 1; break;
case 5: bug->x -= 2; bug->y += 1; break;
}
if (simParams.toroidal) {
if (bug->x < 0) {
bug->x += simParams.worldWidth;
} else if (bug->x >= simParams.worldWidth) {
bug->x -= simParams.worldWidth;
}
if (bug->y < 0) {
bug->y += simParams.worldHeight;
} else if (bug->y >= simParams.worldHeight) {
bug->y -= simParams.worldHeight;
}
} else {
// Bump walls
if (bug->x <= 0) {
bug->x = 1;
}
if (bug->x >= CHILD_WND_WIDTH - 1) {
bug->x = CHILD_WND_WIDTH - 2;
}
if (bug->y <= 0) {
bug->y = 1;
}
if (bug->y >= CHILD_WND_HEIGHT - 1) {
bug->y = CHILD_WND_HEIGHT - 2;
}
}
}
}
VOID drawBugsOnBoard(HBRUSH brush) {
RECT rect;
int x, y;
struct Bug *bug;
COLORREF color = RGB(0, 0, 0);
startBugLoop();
while (bug = nextBug()) {
if (bug->x <= 0 || bug->x >= simParams.worldWidth - 1 ||
bug->y <= 0 || bug->y >= simParams.worldHeight - 1
) {
if (!brush) {
color = bugColor[bug->brushIndex];
}
x = bug->x;
y = bug->y;
SetPixel(backbuffDC, px(x - 1), py(y - 1), color);
SetPixel(backbuffDC, px(x ), py(y - 1), color);
SetPixel(backbuffDC, px(x + 1), py(y - 1), color);
SetPixel(backbuffDC, px(x - 1), py(y ), color);
SetPixel(backbuffDC, px(x ), py(y ), color);
SetPixel(backbuffDC, px(x + 1), py(y ), color);
SetPixel(backbuffDC, px(x - 1), py(y + 1), color);
SetPixel(backbuffDC, px(x ), py(y + 1), color);
SetPixel(backbuffDC, px(x + 1), py(y + 1), color);
} else {
rect.left = bug->x - 1;
rect.top = bug->y - 1;
rect.right = bug->x + 2;
rect.bottom = bug->y + 2;
if (brush) {
FillRect(backbuffDC, &rect, brush);
} else {
FillRect(backbuffDC, &rect, bugBrush[bug->brushIndex]);
}
}
}
}
VOID eraseBugs() {
drawBugsOnBoard(backgroundBrush);
}
VOID drawBugs() {
drawBugsOnBoard(NULL);
}
VOID selectNewDirection() {
int i, num;
struct Bug *bug;
startBugLoop();
while (bug = nextBug()) {
if (simParams.geneModel == dewdney) {
num = rand()%100;
for (i = 0; i < 6; i++) {
num -= bug->geneWeight[i];
if (num <= 0) {
bug->dir = (bug->dir + i) % 6;
break;
}
}
} else if (simParams.geneModel == simplified_ga) {
//if (outf) fprintf(outf, "MOVE for cycle %d\n", cycle);
bug->dir = (bug->dir + (bug->ga_genes[bug->ga_op_index] - 48)) % 6;
//if (outf) fprintf(outf, " Using %d at %d to select new dir %d\n",
// bug->ga_genes[bug->ga_op_index] - 48, bug->ga_op_index, bug->dir);
bug->ga_op_index = (bug->ga_op_index + 1) % bug->ga_genes_length;
}
}
}
VOID insertAfter(struct Bug *bug, struct Bug *newBug) {
if (!newBug) return;
newBug->next = NULL;
newBug->prev = NULL;
if (!bug) {
firstBug = newBug;
} else {
if (bug->next) bug->next->prev = newBug;
newBug->next = bug->next;
newBug->prev = bug;
bug->next = newBug;
}
}
struct Bug * deleteBug(struct Bug *bug) {
struct Bug *result;
if (!bug) return NULL;
if (bug->prev) bug->prev->next = bug->next;
if (bug->next) bug->next->prev = bug->prev;
if (bug == firstBug) {
firstBug = bug->next;
if (firstBug) firstBug->prev = NULL;
}
result = bug->next;
if (bug->ga_genes) free(bug->ga_genes);
free(bug);
return result;
}
VOID mutateBug(struct Bug *bug) {
int i, gnum;
char tmpval;
char *tmp;
if (simParams.geneModel == dewdney) {
gnum = rand()%6;
i = rand()%100;
if (i < 34) {
bug->gene[gnum] = (bug->gene[gnum] + 1) % maxGeneValue;
} else if (i < 67){
bug->gene[gnum] = ((bug->gene[gnum] - 1) + maxGeneValue) % maxGeneValue;
}
calculateBugWeights(bug);
assignBrushToBug(bug);
} else if (simParams.geneModel == simplified_ga && bug->ga_genes) {
bug->ga_op_index = 0;
i = rand()%100;
if (i < 34 && bug->ga_genes_length > 1) { // Remove one
gnum = rand()%bug->ga_genes_length;
if (outf)
fprintf(outf, "Mutation for %d: Remove %d\n", bug->id, gnum);
tmp = (char *)malloc(bug->ga_genes_length);
if (gnum > 0) {
strncpy(tmp, bug->ga_genes, gnum);
}
if (gnum < bug->ga_genes_length - 1) {
strcpy(tmp + gnum, bug->ga_genes + gnum + 1);
} else {
tmp[bug->ga_genes_length] = '\0';
}
free(bug->ga_genes);
bug->ga_genes = tmp;
bug->ga_genes_length--;
} else if (i < 67) { // Add one
gnum = rand()%(bug->ga_genes_length + 1);
tmp = (char *)malloc(bug->ga_genes_length + 2);
if (gnum > 0) {
strncpy(tmp, bug->ga_genes, gnum);
}
tmp[gnum] = 48 + rand()%maxGeneValue;
if (outf)
fprintf(outf, "Mutation for %d: Add %s at %d\n", bug->id, tmp[gnum], gnum);
if (gnum < bug->ga_genes_length - 1) {
strcpy(tmp + gnum + 1, bug->ga_genes + gnum);
} else {
tmp[bug->ga_genes_length + 1] = '\0';
}
free(bug->ga_genes);
bug->ga_genes = tmp;
bug->ga_genes_length++;
} else { // Change existing
gnum = rand()%bug->ga_genes_length;
i = rand()%100;
tmpval = 48 - bug->ga_genes[gnum];
if (i < 51) {
bug->ga_genes[gnum] = 48 + ((tmpval + 1) % maxGeneValue);
} else {
bug->ga_genes[gnum] = 48 + (((tmpval - 1) + maxGeneValue) % maxGeneValue);
}
if (outf)
fprintf(outf, "Mutation for %d: Set %d from %s to %s\n", bug->id, gnum, 48 + tmpval, bug->ga_genes[gnum]);
}
}
}
VOID doCycleStuff() {
int i, gnum, parentId;
struct Bug *bug, *newBug;
startBugLoop();
bugCount = 0;
while (bug = nextBug()) {
bug->age += 1;
bug->health -= 1;
if (bug->health <= 0) {
if (outf) {
fprintf(outf, "Bug %d has died at age %d, how sad!\n", bug->id, bug->age);
}
bug = deleteBug(bug);
} else if (bug->health >= 1000 && bug->age >= 800) {
parentId = bug->id;
newBug = createNewBug();
newBug->parentId = parentId;
newBug->health = bug->health / 2;
newBug->age = 0;
newBug->x = bug->x;
newBug->y = bug->y;
newBug->dir = (bug->dir + 3) % 6;
// Copy dewdney genes
for (i = 0; i < 6; i++) {
newBug->gene[i] = bug->gene[i];
}
// Copy simplified_ga genes
if (bug->ga_genes) {
if (newBug->ga_genes) free(newBug->ga_genes);
newBug->ga_genes = (char *)malloc(bug->ga_genes_length + 1);
strcpy(newBug->ga_genes, bug->ga_genes);
newBug->ga_genes_length = bug->ga_genes_length;
}
mutateBug(newBug);
writeOutBugInfo(newBug);
bug->health = bug->health / 2;
bug->id = lastBugId++;
bug->parentId = parentId;
bug->age = 0;
mutateBug(bug);
writeOutBugInfo(bug);
insertAfter(bug, newBug);
bugCount += 2;
} else {
bugCount += 1;
}
}
}
VOID createInitialBugs(int startingBugCount) {
int i;
struct Bug *newBug = NULL, *lastBug = NULL;
for (i = 0; i < startingBugCount; i++) {
bugCount += 1;
newBug = createNewBug();
writeOutBugInfo(newBug);
insertAfter(lastBug, newBug);
lastBug = newBug;
}
}
VOID reportStuff(HWND hwnd, HDC hdc) {
char msg[100];
int len;
len = sprintf(msg, "Cycle: %d", cycle);
TextOut(hdc, 5, 5, msg, len);
len = sprintf(msg, "Bugs: %d", bugCount);
TextOut(hdc, 5, 35, msg, len);
if (outf) {
fprintf(outf, "Cycle: %8d, Bugs: %4d\n", cycle, bugCount);
}
}
VOID processBugs() {
eraseBugs();
doCycleStuff();
selectNewDirection();
moveBugs();
bugsEatBacteria();
drawBugs();
}
VOID assignBrushToBug(struct Bug *bug) {
if (bug->geneWeight[0] < 26) {
bug->brushIndex = 0;
} else if (bug->geneWeight[0] < 51) {
bug->brushIndex = 1;
} else if (bug->geneWeight[0] < 76) {
bug->brushIndex = 2;
} else {
bug->brushIndex = 3;
}
}
FILE *openNewLog() {
char fname[50];
time_t rawtime;
struct tm *td;
time(&rawtime);
td = localtime(&rawtime);
sprintf(fname, "winprot-%04d%02d%02d%02d%02d%02d.log",
td->tm_year + 1900, td->tm_mon, td->tm_mday, td->tm_hour, td->tm_min, td->tm_sec
);
free(td);
return fopen(fname, "w");
}
VOID rereadSimParams() {
simParams.delay = delayChoices[getDelaySetting()];
simParams.reseedRate = reseedChoices[getReseedSetting()];
}
VOID populateSimParams() {
simParams.toroidal = TRUE;
simParams.worldWidth = CHILD_WND_WIDTH;
simParams.worldHeight = CHILD_WND_HEIGHT;
simParams.startingBacteria = initBacteriaChoices[getInitBacteriaSetting()];
simParams.startingBugs = initBugChoices[getInitBugsSetting()];
simParams.reseedRate = reseedChoices[getReseedSetting()];
simParams.delay = delayChoices[getDelaySetting()];
simParams.geneModel = dewdney;
}
VOID Thread(PVOID pvoid) {
HDC hdc = GetDC(childHwnd);
struct Bug *bug, *nextBug;
time_t rtime;
int i, reseeding = 0;
if ((int)SendMessage(writeLogHwnd, BM_GETCHECK, 0, 0)) {
outf = openNewLog();
} else {
outf = NULL;
}
populateSimParams();
rtime = time(NULL);
if (outf) fprintf(outf, "Random seed: %u\n", rtime);
srand(rtime);
//srand(1);
for (i = 0; i < 4; i++) {
bugBrush[i] = CreateSolidBrush(bugColor[i]);
}
backgroundBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
// Initialize run variables
lastBugId = 1;
cycle = 0;
backbuffDC = CreateCompatibleDC(hdc);
createInitialBugs(simParams.startingBugs);
paintInitialBacteria(hdc, simParams.startingBacteria);
processBugs();
updateBoard(hdc);
InvalidateRect(reportHwnd, NULL, TRUE);
while (ThreadRun) {
while (ThreadPaused) {
Sleep(250);
}
if (simParams.delay) {
Sleep(simParams.delay);
}
reseeding += simParams.reseedRate;
while (reseeding >= 100) {
AddRandomBacteria();
reseeding -= 100;
}
processBugs();
if (bugCount <= 0) {
if (outf) {
fprintf(outf, "Cycle %8d: BUGAPOCALYPSE! All bugs died!\n", cycle);
}
break;
}
updateBoard(hdc);
// Generate report
if (cycle % 10 == 0) {
InvalidateRect(reportHwnd, NULL, TRUE);
}
cycle += 1;
}
// Final report to true things up
InvalidateRect(reportHwnd, NULL, TRUE);
DeleteDC(backbuffDC);
backbuffDC = NULL;
ReleaseDC(childHwnd, hdc);
DeleteObject(backgroundBrush);
DeleteObject(bugBrush[0]);
DeleteObject(bugBrush[1]);
DeleteObject(bugBrush[2]);
DeleteObject(bugBrush[3]);
if (outf) {
fclose(outf);
}
bug = firstBug;
while (bug) {
nextBug = bug->next;
free(bug);
bug = nextBug;
}
SimStopped();
ThreadRun = FALSE;
}
|
hculpan/winprotz
|
src/mainpaint.h
|
<reponame>hculpan/winprotz
#ifndef __MAINPAINT_H__
#define __MAINPAINT_H__
#include <windows.h>
extern int cxClient;
extern int cyClient;
extern HWND childHwnd;
extern HWND reportHwnd;
extern HWND startPushButtonHwnd;
extern HWND stopPushButtonHwnd;
extern HWND writeLogHwnd;
extern HWND delayTrackHwnd;
extern HWND reseedTrackHwnd;
extern HWND initBacteriaTrackHwnd;
extern HWND initBugsTrackHwnd;
#define CHILD_WND_WIDTH 700
#define CHILD_WND_HEIGHT 700
#define IDC_START_BUTTON 1
#define IDC_STOP_BUTTON 2
#define IDC_DELAY_TRACK 3
#define IDC_PAUSE_BUTTON 4
#define IDC_RESUME_BUTTON 5
void paintMain(HDC hdc, HWND hwnd, PAINTSTRUCT *ps);
void onCreate(HWND hwnd, char *ChildWndClass, char *ReportWndClass);
void handleDelayTrack(HWND hwnd);
void handleReseedTrack(HWND hwnd);
void handleInitBacteriaTrack(HWND hwnd);
void handleInitBugsTrack(HWND hwnd);
VOID SimStopped();
VOID SimRunning();
VOID SimPaused();
int getDelaySetting();
int getReseedSetting();
int getInitBacteriaSetting();
int getInitBugsSetting();
#endif
|
ioriayane/masterqtquick4
|
src/C4_Plugin/colorfulflower.h
|
<gh_stars>0
#ifndef COLORFULFLOWER_H
#define COLORFULFLOWER_H
#include "flower.h"
class ColorfulFlower : public Flower
{
Q_OBJECT
public:
explicit ColorfulFlower(Flower *parent = nullptr);
virtual void paint(QPainter *painter);
public slots:
signals:
};
#endif // COLORFULFLOWER_H
|
ioriayane/masterqtquick4
|
src/C4_Plugin/randomcolorgenerator.h
|
#ifndef RANDOMCOLORGENERATOR_H
#define RANDOMCOLORGENERATOR_H
#include <QObject>
#include <QQmlPropertyValueSource>
#include <QQmlProperty>
#include <QTimer>
class RandomColorGenerator : public QObject, public QQmlPropertyValueSource // [1]
{
Q_OBJECT
Q_INTERFACES(QQmlPropertyValueSource) // [2]
Q_PROPERTY(bool running MEMBER m_running WRITE setRunning NOTIFY runningChanged)
public:
explicit RandomColorGenerator(QObject *parent = nullptr);
//更新対象のプロパティの参照が指定されて呼び出される // [3]
virtual void setTarget(const QQmlProperty &prop);
signals:
void runningChanged(bool running);
public slots:
void setRunning(bool running);
//タイマーでプロパティの値を更新するスロット
void updateProperty();
private:
QQmlProperty m_targetProperty;
QTimer m_timer;
bool m_running;
};
#endif // RANDOMCOLORGENERATOR_H
|
ioriayane/masterqtquick4
|
src/C4_Plugin/flowerextension.h
|
#ifndef FLOWEREXTENSION_H
#define FLOWEREXTENSION_H
#include "flower.h"
class FlowerExtension : public QObject
{
Q_OBJECT
Q_PROPERTY(QColor complementaryColor
READ complementaryColor
WRITE setComplementaryColor
NOTIFY complementaryColorChanged) // [1]
public:
explicit FlowerExtension(QObject *parent = nullptr);
QColor complementaryColor() const;
signals:
void complementaryColorChanged(QColor complementaryColor);
public slots:
void setComplementaryColor(QColor complementaryColor);
private:
Flower *m_flower; // [2]
QColor m_complementaryColor;
};
#endif // FLOWEREXTENSION_H
|
ioriayane/masterqtquick4
|
src/C2-6_Plugin/flower.h
|
<filename>src/C2-6_Plugin/flower.h
#ifndef FLOWER_H
#define FLOWER_H
#include <QQuickPaintedItem>
#include <QPainter>
class Flower : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
QColor m_color;
QPointF rotatePoint(double x, double y, double rad);
public:
Flower(QQuickPaintedItem *parent = nullptr);
virtual void paint(QPainter *painter);
QColor color() const;
public slots:
void setColor(QColor color);
signals:
void colorChanged(QColor color);
};
#endif // FLOWER_H
|
ioriayane/masterqtquick4
|
src/C1-2_MakeByCPPExample/myitem.h
|
#ifndef MYITEM_H
#define MYITEM_H
#include <QQuickItem>
#include <QSGGeometryNode>
class MyItem : public QQuickItem
{
Q_OBJECT
public:
MyItem(QQuickItem *parent = nullptr)
: QQuickItem(parent)
{
//このフラグ設定でupdatePaintNodeが呼ばれるようになる [1]
setFlag(ItemHasContents, true);
}
protected:
//描画処理 [2]
virtual QSGNode *updatePaintNode(QSGNode *oldNode
, UpdatePaintNodeData *updatePaintNodeData){
//描画処理を記述
return oldNode;
}
signals:
public slots:
};
#endif // MYITEM_H
|
ioriayane/masterqtquick4
|
src/C4_Plugin/flower.h
|
<gh_stars>0
#ifndef FLOWER_H
#define FLOWER_H
#include <QQuickPaintedItem>
#include <QPainter>
class Flower : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
Q_PROPERTY(int petalCount READ petalCount WRITE setPetalCount
NOTIFY petalCountChanged REVISION 1) // [1]
QColor m_color;
int m_petalCount;
protected:
QPointF rotatePoint(double x, double y, double rad);
public:
Flower(QQuickPaintedItem *parent = nullptr);
virtual void paint(QPainter *painter);
Q_REVISION(2) Q_INVOKABLE void play(); // [2]
QColor color() const;
int petalCount() const;
public slots:
void setColor(QColor color);
void setPetalCount(int petalCount);
signals:
void colorChanged(QColor color);
void petalCountChanged(int petalCount);
};
#endif // FLOWER_H
|
EnricoPittini/Virtual-machine
|
src/esegui.c
|
<reponame>EnricoPittini/Virtual-machine
#include<stdio.h>
#include<stdlib.h>
#include"esegui.h"
/*Lo stack di interi deve essere di 64 KB ovvero 2^16 B. Un intero è 2^2 Byte: dunque lo stack è composto da 2^16/2^2= 2^14 interi.
Stack con 2^14 elementi, ovvero 16384*/
#define N_STACK 16384
#define N_MAX 2147483647 /*Numero intero massimo rappresentabile su 4 Byte (32 bit). 2147483647=2^31 - 1*/
/*Numero intero minimo rapresentabile su 4 Byte (32 bit). -2147483648=-2^31. */
#define N_MIN -2147483647 /*Numero intero minimo rapresentabile su 4 Byte (32 bit). -2147483648=-2^31.*/
/**************************STACK: PRIMITIVE*************************************************************************************************/
/* Definisco le primitive del mio stack. Lo stack deve essere di 64KB, ovvero 2^14 interi*/
tstack getempty(){/*funzione che ritorna uno stack vuoto*/
tstack risp;
risp.v=(int *)malloc(sizeof(int)*N_STACK);/*Alloco dinamicamente un vettore con 2^14=16384 elementi. Il campo v del mio stack punta
a questo vettore*/
/*controllare allocazione malloc*/
risp.sp=0;/*stack vuoto*/
return risp;
}
int isempty(tstack s){/*Funzione che mi dice se lo stack in input è vuoto*/
return s.sp==0;
}
int push(tstack *ps,int elem){/*Funzione che mette dentro lo stack puntato da ps l'intero elem. Restituisce 1 se inserimento riuscito, 0 se
stack pieno*/
if(ps->sp<16384){
ps->v[ps->sp]=elem;/*Mette nella prima posizione libera dello stack elem*/
ps->sp++;/*Prima posizione libera ora è la successiva*/
return 1;
}
else /*stack pieno*/
return 0;
}
int pop(tstack *ps,int *elem){/*Funzione che mette dentro la variabile puntata da elem l'ultimo elemento dello stack. Ritorna 1 se estrazione
riuscita, 0 se stack vuoto*/
if(!isempty(*ps)){
ps->sp--;/*Decremento sp. Ora la prima posizione libera dello stack è la precedente*/
*elem=ps->v[ps->sp];/*Metto dentro la variabile puntata da elem l'ultimo elemento dello stack*/
return 1;
}
else /*stack vuoto*/
return 0;
}
/****************************************************************************************************************************************/
/* esegui è una funzione che dato un vettore di interi arr, di dimensione dim, contenente le istruzioni e i parametri delle istruzioni del programma in
input, esegui queste istruzioni. */
void esegui(int *arr,int dim){
tstack s=getempty();/*Creo il mio stack, per ora vuoto*/
if(s.v!=NULL){/*Controllo che l'allocazione del vettore dinamico sia andata a buon fine*/
unsigned int ip=0;/*INSTRUCTION POINTER: variabile che mi indica la posizione di dove sono arrivato sull'array arr*/
int R[32];/*Array di 32 interi: sono i miei 32 registri. R è l'indirizzo di R0*/
int error=0;/*Variabile che mi dice se ci sono stati errori (error=1) oppure no (error=0):*/
while(arr[ip]!=0 && !error)/*continuo a eseguire le istruzioni finchè non raggiungo l'istruzione HALT (codificata con 0) e finchè
non ho trovato errori*/
if(!esegui_istruzione(arr,dim,&ip,&s,R))
error=1;
/*esegui_istruzione è una funzione che esegue l'istruzione con indice ip (dell'array arr). L'eseguire un'istruzione può comportare la
lettura/modifica di un registro (passo alla funzione R), o la lettura/mdofica dello stack (passo l'indirizzo dello stack s,
così posso modificarlo da dentro la funzione). Devo inoltre modificare ip in modo che sia l'indice della prossima istruzione
da eseguire : passo alla funzione l'indirizzo di ip, così posso modificarlo da dentro la funzione.
esegui_istruzione inoltre ritorna 0 in caso di errore, 1 altrimenti*/
free(s.v);/*Libero il vettore allocato dinamicamente*/
}
else/* Errore allocazione malloc*/
printf("ERRORE: allocazione dinamica non andata a buon fine\n");
}
/*esegui_istruzione è una funzione che esegue un'istruzione, interagendo e modificando opportunamente ip, R e lo stack. Ritorna 0 in caso di
errore, 1 altrimenti*/
int esegui_istruzione(int *arr,int dim,unsigned int *ip,tstack *ps,int *R){
int risp=0;/*variabile dove memorizzo la tipologia di errore incontrata. Se alla fine della funzione vale 0, allora non ci sono stati
errori. Se invece il suo valore è !=0, allora c'è stato un errore (identificato dal numero).
In caso di errore stampo sullo schermo il tipo di errore e lo segnalo al chiamante (così interrompo l'esecuzione)*/
int istr=arr[*ip];/*istr è una variabile che contiene il codice intero dell'istruzione attuale, ovvero quella con indice ip*/
/*Ora segue uno switch con vari casi per identificare il tipo di istruzione. Oltre ad eseguire l'istruzione, modifico opportunamente ip in modo
che sia l'indice della prossima istruzione da eseguire.
Inoltre, cerco di rilevare eventuali tipologie di errore*/
switch(istr){
case 1:{/*DISPLAY*/
if(arr[*ip+1]<0 || arr[*ip+1]>31)/*registro non valido*/
risp=7;
else{
printf("%d\n",R[arr[(*ip)+1]]);/*Stampo il contenuto del registro*/
*ip=(*ip)+2;/*La prossima istruzione da eseguire è la successiva, ovvero due posizioni dopo nell'array (salto anche
il parametro)*/
}
break;
}
case 2:{/*PRINT_STACK*/
int n=arr[(*ip)+1];/*Numero di elementi dello stack da stampare (è specificato come parametro)*/
int i=1,empty=0;/*i mi serve per contare il numero di elementi stampati, empty mi segnala se ho già stampato tutti gli elementi disponibili
nello stack. empty==1 elementi dello stack finiti, empty==0 elementi dello stack non finiti.*/
/*Ovviamente il caso in cui finiscano gli elementi dell'array può capitare solo nel caso in cui n (numero di elementi dello stack da
stampare) sia maggiore di sp (indice della prima posizione libera dello stack o in modo equivalente numero di elementi effettivamente
contenuti nello stack).
Il caso in cui n>sp abbiamo deciso di gestirlo segnalando un avviso, ma senza interrompere il programma (come invece facciamo con gli
errori). Stampiamo tutti gli elementi dello stack, diamo l'avviso e continuiamo a eseguire il programma*/
while(i<=n && !empty){/*Continuo a stampare elementi finchè mi è richiesto (i<=n) e finchè gli elementi dello stack non sono finiti
(empty!=0)*/
int index=ps->sp-i;/*Indice dell'elemento dello stack che sto per stampare*/
if(index>=0)/*Se l'indice è >=0 vuol dire che non sono finiti gli elementi dello stack*/
printf("%d: %d\n",index,ps->v[index]);/*Stampo l'indice e l'elemento dello stack*/
else{/*Elementi dello stack finiti*/
printf("ATTENZIONE: numero di elementi da stampare maggiore del numero di elementi nello stack\n");/*Stamp a schermo un avviso*/
empty=1;/*Elementi dello stack finiti: interrompo il ciclo*/
}
i++;/*Prossimo elemento da stampare*/
}
*ip=(*ip)+2;/*La prossima istruzione da eseguire è la successiva, ovvero due posizioni dopo nell'array (salto anche
il parametro)*/
break;
}
case 10:{/*PUSH*/
if(arr[*ip+1]<0 || arr[*ip+1]>31)/*registro non valido*/
risp=7;
else{
if(push(ps,R[arr[(*ip)+1]]))/*Metto nello stack il contenuto del registro che ho come parametro. La push restituisce
1 in caso di corretto inserimento nello stack */
*ip=(*ip)+2;/*istruzione successiva (2 posizioni dopo)*/
else/*stack pieno*/
risp=1;
}
break;
}
case 11:{/*POP*/
if(arr[*ip+1]<0 || arr[*ip+1]>31)/*registro non valido*/
risp=7;
else{
if(pop(ps,&R[arr[(*ip)+1]]))/*Tolgo dallo stack l'ultimo elemento inserito (LIFO) e lo metto nel registro che ho come
parametro. La pop restituisce 1 in caso di stack non vuoto, 0 altrimenti*/
*ip=(*ip)+2;/*Istruzione successiva (2 posizioni dopo)*/
else/*stack vuoto*/
risp=2;
}
break;
}
case 12:{/*MOV*/
if(arr[*ip+1]<0 || arr[*ip+1]>31)/*resistro non valido.*/
risp=7;
else{
R[arr[(*ip)+1]]=arr[(*ip)+2];/*Metto nel registro che ho come primo parametro il valore numerico che ho come secondo
parametro*/
*ip=(*ip)+3;/*Istruzione successiva (devo saltare due parametri)*/
}
break;
}
case 20:{/*CALL*/
if(arr[*ip+1]>=0 && arr[*ip+1]<=dim-1){/*Indice di salto corretto (prossima istruzione da eseguire ha indice compreso tra 0 e dim-1,
ovvero ha indice dentro l'array)*/
if(push(ps,(*ip)+2))/*Metto nello stack l'indice corrispondente all'istruzione successiva. Così quando torno dalla Funzione
al chiamante so dove tornare*/
*ip=arr[(*ip)+1];/*La prossima istruzione da eseguire non è la successiva ma quella con indice specificato come
parametro*/
else/*stack pieno*/
risp=1;
}
else/*Indice di salto non corretto, fuori dall'array contenente il programma*/
risp=9;
break;
}
case 21:{/*RET*/
int temp; /*serve perchè ip è unsigned int* mentre la pop come secondo parametro vuole un int* */
if(pop(ps,&temp)){/*Tolgo dallo stack l'ultimo elemento (indice di ritorno dalla funzione) e lo metto dentro temp*/
if(temp>=0 && temp<=dim-1)/*Indice di salto corretto, dentro l'array*/
*ip=temp;/*Metto il valore appena preso dentro a ip, ovvero l'indice della prossima istruzione da eseguire*/
else/*Indice di salto non corretto, fuori dall'array*/
risp=9;
}
else/*stack vuoto*/
risp=2;
break;
}
case 22:/*JMP*/
if(arr[*ip+1]>=0 && arr[*ip+1]<=dim-1)/*Indice di salto corretto, dentro l'array*/
*ip=arr[(*ip)+1];/*Indice della prossima istruzione da eseguire è specificato come parametro. E' un salto incondizionato*/
else/*Indice di salto nfuori dall'array*/
risp=9;
break;
case 23:{/*JZ*/
if(arr[*ip+1]>=0 && arr[*ip+1]<=dim-1){/*Indice di salto corretto, dentro l'array*/
int elem;
if(pop(ps,&elem))/*Tolgo l'ultimo elemento dello stack (sempre cje non sia vuoto) e lo metto dentro elem*/
if(elem==0)/*se elem è uguale a 0 allora salto (indice prossima istruzione è quello specificato come parametro).*/
/*Salto condizionato*/
*ip=arr[(*ip)+1];
else /*Se elem è diverso da 0 non salto: la prossima istruzione da eseguire è la successiva*/
*ip=(*ip)+2;/*Metto dentro a ip indice prossima istruzione da eseguire*/
else/*stack vuoto*/
risp=2;
}
else/*Indice di salto fuori dall'array*/
risp=9;
break;
}
case 24:{/*JPOS*/
if(arr[*ip+1]>=0 && arr[*ip+1]<=dim-1){/*Indice di salto corretto, dentro l'array*/
int elem;
if(pop(ps,&elem))/*Tolgo l'ultimo elemento dello stack (sempre che non sia vuoto) e lo metto dentro a elem*/
if(elem>0)/*Se elem è maggiore di 0 allora salto. Salto condizionato*/
*ip=arr[(*ip)+1];/*Indice prossima istruzione da eseguire specificata come parametro*/
else /*Se elem non è maggiore di 0 non salto: prossima istruzione da eseguire è la successiva*/
*ip=(*ip)+2;
else/*stack vuoto*/
risp=2;
}
else/*Indice di salto scorretto, fuori dall'array*/
risp=9;
break;
}
case 25:{/*JNEG*/
if(arr[*ip+1]>=0 && arr[*ip+1]<=dim-1){/*Indice di salto corretto, dentro l'array*/
int elem;
if(pop(ps,&elem))/*Tolgo l'ultimo elemento dello stack (sempre che non sia vuoto) e lo metto dentro a elem*/
if(elem<0)/*Se elem è minore di 0 allora salto. Salto condizionato*/
*ip=arr[(*ip)+1];/*Indice prossima istruzione da eseguire specificata come parametro*/
else /*Se elem non è minore di 0 non salto: prossima istruzione da eseguire è la successiva*/
*ip=(*ip)+2;
else/*stack vuoto*/
risp=2;
}
else/*Indice di salto scorretto, fuori dall'array*/
risp=9;
break;
}
case 30:{/*ADD*/
if(arr[*ip+1]<0 || arr[*ip+1]>31 || arr[*ip+2]<0 || arr[*ip+2]>32)/*registro non valido*/
risp=7;
else{
int p1=R[arr[*ip+1]];/*Primo operando (primo registro specificato come parametro)*/
int p2=R[arr[*ip+2]];/*Secondo operando (secondo registro specificato come parametro)*/
if(overflow(0,p1,p2))/*Chiamo la funzione overflow che ritorna 1 se c'è overflow. Prende come parametri il codice
dell'operazione (0 per somma, 1 per moltiplicazione) e i due parametri*/
risp=3;/*overflow somma*/
else{/*Non c'è overflow*/
int sum=p1+p2;/*somma tra gli operandi*/
if(push(ps,sum))/*Metto la somma nello stack (sempre che non sia pieno)*/
*ip=*ip+3;/*Prossima istruzione da eseguire è la successiva (2 parametri da saltare)*/
else/*stack pieno*/
risp=1;
}
}
break;
}
case 31:{/*SUB*/
if(arr[*ip+1]<0 || arr[*ip+1]>31 || arr[*ip+2]<0 || arr[*ip+2]>32)/*registro non valido*/
risp=7;
else{
int p1=R[arr[*ip+1]];/*Primo operando*/
int p2=R[arr[*ip+2]];/*Secondo operando*/
if(overflow(0,p1,-p2))/*Chiamo la funzione overflow e controllo se c'è overflow. Come codice di operazione metto 0, ovvero somma.
Controllare che p1-p2 non dia overflow è come controllare che p1+(-p2) non dia overflow*/
risp=4;/*overflow sottrazione*/
else{/*Non c'è overflow*/
int sub=p1-p2;/*Sottrazione tra i due operandi*/
if(push(ps,sub))/*Metto il risultato nello stack (sempre che non sia pieno)*/
*ip=*ip+3;/*Prossima istruzione da eseguire è la successiva (2 parametri da saltare)*/
else/*stack pieno*/
risp=1;
}
}
break;
}
case 32:{/*MUL*/
if(arr[*ip+1]<0 || arr[*ip+1]>31 || arr[*ip+2]<0 || arr[*ip+2]>32)/*registro non valido*/
risp=7;
else{
int p1=R[arr[*ip+1]];/*Primo operando*/
int p2=R[arr[*ip+2]];/*Secondo operando*/
if(overflow(1,p1,p2))/* Chiamo la funzione overflow e controllo che non ci sia overflow. Codice di operazione 1 (moltiplicazione)*/
risp=5;/*overflow moltiplicazione*/
else{/*Non c'è overflow*/
int mul=p1*p2;/*Eseguo la moltiplicazione*/
if(push(ps,mul))/*Metto il risultato nello stack(sempre che non sia pieno)*/
*ip=*ip+3;/*Prossima istruzione da eseguire è la successiva (2 parametri da saltare)*/
else/*stack pieno*/
risp=1;
}
}
break;
}
case 33:{/*DIV*/
if(arr[*ip+1]<0 || arr[*ip+1]>31 || arr[*ip+2]<0 || arr[*ip+2]>32)/*registro non valido*/
risp=7;
else{
int p1=R[arr[*ip+1]];/*Primo operando*/
int p2=R[arr[*ip+2]];/*Secondo operando*/
if(p2!=0){/*COntrollo che il secondo operando non sia 0*/
int div=p1/p2;/*Eseguo l'operazione*/
if(push(ps,div))/*Metto il risultato nello stack (sempre che non sia pieno)*/
*ip=*ip+3;/*Prossima istruzione da eseguire è la successiva (2 parametri da saltare)*/
else/*stack pieno*/
risp=1;
}
else/*divisione per zero*/
risp=6;
}
break;
}
default:
risp=8;/*istruzione non valida*/
break;
}
/*Ora vedo se c'è stato qualche errore e in caso lo identifico e lo stampo a schermo.*/
if(risp==1)
printf("ERRORE: stack pieno\n");
if(risp==2)
printf("ERRORE: stack vuoto\n");
if(risp==3)
printf("ERRORE: overflow somma\n");
if(risp==4)
printf("ERRORE: overflow sottrazione\n");
if(risp==5)
printf("ERRORE: overflow moltiplicazione\n");
if(risp==6)
printf("ERRORE: divisione per zero\n");
if(risp==7)
printf("ERRORE: registro non valido\n");
if(risp==8)
printf("ERRORE: istruzione non valida\n");
if(risp==9)
printf("ERRORE: indirizzo(indice) di salto non corretto\n");
return !risp;/*Ritorno 1 se non ci sono stati errori (risp==0), 0 altrimenti (risp!=0)*/
}
/*Funzione che restituisce 1 in caso di overflow, 0 altrimenti. Prende come parametri il codice numerico che rappresenta il tipo di
operazione e i due operandi.*/
int overflow(int op,int p1,int p2){/*op codice operazione, p1 primo parametro, p2 secondo parametro*/
if(op==0 && p1!=0 && p2!=0){/*overflow somma: op==0 (anche sottrazione è compresa). Se anche uno solo dei due operandi è 0 non testo
neanche l'overflow perche sicuramente il risultato dell'operazione sarà rappresentabile*/
int s1=(p1>0)?1:-1; /*In s1 metto il segno di p1*/
int s2=(p2>0)?1:-1;/*In s2 metto il segno di p2*/
if(s1*s2>0){/*Testo l'overflow solo se p1 e p2 hanno lo stesso segno: solo in questo caso può infatti verificarsi overflow*/
if(s1>0){/* Caso in cui p1>0 && p2>0. L'overflow può verificarsi superando il massimo numero positivo (N_MAX)*/
/*Devo testare se p1+p2>N_MAX senza però effettivamente svolgere l'operazione p1+p2 (se no appunto in caso di overflow il
risultato sarebbe sbagliato e verrebbe segnalato dal sistema C). Allora testo se p2>N_MAX-p1.*/
int temp=N_MAX-p1;/*Metto in una variabile temporanea N_MAX -p1*/
if(p2>temp)
return 1;/*overflow rilevato*/
}
else{/*Caso in cui p1<0 && p2<0. L'overflow può verificarsi se il risultato è minore del minore numero negativo (N_MIN)*/
/*Devo testare se p1+p2<N_MIN senza però effettivamente svolgere l'operazione p1+p2 (se no appunto in caso di overflow il
risultato sarebbe sbagliato e verrebbe segnalato dal sistema C). Allora testo se p2<N_MAX-p1.*/
int temp=N_MIN-1-p1;/*Metto in una variabile temporanea N_MIN-p1*/
if(p2<temp)
return 1;/*overflow rilevato*/
}
}
}
if(op==1 && p1!=0 && p2!=0 && p1!=1 && p2!=1){/*overflow moltiplicazione: op==1. Se anche uno solo dei due operandi è 0 o 1 non testo
neanche l'overflow perche sicuramente il risultato dell'operazione sarà rappresentabile*/
int s1=(p1>0)?1:-1;/*In s1 metto il segno di p1*/
int s2=(p2>0)?1:-1;/*In s2 metto il segno di p2*/
if(s1*s2>0){/*(p1>0 && p2>0) || (p1<0 && p2<0): in entrambi i casi l'overflow può verificarsi superando il più grande numero positivo*/
int temp;
p1=p1*s1;/*valore assoluto di p1*/
p2=p2*s2;/*valore assoluto di p2*/
/*Devo testare se p1*p2>N_MAX senza però effettivamente svolgere l'operazione p1*p2 (se no appunto in caso di overflow il
risultato sarebbe sbagliato e verrebbe segnalato dal sistema C). Allora testo se p1>N_MAX/p2.*/
temp=N_MAX/p2;/*Metto N_MAX/p2 in una variabile temporanea*/
if(p1>temp)
return 1;/*overflow rilevato*/
}
else{/*(p1<0 && p2>0) || (p1>0 && p2<0): in entrambi i casi l'overflow può verificarsi se il risultato è minore del minimo numero
negativo rappresentabile (N_MIN)*/
int temp;
p1=p1*s1;/*valore assoluto di p1*/
p2=p2*s2;/*valore assoluto di p2*/
/*Devo testare se p1*p2>-N_MIN senza però effettivamente svolgere l'operazione p1*p2 (se no appunto in caso di overflow il
risultato sarebbe sbagliato e verrebbe segnalato dal sistema C). Allora testo se p1>-N_MAX/p2.*/
temp=(N_MIN-1)/p2;
temp=-temp;/*attenzione, bisogna cambiare il segno. p1 e p2 sono entrambi valori assoluti*/
if(p1>temp)
return 1;/*overflow rilevato*/
}
}
return 0;/*nessun overflow trovato*/
}
|
EnricoPittini/Virtual-machine
|
src/vm.c
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"leggi.h"
#include"stampa.h"
#include"esegui.h"
int main(int argc,char *argv[]){
/*Il programma deve prendere due parametri da linea di comando: il primo (argv[1]) dice l'azione da svolgere, il secondo (argv[2])
è il nome del file contenete il programma da eseguire. I parametri da linea di comando (argv[1] e argv[2]) sono due stringhe.*/
int *arr=NULL; /*Variabile puntatore che punterà all'array contenete le istruzioni e i parametri delle istruzioni*/
int dim=0; /*Variabile intera che conterrà la dimensione dell'array arr*/
if(argc!=3)/*Controllo che il numero di parametri da linea di comando sia giusto*/
printf("ERRORE: il programma VM accetta due parametri da linea di comando\n");
else{
if(!strcmp(argv[1],"stampa")){
/*Se la stringa argv[1] è uguale alla stringa "stampa" allora devo stampare il programma in input nel suo formato mnemonico/assembler.
Uso la funzione di libreria strcmp per verificare che le stringhe siano uguali*/
if(leggi(argv[2],&arr,&dim)){/*leggi mette le istruzioni e i parametri delle istruzioni, presenti nel file con nome argv[2],
dentro l'array di interi arr,creato dinamicamente sempre dentro la funzione. Passo alla funzione gli indirizzi di arr e dim
perchè così posso modificarli da dentro la funzione. Alla fine dell'esecuzione della funzione arr conterrà l'indirizzo
dell'array dinamico contente le istruzioni e dim conterrà la sua dimensione.
leggi ritorna 1 in caso di successo, 0 altrimenti (qualsiasi tipo di errore).
I vari tipi di errore che possono esserci in lettura li gestico dentro la funzione leggi.
Vedi leggi.c*/
stampa(arr,dim);/*La funzione "stampa" stampa il formato mnemonico delle istruzioni che sono dentro l'array arr. Vedi stampa.c*/
free(arr);/*arr è un array dinamico: prima del termine del programma VM devo liberare lo spazio allocato dinamicamente*/
}
}
else if(!strcmp(argv[1],"esegui")){
/*Se la stringa argv[1] è uguale alla stringa "esegui" allora devo eseguire il programma in input. Uso come prima strcmp*/
if(leggi(argv[2],&arr,&dim)){/*Anche qua mi serve creare l'array con dentro le istruzioni e i loro parametri*/
esegui(arr,dim);/*La funzione esegui esegue le istruzioni presenti dentro l'array arr*/
free(arr);/*Libero il vettore dinamico arr*/
}
}
}
return 0;
}
|
EnricoPittini/Virtual-machine
|
src/leggi.c
|
<filename>src/leggi.c<gh_stars>0
#include<stdio.h>
#include<stdlib.h>
#include"leggi.h"
int control(char *buffer){ /*funzione che data la stringa contenente una riga acquisita dal file ,verifica se ci sono errori di formato. Se
sono presenti errori la funzione ritorna 1 altrimenti 0 */
int i=0; /* indice della stringa */
int flag=0; /* flag che indica se un ";" è stato trovato */
int flag1=0; /* flag che indica se un numero è stato trovato */
int err=0; /* variabile che segnala se c'è un errore di formato nella riga letta */
/* continua a controllare la stringa fino a quando o non è finita,o c'è un errore ,o
quando non trova un ";" (è stato determinato che prima del ";" sia tutto corretto */
while(buffer[i]!='\0' && err==0 && flag==0){
/* se ha trovato un ";" mette a 1 un flag che segnala che ha trovato un ";" */
if(buffer[i]==';')
flag=1;
/* Se prima del ";" ha trovato un carattere che non è un numero,o uno spazio ,o un ";" ,o uno dei caratteri per
andare a capo ,mette a 1 una variabile errore per segnalare che c'è un errore nel formato della riga */
if((buffer[i]<'0'||buffer[i]>'9') && buffer[i]!=' ' && buffer[i]!=';' && buffer[i]!='\r' && buffer[i]!='\n')
err=1;
/*se ha trovato una cifra (prima di un ";") dopo che è già stata trovato un numero
la variabile err che segnala l'errore di formato viene messa a 1 */
if(buffer[i]>='0' && buffer[i]<='9' && flag1==1)
err=1;
/*se ha trovato una cifra (prima di un ";") e nessun numero è stato trovato prima, allora
viene verificato quanto lungo è il numero (in modo che l'indice della stringa prosegua
fino alla fine del numero) e viene messo a 1 un flag che indica che un numero è stato trovato */
if(buffer[i]>='0' && buffer[i]<='9' && flag1==0){
/* l'indice della stringa viene fatto scorrere fino alla fine del numero */
while(buffer[i]>='0' && buffer[i]<='9')
i++;
flag1=1; /* il flag che indica che un numero è stato trovato (prima di un ";") viene messo a 1 */
i--; /* l'indice viene decrementato in modo che con il prossimo incremento la posizione nella stringa non venga spostata più del dovuto */
}
i++; /* l'indice della stringa viene incrementato, per verificare poi il contenuto della successiva posizione della stringa al ciclo successivo */
}
if(err==1) /* se c'è stato un errore di formato allora la funzione ritorna 1 */
return 1;
return 0; /* se nessun errore di formato è stato riscontrato allora la funzione ritorna 0 */
}
/* Funzione leggi che apre il file in input s, contenete le istruzioni e i parametri delle istruzioni, e crea un vettore dinamico contenente
le istruzioni e i loro parametri. Modifica la variabile del main arr, facendola puntare proprio all'array dinamico. Modifica la variabile
del main dim mettendoci dentro la dimensione dell'array dinamico. Per modificore le variabili del main arr e dim da dentro la funzione, uso
i loro indirizzi.
leggi ritorna 1 in caso sia andato tutto bene (nessun errore); ritorna 0 altrimenti
*/
int leggi(char *s,int **pa,int *pdim){/* s contiene il nome del file, pa l'indirizzo della variabile arr del main, pdim l'indirizzo della
variabile dim del main */
char *buffer=NULL; /* buffer dove metto la stringa letta da getline */
size_t nBytes=0; /* variabile che contiene il numero di Bytes letti da getline */
int i=0; /* è l'indice dell'array di istruzioni , ed è la variabile che tiene conto del numero di istruzioni acquisite */
int elem; /* variabile contenente il codice di un istruzione ad ogni acquisizione */
int flag_err=0; /* flag che segnala se c'è stato un errore (messo a 1 in caso di errore,messo a 0 in caso non ci siano errori) */
int flag_exit=0; /* flag che viene messo a 1, non appena la dimensione dell'array è stata trovata, per uscire dal ciclo */
int line=0; /* variabile che indica a che linea vi è un errore di formato (se c'è) */
ssize_t end=0; /* variabile che segnala se la fine del file è stata raggiunta */
int error_type=-1; /* variabile che contiene il codice d'errore in caso si verifichi un errore */
FILE *f; /* file */
f=fopen(s,"r"); /* Apro il file s in modalità lettura */
if(f){ /*file esiste*/
/*acquisisce la dimensione dell'array di istruzioni*/
do{
end=getline(&buffer,&nBytes,f); /* acquisisce una riga dal file */
if(end!=-1){ /* verifica che qualcosa sia stato letto */
if(control(buffer)){ /* controlla se ci sono errori di formato nella riga acquisita */
if(flag_err!=1){ /* controlla che non sia già stato segnalato un errore, in caso affermativo non modifico il codice d'errore
cosi da poter segnalare solo l'errore trovato per primo */
error_type=0;
flag_err=1;
}
}
else{ /* se non ci sono errori di formato nella riga letta, viene acquisito il codice dell'istruzione (se presente) */
if(sscanf(buffer,"%d",&elem)>0){ /* se è presente il codice di un istruzione lo acquisisce */
*pdim=elem; /* inserisce nella variabile puntatata da pdim (destinata a contere la dimesione dell'array di istruzioni) la dimensione acquisita */
flag_exit=1; /* esco dal ciclo (poichè ho trovato la dimensione dell'array di istruzioni */
}
}
}
line++; /* incrementa la variabile in modo che sia aggiornata sulla riga che sta analizzando */
}while(end!=-1 && flag_err==0 && flag_exit==0); /* continua ad analizzare le righe finchè o il file non è finito, o non è stato trovato un errore,o la dimensione non è stata acquisita */
/*acquisice i numeri che indentificano le istruzioni asembly */
if(*pdim>=0){ /* controlla che la dimensione dell'array di istruzioni acquisita sia >=0 (in caso contrario il resto del file non viene analizzato,
poichè non vi sono istruzioni da poter eseguire) */
*pa=(int*)malloc(sizeof(int)*(*pdim)); /* viene allocata la memoria dinamica per l'array di istruzioni */
if(*pa==NULL){ /* cotrolla se l'allocazione va a buon fine o no */
if(flag_err!=1){ /* controlla che non sia già stato segnalato un errore, in caso affermativo non modifico il codice d'errore
cosi da poter segnalare solo l'errore trovato per primo */
flag_err=1;
error_type=3;
}
}
while(getline(&buffer,&nBytes,f)!=-1 && flag_err==0){ /* continua ad analizzare le righe finchè o il file non è finito, o non
è stato trovato un errore */
if(control(buffer)){ /* controlla se ci sono errori di formato nella riga acquisita */
if(flag_err!=1){ /* controlla che non sia già stato segnalato un errore, in caso affermativo non modifico il codice d'errore
cosi da poter segnalare solo l'errore trovato per primo */
error_type=0;
flag_err=1;
}
}
else{ /* se non ci sono errori di formato nella riga letta viene acquisito il codice dell'istruzione (se presente) */
if(sscanf(buffer,"%d",&elem)>0){ /* se è presente il codice di un istruzione lo acquisisce */
if(i < *pdim) /* controlla che il numero di istruzioni acquisite non sia maggiore di quello dichiarato nel file */
(*pa)[i]=elem; /*inserisce nell'array di istruzioni il numero acquisito (che corrisponde ad una istruzione) */
else{
if(flag_err!=1){ /* controlla che non sia già stato segnalato un errore, in caso affermativo non modifica il codice d'errore
cosi da poter segnalare solo l'errore trovato per primo */
flag_err=1;
error_type=1;
}
}
i++; /* l'indice della stringa viene incrementato, per verificare poi il contenuto della successiva posizione della stringa al ciclo successivo */
}
}
line++; /* incrementa la variabile in modo che sia aggiornata sulla riga che sta analizzando */
}
}
/*controlla che il numero di istruzioni acquisite non sia minore del numero di istruzioni dichiarato nel file , se è minore do errore */
if(i < *pdim){ /* controlla che il numero di istruzioni acquisite non sia minore di quello dichiarato nel file */
if(flag_err!=1){ /* controlla che non sia già stato segnalato un errore, in caso affermativo non modifico il codice d'errore
cosi da poter segnalare solo l'errore trovato per primo */
flag_err=1;
error_type=2;
}
}
/*libera la memoria allocata dinamicamente nel caso sia stata allocata e chiude il file*/
if(buffer)
free(buffer);
fclose(f);
}
else{ /* da errore poichè il file non è stato trovato o è impossibile da aprire */
flag_err=1;
error_type=4;
}
/*controlla il tipo di errore in caso si sia verificato almeno un errore */
if(flag_err){
/*fa corrispondere a ogni codice d'errore un messaggio che verrà stampato su terminale */
switch(error_type){
case 0 : printf("ERRORE: Formato riga input %d non corretto\n",line);
break;
case 1 : printf("ERRORE: Numero istruzioni dichiarato (%d) e' minore di numero istruzioni acquisite (%d)\n",*pdim,i);
break;
case 2 : printf("ERRORE: Numero istruzioni dichiarato (%d) e' maggiore di numero istruzioni acquisite (%d)\n",*pdim,i);
break;
case 3 : printf("ERRORE: Memoria dinamica non allocata correttamente\n");
break;
case 4 : printf("ERRORE: File non trovato o impossibile da aprire\n");
break;
}
}
return !flag_err; /*ritorna 0 in caso ci sia stato almeno un errore, ritorna 1 in caso non ci siano stati errori */
}
|
EnricoPittini/Virtual-machine
|
src/esegui.h
|
<filename>src/esegui.h
/**************************STACK: DEFINIZIONE DI TIPO********************************************/
/* Definisco lo stack come una struttura con un puntatore a interi, che punta all'array in memoria dinamica contenete i valori dello stack,
e con un unsigned int che è l'indice che corrisponde alla prima posizione libera nello stack*/
struct stack{/*struttura stack: è formata da un puntatore e da un unsigned int*/
int *v;/*Puntatore a interi che punta all'array dinamico contenente i valori dello stack*/
unsigned int sp;/*STACK POINTER: è l'indice della prima posizione libera dello stack*/
};
typedef struct stack tstack;/*Definisco il tipo tstack*/
/**************************************************************************************************/
int overflow(int op,int p1,int p2);
int esegui_istruzione(int *arr,int dim,unsigned int *ip,tstack *ps,int *R);
void esegui(int *arr,int dim);
|
EnricoPittini/Virtual-machine
|
src/leggi.h
|
int leggi(char *s,int **pa,int *pdim);
|
EnricoPittini/Virtual-machine
|
src/stampa.h
|
int stampa_istruzione(int *arr,int *i);
void stampa(int *arr,int dim);
|
EnricoPittini/Virtual-machine
|
src/stampa.c
|
#include<stdio.h>
#include"stampa.h"
/*Funzione stampa che dato un vettore di interi arr, di dimensione dim, contenente le istruzioni e i loro parametri, stampa su terminale il
formato mnemonico di queste istruzioni.*/
void stampa(int *arr,int dim){
int i=0;/*E' l'indice che mi dice dove sono arrivato a stampare sull'array arr*/
int error=0;/*E' una variabile che mi dice se ci sono stati errori (error=1) oppure no (error=0)*/
while(i<dim && !error){/*In ogni iterazione del ciclo while stampo un'istruzione. Termino o quando finisce l'array(i>=dim) o quando
rilevo un errore nel stampare un'istruzione*/
printf("[%3d] ",i);/*Stampo l'indice dell'istruzione*/
if(!stampa_istruzione(arr,&i))
error=1;
/* stampa_istruzione è una funzione che stampa l'istruzione con indice i. Siccome ogni istruzione ha un numero diverso di
parametri, faccio in modo che la funzione modifichi l'indice i in modo che corrisponda alla posizione nell' array dell'ultimo
parametro dell'istruzione attuale. Poichè modifico i da dentro la funzione, passo il suo indirizzo.
Inoltre la funzione stampa_istruzione ritorna 0 in caso di errori, 1 altrimenti*/
i++;/*Ora i corrisponde alla posizione nell'array della prossima istruzione*/
}
}
/*Funzione che stampa l'istruzione con indice *i e modifica *i in modo che sia la posizione dell'ultimo parametro dell'istruzione attuale*/
int stampa_istruzione(int *arr,int *i){/* i punta alla variabile contenente l'indice dell'istruzione attuale*/
int istr=arr[*i];/*istr è l'intero corrispondente all'istruzione attuale, ovvero quella con indice *i*/
int risp=0;/*risp è una variabile intera dove salvo il tipo d'errore trovato. Se non trovo errori, alla fine della funzione risp varrà
0. Le tipologie di errori possibili sono: registro non valido (risp==1); istruzione non valida (risp==2)*/
/*Ora segue uno switch con vari casi per identificare che tipo di istruzione è. Per ogni istruzione diversa dovrò stampare una stringa mnemonica
diversa. In più, le istruzioni hanno numero e tipologia di parametri diversi.
Oltre a stampare la stringa mnemonica, modifico *i in modo che sia la posizione dell'ultimo parametro dell'istruzione attuale.
Inoltre, cerco di rilevare eventuali errori*/
switch(istr){
case 0:/*HALT*/
printf("HALT\n");
break;
case 1:/*DISPLAY*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else
printf("DISPLAY R%d\n",arr[*i]);
break;
case 2:/*PRINT_STACK*/
(*i)++;
printf("PRINT_STACK %d\n",arr[*i]);
break;
case 10:/*PUSH*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else
printf("PUSH R%d\n",arr[*i]);
break;
case 11:/*POP*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else
printf("POP R%d\n",arr[*i]);
break;
case 12:/*MOV*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else{
printf("MOV R%d %d\n",arr[*i],arr[(*i)+1]);
(*i)++;
}
break;
case 20:/*CALL*/
(*i)++;
printf("CALL %d\n",arr[*i]);
break;
case 21:/*RET*/
printf("RET\n");
break;
case 22:/*JMP*/
(*i)++;
printf("JMP %d\n",arr[*i]);
break;
case 23:/*JZ*/
(*i)++;
printf("JZ %d\n",arr[*i]);
break;
case 24:/*JPOS*/
(*i)++;
printf("JPOS %d\n",arr[*i]);
break;
case 25:/*JNEG*/
(*i)++;
printf("JNEG %d\n",arr[*i]);
break;
case 30:/*ADD*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31 || arr[*i+1]<0 || arr[*i+1]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else{
printf("ADD R%d R%d\n",arr[*i],arr[(*i)+1]);
(*i)++;
}
break;
case 31:/*SUB*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31 || arr[*i+1]<0 || arr[*i+1]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else{
printf("SUB R%d R%d\n",arr[*i],arr[(*i)+1]);
(*i)++;
}
break;
case 32:/*MUL*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31 || arr[*i+1]<0 || arr[*i+1]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else{
printf("MUL R%d R%d\n",arr[*i],arr[(*i)+1]);
(*i)++;
}
break;
case 33:/*DIV*/
(*i)++;
if(arr[*i]<0 || arr[*i]>31 || arr[*i+1]<0 || arr[*i+1]>31)/*resistro non valido. Ci sono 32 registri, che vanno da 0 a 31*/
risp=1;
else{
printf("DIV R%d R%d\n",arr[*i],arr[(*i)+1]);
(*i)++;
}
break;
default:/*istruzione non valida*/
risp=2;
break;
}
/*Ora vedo se c'è stato qualche errore e in caso lo stampo a schermo.*/
if(risp==1)
printf("ERRORE: registro non valido\n");
if(risp==2)
printf("ERRORE: istruzione non valida\n");
return !risp;/*Ritorno 1 se non ci sono stati errori (risp==0), 0 altrimenti (risp!=0)*/
}
|
pyperanger/mazethread
|
src/rrand.c
|
/*
* Generate the random number in a range defined by number of runners in main.c
* Formula: N = RAND([0:T*5])
*/
#include "rrand.h"
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int
tryharder(struct racebj* race) // return a number in context of endline
{
srand(race->seed);
return rand() % (race->runners * 5);
}
int
meters(struct racebj* race) // objetive number
{
int range;
struct timespec ts;
range = race->runners * 5;
clock_gettime(CLOCK_MONOTONIC, &ts); // ignore clang erros
race->seed = (int)ts.tv_nsec;
srand(race->seed);
trygain:
race->endline = rand() % range;
if (race->endline == 0)
goto trygain;
return 0;
}
|
pyperanger/mazethread
|
src/racing.h
|
<reponame>pyperanger/mazethread
#pragma once
void*
rungo(void* racego);
|
pyperanger/mazethread
|
src/rrand.h
|
<reponame>pyperanger/mazethread<filename>src/rrand.h
#pragma once
#include "maze.h"
int
meters(struct racebj* race);
int
tryharder(struct racebj* race);
|
pyperanger/mazethread
|
src/maze.c
|
<filename>src/maze.c
/*
* Maze Thread
* | - --thread|-t 5 (RANGE = RAND(T*10))
* | - --help|-h
*/
// MAZE HEADER
#include "maze.h"
#include "racing.h"
#include "rrand.h"
#include <ctype.h>
#include <getopt.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define die(STR) \
{ \
printf(STR); \
exit(1); \
}
void
help()
{
printf("Welcome to Maze Thread Race 2020\n"
"-t\t- number of thread.. or runners(minimum 4) each one have "
"$endline/2 chances to find the value\n"
"-h\t- this message output\n");
die("life is short, try u best or die like the rest\n");
}
void
telao(struct racebj tbj)
{
printf("Welcome to Maze Thread Runner 2020\n"
"Competitors: %d\n"
"Endline: %d\n"
"Good look for all\n",
tbj.runners,
tbj.endline);
}
int
orgarg(int argc, char** argv, struct racebj* raceopt)
{
int copt, ret = 0;
while ((copt = getopt(argc, argv, "ht:")) != -1) {
switch (copt) {
case 'h':
ret = 1;
break;
case 't':
if (atoi(optarg) >= MIN_THREAD)
raceopt->runners = strtol(optarg, NULL, 10) > MAX_THREAD
? MAX_THREAD
: strtol(optarg, NULL, 10);
else
raceopt->runners = MIN_THREAD;
break;
case '?':
ret = 1;
break;
default:
ret = 1;
}
}
return ret;
}
int
main(int argc, char* argv[])
{
struct racebj race;
if (orgarg(argc, argv, &race) != 0 || argc < 2) // Organize the arguments
help();
if (meters(&race) != 0)
die("Impossible to find meters number\n");
telao(race);
// prepare runners
pthread_t tid[race.runners];
race.end = 0;
short int i = 0;
for (; i < race.runners; i++) {
race.player = i;
pthread_create(&tid[i], NULL, rungo, &race);
}
for (i = 0; i < race.runners; i++) {
pthread_join(tid[i], NULL);
}
return 0;
}
|
pyperanger/mazethread
|
src/racing.c
|
<gh_stars>1-10
#include "racing.h"
#include "maze.h"
#include "rrand.h"
#include <pthread.h>
#include <stdio.h>
void*
rungo(void* racego)
{
struct racebj* rgo = (struct racebj*)racego;
for (int r = 0; r < rgo->endline / 2; r++) // X chance to find the vlue
{
if (tryharder(rgo) != rgo->endline) {
printf("Player Number %d find the flag!!\n", rgo->player);
break;
}
}
return NULL;
}
|
pyperanger/mazethread
|
src/maze.h
|
<filename>src/maze.h
#pragma once
#define MAZE_VERSION 0.1
#define AUTHOR "pype"
#define MIN_THREAD 4 // the more competitors the better
#define MAX_THREAD 255 // ignore > /proc/sys/kernel/threads-max
struct racebj
{
unsigned int runners;
unsigned int endline;
int player;
int seed;
int end;
};
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/EPollPoller.h
|
#ifndef NLIB_POLLER_EPOLLPOLLER_H
#define NLIB_POLLER_EPOLLPOLLER_H
#include "header.h"
#include <sys/epoll.h>
#include "Poller.h"
struct epoll_event;
class EPollPoller : public Poller
{
public:
EPollPoller(
EventLoop* loop);
~EPollPoller() override;
TimeStamp poll(
int timeoutMs,
ChannelList* activeChannels) override;
void updateChannel(
Channel* channel) override;
void removeChannel(
Channel* channel) override;
private:
static const int s_nInitEventListSize = 16;
static const char* operationToString(
int op);
void fillActiveChannels(
int numEvents,
ChannelList* activeChannels) const;
void update(
int operation,
Channel* channel);
private:
typedef std::vector<struct epoll_event> EventList;
int m_nEpollFd;
EventList m_nEvents;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/header.h
|
<filename>MyMuduo/Lib/header.h
#ifndef LIB_HEADER_H
#define LIB_HEADER_H
#include <functional>
#include <memory>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <errno.h>
#include <sys/uio.h>
#include <functional>
#include <memory>
#include <stdint.h>
#include <endian.h>
#include <functional>
#include <memory>
#include <vector>
#include <memory>
#include <boost/any.hpp>
#include <functional>
#include <memory>
#include <vector>
#include <errno.h>
#include <map>
#include <atomic>
#include <functional>
#include <vector>
#include <atomic>
#include <vector>
#include <stdint.h>
#include <deque>
#include <assert.h>
#include <boost/circular_buffer.hpp>
#include <stdio.h>
#include <time.h>
#include <exception>
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <zlib.h>
#include <memory>
#include <assert.h>
#include <string.h> // memcpy
#include <vector>
#include <sys/types.h>
#include <algorithm>
#include <assert.h>
#include <pthread.h>
#include <stdlib.h>
#include <functional>
#include <memory>
#include <pthread.h>
#include <type_traits>
#include <pthread.h>
#include <assert.h>
#include <pthread.h>
#include <deque>
#include <vector>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <linux/unistd.h>
#include <assert.h>
#include <dirent.h>
#include <pwd.h>
#include <stdio.h> // snprintf
#include <stdlib.h>
#include <unistd.h>
#include <sys/resource.h>
#include <sys/times.h>
#include <algorithm>
#include <signal.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include <pthread.h>
#include <sstream>
#include <poll.h>
#include <memory>
#include <set>
#include <vector>
#include <sys/timerfd.h>
#include <unistd.h>
#include <boost/operators.hpp>
#include <sys/time.h>
#include <stdio.h>
#include <inttypes.h>
#include <memory>
#include <time.h>
#include <algorithm>
#include <stdexcept>
#include <string>
#include <vector>
#include <assert.h>
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h> // snprintf
#include <sys/socket.h>
#include <sys/uio.h> // readv
#include <unistd.h>
#include <cxxabi.h>
#include <execinfo.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#include <iosfwd>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h> // snprintf
#include <sys/socket.h>
#include <sys/uio.h> // readv
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <algorithm>
#include <limits>
#include <type_traits>
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
#include <assert.h>
#include <stdio.h>
#include <boost/operators.hpp>
#include <sys/time.h>
#include <stdio.h>
//#ifndef __STDC_FORMAT_MACROS
//#define __STDC_FORMAT_MACROS
//#endif
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <string>
#include <functional>
#include <memory>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <string.h>
using namespace std;
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoClient/Global/global.h
|
#ifndef GOLBAL_GOLBAL_H
#define GOLBAL_GOLBAL_H
#include "header.h"
#define PI 3.141592
class COLOR
{
public:
COLOR()
{
m_nR = 0;
m_nG = 0;
m_nB = 0;
m_nA = 255;
}
COLOR(int nR_, int nG_, int nB_, int nA_)
{
m_nR = nR_;
m_nG = nG_;
m_nB = nB_;
m_nA = nA_;
}
int m_nR;
int m_nG;
int m_nB;
int m_nA;
};
struct ColorObj
{
public:
ColorObj()
{
memset(m_strObjName, 0, sizeof(m_strObjName));
m_nObjectId = -1;
}
ColorObj(char (&strObjName_)[100], COLOR nColor_)
{
strncpy(m_strObjName, strObjName_, sizeof(m_strObjName));
m_nColor = nColor_;
m_nObjectId = -1;
}
char m_strObjName[100];
COLOR m_nColor;
long m_nObjectId;
};
bool operator==(const COLOR& nColor1_, const COLOR& nColor2_);
bool operator!=(const COLOR& nColor1_, const COLOR& nColor2_);
bool operator==(const ColorObj& nObj1_, const ColorObj& nObj2_);
bool operator!=(const ColorObj& nObj1_, const ColorObj& nObj2_);
#endif // GOLBAL_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/ThreadPool.h
|
#ifndef NLIB_THREADPOOL_H
#define NLIB_THREADPOOL_H
#include "header.h"
#include "Condition.h"
#include "Mutex.h"
#include "Thread.h"
// 1.通过类成员函数启动多个线程+
// 线程回调设置为类的成员函数好处
//
// 一个控制线程通过线程池对象
// 构造多个Thread对象,并启动多个并发执行的线程
//
// 由于线程池对象所启动的线程
// 最后的线程函数是线程池类型的成员函数
// 且std::bind时绑定了this
//
// 所有线程池启动的每个线程均可通过
// 隐式的this获得线程需要的语境.
//
// 线程池对象的成员既包含由其启动的线程执行所需要的语境信息
// 也包含它启动的每个线程的属性信息,
// 这些信息对线程池启动的线程可能没用.
// 但对于可访问到线程池对象的访问者,
// 可以提供线程池所管理的所有线程的属性,状态,
// 这些信息可能正是访问者需要的信息
//
// 2.线程池工作模型
// 线程池内每个线程可访问到一个共享的线程池对象
// 所有需要提交执行任务&获取线程池属性/状态的访问者
// 也可以访问到共享的线程池对象
//
//
// 访问者,可以提交任务
// 线程池内每个执行线程,
// 要么,在执行任务
// 要么,取出一个任务并执行
// 要么,阻塞,等待有任务可取
//
// 任务队列存储在多个线程可共享的线程池对象内
// 线程池中每个线程对任务队列来说,是消费者
// 任何需借助线程池对象提交任务的访问线程,是生产者
//
//
// 这样形成了一个
// 多线程下对共享资源的多生产者多消费者问题
// 需要线程间互斥/同步机制.
//
class ThreadPool
{
public:
typedef std::function<void ()> Task;
explicit ThreadPool(
const string& nameArg = string("ThreadPool"));
~ThreadPool();
void setMaxQueueSize(int maxSize)
{
m_nMaxQueueSize = maxSize;
}
void setThreadInitCallback(const Task& cb)
{
m_nThreadInitCallback = cb;
}
void start(int numThreads);
void stop();
const string& name() const
{
return m_strName;
}
size_t queueSize() const;
void run(Task f);
private:
bool isFull() const;
void runInThread();
Task take();
private:
mutable MutexLock m_nMutex;
Condition m_nNotEmpty;
Condition m_nNotFull;
string m_strName;
Task m_nThreadInitCallback;
std::vector<std::unique_ptr<Thread>> m_vecThreads;
std::deque<Task> m_nQueue;
size_t m_nMaxQueueSize;
bool m_bRunning;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoClient/Ui/chatwidget.h
|
// Author : XuBenHao
// Version : 1.0.0
// Mail : <EMAIL>
// Copyright : XuBenHao 2020 - 2030
//
#ifndef APP_UI_CHATWIDGET_H
#define APP_UI_CHATWIDGET_H
#include "header.h"
namespace Ui {
class ChatWidget;
}
class ChatWidget : public QWidget
{
Q_OBJECT
public:
explicit ChatWidget(QWidget *parent = nullptr);
~ChatWidget();
void Initialize();
void SetNewChat(const QByteArray& nByteSource_, const QByteArray& nByteDest_);
void GetChat(QByteArray& nByteSource_, QByteArray& nByteDest_);
void GetNeedToProcessMessagesCallback(const NDataStruct::DynArray<Message>& arrMessages_);
void ErrorCallback(const TcpConnectionPtr&);
void UpdateShow();
private slots:
void SendClicked(bool checked_);
private:
void ChatCallback(int nType_);
void FormatShowText(const NDataStruct::DynArray<Message>& arrChatMessage_);
private:
QByteArray m_nByteSource;
QByteArray m_nByteDest;
mutable MutexLock m_nMutex;
Condition m_nCondition;
int m_nChatRet;
bool m_bError;
mutable MutexLock m_nMutexChatMessage;
NDataStruct::DynArray<Message> m_arrChatMessage;
private:
Ui::ChatWidget *ui;
};
#endif // CHATWIDGET_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/InetAddress.h
|
#ifndef NLIB_INETADDRESS_H
#define NLIB_INETADDRESS_H
#include "header.h"
#include "StringPiece.h"
const struct sockaddr* sockaddr_cast(
const struct sockaddr_in6* addr_);
class InetAddress
{
public:
explicit InetAddress(
uint16_t port_ = 0,
bool loopbackOnly_ = false,
bool ipv6_ = false);
InetAddress(
StringArg ip_,
uint16_t port_,
bool ipv6_ = false);
explicit InetAddress(
const struct sockaddr_in& addr_)
: m_addr(addr_)
{
}
explicit InetAddress(
const struct sockaddr_in6& addr_)
: m_addr6(addr_)
{
}
sa_family_t family() const
{
return m_addr.sin_family;
}
string toIp() const;
string toIpPort() const;
uint16_t toPort() const;
const struct sockaddr* getSockAddr() const
{
return (struct sockaddr*)(&m_addr6);
}
void setSockAddrInet6(
const struct sockaddr_in6& addr6_)
{
m_addr6 = addr6_;
}
uint32_t ipNetEndian() const;
uint16_t portNetEndian() const
{
return m_addr.sin_port;
}
static bool resolve(
StringArg hostname_,
InetAddress* result_);
void setScopeId(uint32_t scope_id);
private:
union
{
struct sockaddr_in m_addr;
struct sockaddr_in6 m_addr6;
};
};
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/lib.h
|
<filename>MyMuduo/Lib/lib.h
#ifndef NLIB_LIB
#define NLIB_LIB
#include "Atomic.h"
#include "Condition.h"
#include "CountDownLatch.h"
#include "CurrentThread.h"
#include "Date.h"
#include "Exception.h"
#include "FileUtil.h"
#include "Logging.h"
#include "LogStream.h"
#include "Mutex.h"
#include "ProcessInfo.h"
#include "StringPiece.h"
#include "Thread.h"
#include "ThreadLocal.h"
#include "ThreadLocalSingleton.h"
#include "ThreadPool.h"
#include "TimeStamp.h"
#include "TimeZone.h"
#include "WeakCallback.h"
#include "Socket.h"
#include "SocketOps.h"
#include "InetAddress.h"
#include "Channel.h"
#include "Buffer.h"
#include "EventLoopThread.h"
#include "EventLoopThreadPool.h"
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/Global/lib.h
|
<filename>MuduoServer/Global/lib.h
#ifndef GLOBAL_LIB_H
#define GLOBAL_LIB_H
#include "Global/global.h"
#endif // LIB_H
|
Fragrant-Yang/git-test-copy
|
MuduoServer/Application/main.h
|
<filename>MuduoServer/Application/main.h
#ifndef APPLICATION_MAIN_H
#define APPLICATION_MAIN_H
#include "header.h"
#endif // MAIN_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Condition.h
|
<reponame>Fragrant-Yang/git-test-copy<gh_stars>1-10
#ifndef NLIB_CONDITION_H
#define NLIB_CONDITION_H
#include "Mutex.h"
class Condition
{
public:
explicit Condition(
MutexLock& mutex)
: m_nMutex(mutex)
{
pthread_cond_init(&m_nCond, NULL);
}
~Condition()
{
pthread_cond_destroy(&m_nCond);
}
void wait()
{
// 在对象存在期间,互斥锁的拥有线程id为0
// 在对象析构时,设置互斥锁的拥有线程id为执行对象析构的线程id
MutexLock::UnassignGuard ug(m_nMutex);
pthread_cond_wait(
&m_nCond,
m_nMutex.getPthreadMutex());
}
bool waitForSeconds(
double seconds);
void notify()
{
pthread_cond_signal(&m_nCond);
}
void notifyAll()
{
pthread_cond_broadcast(&m_nCond);
}
private:
MutexLock& m_nMutex;
pthread_cond_t m_nCond;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/TimeStamp.h
|
<filename>MyMuduo/Lib/TimeStamp.h
#ifndef NLIB_TIMESTAMP_H
#define NLIB_TIMESTAMP_H
#include "header.h"
class TimeStamp :
public boost::equality_comparable<TimeStamp>,
public boost::less_than_comparable<TimeStamp>
{
public:
TimeStamp()
: m_nMicroSecondsSinceEpoch(0)
{
}
explicit TimeStamp(
int64_t microSecondsSinceEpochArg)
: m_nMicroSecondsSinceEpoch(microSecondsSinceEpochArg)
{
}
// 交换
void swap(TimeStamp& that)
{
std::swap(
m_nMicroSecondsSinceEpoch,
that.m_nMicroSecondsSinceEpoch);
}
string toString() const;
// 格式化显示
string toFormattedString(
bool showMicroseconds = true) const;
bool valid() const
{
return m_nMicroSecondsSinceEpoch > 0;
}
// 获取值
int64_t microSecondsSinceEpoch() const
{
return m_nMicroSecondsSinceEpoch;
}
// 转换为以秒为单位的值
time_t secondsSinceEpoch() const
{
return (time_t)(m_nMicroSecondsSinceEpoch
/ s_nMicroSecondsPerSecond);
}
static TimeStamp now();
static TimeStamp invalid()
{
return TimeStamp();
}
// 从time_t对象得到TimeStamp对象
static TimeStamp fromUnixTime(time_t t)
{
return fromUnixTime(t, 0);
}
static TimeStamp fromUnixTime(
time_t t,
int microseconds)
{
return
TimeStamp((int64_t)(t)
* s_nMicroSecondsPerSecond
+ microseconds);
}
static const int s_nMicroSecondsPerSecond
= 1000 * 1000;
private:
int64_t m_nMicroSecondsSinceEpoch;
};
inline bool operator<(
TimeStamp lhs,
TimeStamp rhs)
{
return lhs.microSecondsSinceEpoch()
< rhs.microSecondsSinceEpoch();
}
inline bool operator==(
TimeStamp lhs,
TimeStamp rhs)
{
return lhs.microSecondsSinceEpoch()
== rhs.microSecondsSinceEpoch();
}
// 以秒为单位的差值
inline double timeDifference(
TimeStamp high,
TimeStamp low)
{
int64_t diff = high.microSecondsSinceEpoch()
- low.microSecondsSinceEpoch();
return (double)(diff)
/ TimeStamp::s_nMicroSecondsPerSecond;
}
inline TimeStamp addTime(
TimeStamp timestamp,
double seconds)
{
int64_t delta = (int64_t)(seconds
* TimeStamp::s_nMicroSecondsPerSecond);
return TimeStamp(timestamp.microSecondsSinceEpoch() + delta);
}
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Tcp/TcpClient.h
|
<gh_stars>1-10
#ifndef NLIB_TCPCLIENT_H
#define NLIB_TCPCLIENT_H
#include "../Lib/lib.h"
#include "TcpConnection.h"
class Connector;
// Muduo的事件循环/线程池/客户端/服务端/Io复用总结:
// 1.一个EventLoop的loop独占一个线程
// EventLoop本身构成了此线程执行的语境
// 2.利用EventLoop内的epoll描述符,
// 事件循环可以对一个或多个描述符进行监听
// 监听的事件可以指定
// 事件循环还支持任务回调,其他可访问到EventLoop的线程,
// 可向其任务回调写入回调来提交任务.
// 3.每个描述符提供给epoll监听时允许绑定一个自定义数据
// Muduo里每个描述符绑定一个指向Channel对象的指针,
// 此Channel对象构成了每个描述符的语境.
// 通过Channel语境可以提供描述符
// 当前与epoll的关系/要监听的事件/产生的事件/事件回调/...
// 4.一个TcpClient代表一个客户端
// 提供的接口connect/disconnect/stop允许触发
// 套接字创建/连接请求发起/连接关闭/...
// 5.Muduo的事件循环既监听多个描述符,
// 在事件发生时触发事件回调
// 又支持任务回调.
// 这样要求事件循环监听的每个描述符/处理的每个任务回调
// 必须在一个短的时间内完成事件处理/任务回调,
// 这样才能保证高响应性.
// 防止阻塞与一个处理,导致后续处理,延迟较大才响应情况.
// 为此,监听的描述符需要是非阻塞描述符
// 处理的任务回调需要是可以是快速处理完毕的任务回调
// 6.非阻塞客户端流程:
// a.创建套接字+发起连接请求
// b.创建套接字语境Channel+事件循环监听套接字可读
// c.处理可读事件,处理结果是产生一个TcpConnecton对象代表一个已经连接套接字的语境
// d.已经连接套接字,需要有其Channel语境+事件循环监听套接字可读
// 对套接字可读的监听,在连接建立期间一直如此
// 仅在有要写到套接字的内容存储于缓冲区时,才需要监听其可写.
// 且在可写事件中,写入缓冲区数据后,若无数据等待写入,
// 则关闭对其可写监视
//
// e.连接关闭
// 主动发起时,
// 待收到对端的FIN,会触发读事件
// 读事件处理中,读0字节表示收到对端FIN,可关闭连接
// 执行清理--删除在epoll中对此描述符监视/回收套接字的语境Channel
//
// 7.非阻塞服务端流程:
// a.创建套接字+开始监听
// b.创建监听套接字语境Channel+事件循环监听套接字可读
// c.处理可读事件,
// 处理结果是产生一个TcpConnection对象代表一个已经连接套接字语境
// d.已经连接套接字,需要有其Channel语境+事件循环监听套接字可读
// 对套接字可读的监听,在连接建立期间一直如此
// 仅在有要写到套接字的内容存储于缓冲区时,才需要监听其可写.
// 且在可写事件中,写入缓冲区数据后,若无数据等待写入,
// 则关闭对其可写监视
//
// e.连接关闭
// 主动发起时,
// 待收到对端的FIN,会触发读事件
// 读事件处理中,读0字节表示收到对端FIN,可关闭连接
// 执行清理--删除在epoll中对此描述符监视/回收套接字的语境Channel
// 服务器对象可以保存所有存在的已经连接套接字及其他信息
// 实现管理
// 8.服务端的多线程模型
// 监听套接字依附的事件循环所在的线程,负责监听
// 服务器通过接口启动多个并行线程--即线程池
// 监听套接字可读处理时,
// 产生的每个已经连接套接字按负载均衡方式分配非线程池中线程
typedef std::shared_ptr<Connector> ConnectorPtr;
class TcpClient
{
public:
TcpClient(
EventLoop* loop,// 一个独立线程的事件循环
const InetAddress& serverAddr,// 目的端地址
const string& nameArg);
~TcpClient();
void connect();
void disconnect();
void stop();
TcpConnectionPtr connection() const
{
MutexLockGuard lock(m_nMutex);
return m_nConnection;
}
EventLoop* getLoop() const
{
return m_pLoop;
}
bool retry() const
{
return m_bRetry;
}
void enableRetry()
{
m_bRetry = true;
}
const string& name() const
{
return m_strName;
}
void setConnectionCallback(
ConnectionCallback cb)
{
m_nConnectionCallback = std::move(cb);
}
void setMessageCallback(
MessageCallback cb)
{
m_nMessageCallback = std::move(cb);
}
void setWriteCompleteCallback(
WriteCompleteCallback cb)
{
m_nWriteCompleteCallback = std::move(cb);
}
private:
void newConnection(int sockfd);
void removeConnection(const TcpConnectionPtr& conn);
private:
EventLoop* m_pLoop;
ConnectorPtr m_nConnector;
const string m_strName;
ConnectionCallback m_nConnectionCallback;
MessageCallback m_nMessageCallback;
WriteCompleteCallback m_nWriteCompleteCallback;
bool m_bRetry;
bool m_bConnect;
int m_nNextConnId;
mutable MutexLock m_nMutex;
TcpConnectionPtr m_nConnection;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/ThreadLocalSingleton.h
|
#ifndef NLIB_THREADLOCALSINGLETON_H
#define NLIB_THREADLOCALSINGLETON_H
#include "header.h"
template<typename T>
class ThreadLocalSingleton
{
class Deleter
{
public:
Deleter()
{
pthread_key_create(
&m_nKey,
&ThreadLocalSingleton::destructor);
}
~Deleter()
{
pthread_key_delete(m_nKey);
}
void set(T* newObj)
{
assert(pthread_getspecific(m_nKey) == NULL);
pthread_setspecific(m_nKey, newObj);
}
pthread_key_t m_nKey;
};
public:
// 不可定义此模板类型的局部对象
// 不可用new产生此模板类型对象
ThreadLocalSingleton() = delete;
~ThreadLocalSingleton() = delete;
// m_pValue每个线程共享一个静态值对象[指针]
// 每个线程初次执行到此时,分配一个模板T动态对象,
// 将m_pValue指向它
//
// 进程内所有线程针对模板类型T共享唯一一个静态值对象m_nDelete
// 进程首次使用模板类型T时,触发一个全局唯一的m_nDelete的构造
static T& instance()
{
if (!m_pValue)
{
m_pValue = new T();
// 再将线程特定数据设置通过所有线程共享的索引
// 设置到线程特定数据槽,
// 有点多余.
// 利用__thread修饰的线程特定数据自身可以实现此功能
m_nDeleter.set(m_pValue);
}
return *m_pValue;
}
static T* pointer()
{
return m_pValue;
}
private:
static void destructor(void* obj)
{
delete m_pValue;
m_pValue = 0;
}
private:
static __thread T* m_pValue;
static Deleter m_nDeleter;
};
// 每个线程内所有类型T的模板类对象共享一个m_pValue
template<typename T>
__thread T* ThreadLocalSingleton<T>::m_pValue = 0;
// 所有类型T的模板类对象共享一个m_nDeleter
template<typename T>
typename ThreadLocalSingleton<T>::Deleter ThreadLocalSingleton<T>::m_nDeleter;
// 因为delete的构造/析构,不会存在此模板类的对象
// 这样,
// 每个线程,对类型T,
// 通过模板类的instance静态调用可获得调用线程特定的一个T对象
// instance静态方法,若调用线程的T对象尚不存在,
// 动态产生对象后,既将对象指针存储在调用线程特定的m_pValue又通过m_nDeleter存储在线程特定数据
// 多余.
// m_pValue本身已经有了线程特定数据的意义,这时,不必再用m_nDelete来设置线程特定数据.
// 通过模板类的pointer静态调用可访问调用线程特定的一个T对象[若存在的话]
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Timer.h
|
<filename>MyMuduo/Lib/Timer.h
#ifndef LIB_TIMER_H
#define LIB_TIMER_H
#include "Atomic.h"
#include "TimeStamp.h"
#include "CallBacks.h"
// 将定时器回调函数作为类的数据成员的好处:
// 类对象构成了定时器回调及其回调语境
//
class Timer
{
public:
Timer(
// 定时器回调函数
TimerCallback cb,
// 何时触发时间戳
TimeStamp when,
// 是否间隔性触发
double interval)
: m_nCallBack(
std::move(cb)),
m_nExpiration(when),
m_nInterval(interval),
m_bRepeat(interval > 0.0),
m_nSequence(
s_nNumCreated.incrementAndGet())
{
}
// 执行定时器回调函数
void run() const
{
m_nCallBack();
}
TimeStamp expiration() const
{
return m_nExpiration;
}
bool repeat() const
{
return m_bRepeat;
}
int64_t sequence() const
{
return m_nSequence;
}
void restart(TimeStamp now);
static int64_t numCreated()
{
return
s_nNumCreated.get();
}
private:
const TimerCallback
m_nCallBack;
TimeStamp m_nExpiration;
const double m_nInterval;
const bool m_bRepeat;
const int64_t m_nSequence;
static AtomicInt64 s_nNumCreated;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoClient/Ui/mainwindow.h
|
// Author : XuBenHao
// Version : 1.0.0
// Mail : <EMAIL>
// Copyright : XuBenHao 2020 - 2030
//
#ifndef APP_UI_MAINWINDOW_H
#define APP_UI_MAINWINDOW_H
#include "header.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
void Initialize();
virtual void closeEvent(QCloseEvent *event);
private slots:
void ShowDataStruct(const QString& strName_);
void ShowMainChatWidget(const QByteArray& strUserId_, const TimeStamp& nTimeStamp);
private:
Ui::MainWindow *ui;
NDataStruct::DynArray<std::pair<QByteArray, QWidget*>> m_arrMapWidget;
};
#endif // MAINWINDOW_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Mutex.h
|
<reponame>Fragrant-Yang/git-test-copy
#ifndef NLIB_MUTEX_H
#define NLIB_MUTEX_H
#include "header.h"
#include "CurrentThread.h"
// 互斥锁,同时包含拥有此锁的线程id
class MutexLock
{
class UnassignGuard
{
public:
explicit UnassignGuard(
MutexLock& owner)
: m_nOwner(owner)
{
m_nOwner.unassignHolder();
}
~UnassignGuard()
{
m_nOwner.assignHolder();
}
private:
MutexLock& m_nOwner;
};
public:
MutexLock()
: m_nHolder(0)
{
pthread_mutex_init(&m_nMutex, NULL);
}
~MutexLock()
{
assert(m_nHolder == 0);
pthread_mutex_destroy(&m_nMutex);
}
bool isLockedByThisThread() const
{
// m_nHolder记录拥有互斥锁的线程id
return m_nHolder == tid();
}
void assertLocked() const
{
assert(isLockedByThisThread());
}
void lock()
{
pthread_mutex_lock(&m_nMutex);
assignHolder();
}
void unlock()
{
unassignHolder();
pthread_mutex_unlock(&m_nMutex);
}
pthread_mutex_t* getPthreadMutex()
{
return &m_nMutex;
}
private:
void unassignHolder()
{
m_nHolder = 0;
}
void assignHolder()
{
// tid得到执行此调用线程的id
m_nHolder = tid();
}
private:
pthread_mutex_t m_nMutex;
pid_t m_nHolder;
friend class Condition;
};
class MutexLockGuard
{
public:
explicit MutexLockGuard(MutexLock& mutex)
: m_nMutex(mutex)
{
m_nMutex.lock();
}
~MutexLockGuard()
{
m_nMutex.unlock();
}
private:
MutexLock& m_nMutex;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/MySqlAgent/lib.h
|
#ifndef MYSQL_AGENT_LIB_H
#define MYSQL_AGENT_LIB_H
#include "mysqlagent.h"
#endif // LIB_H
|
Fragrant-Yang/git-test-copy
|
MuduoClient/Ui/mainchatwidget.h
|
// Author : XuBenHao
// Version : 1.0.0
// Mail : <EMAIL>
// Copyright : XuBenHao 2020 - 2030
//
#ifndef APP_UI_MAINCHATWIDGET_H
#define APP_UI_MAINCHATWIDGET_H
#include "header.h"
class ChatWidget;
namespace Ui {
class MainChatWidget;
}
class MainChatWidget : public QWidget
{
Q_OBJECT
public:
explicit MainChatWidget(QWidget *parent = nullptr);
~MainChatWidget();
void Initialize();
virtual void timerEvent(QTimerEvent *event);
//void Reset();
void SetUserId(const QString& arrUserId_);
void SetLoginTime(const TimeStamp& nTimeStamp_);
void UpdateFriendList();
void OffLine();
void NeedToProcessUserList();
void NewMessageCallback(const QByteArray& nByteSender_);
private:
void UpdateNeedToProcessUserShow(const NDataStruct::DynArray<QByteArray>& arrUsers_);
void NeedToProcessUserListCallback(const NDataStruct::DynArray<QByteArray>& arrUserIds_);
void UpdateFriendCallback(const NDataStruct::DynArray<QByteArray>& arrUserIds_);
void ErrorCallback(const TcpConnectionPtr&);
void GetNeedToProcessMessagesCallback(const NDataStruct::DynArray<Message>& arrMessages_);
//void ErrorCallback(const TcpConnectionPtr&);
private slots:
void AddClicked(bool checked_);
void ListDoubleClicked(const QModelIndex& index);
private:
Ui::MainChatWidget *ui;
mutable MutexLock m_nMutex;
Condition m_nCondition;
bool m_bError;
bool m_bFriendValid;
NDataStruct::DynArray<QByteArray> m_arrFriends;
mutable MutexLock m_nMutexForGetNeedToProcessMessage;
Condition m_nConditionForGetNeedToProcessMessage;
int m_nGetNeedToProcessMessagesRet;
mutable MutexLock m_nMutexForNeedToProcessUsers;
Condition m_nConditionForNeedToProcessUsers;
bool m_bNeedToProcessUserValid;
NDataStruct::DynArray<QByteArray> m_arrNeedToProcessUsers;
mutable MutexLock m_nMutexLogin;
QString m_arrUserId;
TimeStamp m_nLoginTime;
private:
QStandardItemModel* m_pModel;
QStandardItemModel* m_pActiveModel;
private:
// chat-window manager
NDataStruct::DynArray<std::pair<QByteArray, QWidget*>> m_arrMapWidget;
QByteArray m_nChattingUserId;
int m_nRefreshTimerId;
ChatWidget* m_pChattingWidget;
};
#endif // MAINCHATWIDGET_H
|
Fragrant-Yang/git-test-copy
|
MuduoClient/MuduoApp/lib.h
|
<gh_stars>1-10
#ifndef MUDUO_APP_LIB_H
#define MUDUO_APP_LIB_H
#include "muduoclient.h"
#endif // LIB_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Tcp/Connector.h
|
#ifndef NLIB_CONNECTOR_H
#define NLIB_CONNECTOR_H
#include "../Lib/lib.h"
class Channel;
class EventLoop;
class Connector :
public std::enable_shared_from_this<Connector>
{
public:
typedef std::function<void (int sockfd)> NewConnectionCallback;
Connector(
EventLoop* loop,
const InetAddress& serverAddr);
~Connector();
void setNewConnectionCallback(
const NewConnectionCallback& cb)
{
m_nNewConnectionCallback = cb;
}
void start();
void restart();
void stop();
const InetAddress& serverAddress() const
{
return m_nServerAddr;
}
private:
enum States
{
s_nDisconnected,
s_nConnecting,
s_nConnected
};
static const int s_nMaxRetryDelayMs = 30*1000;
static const int s_nInitRetryDelayMs = 500;
void setState(States s)
{
m_nState = s;
}
void startInLoop();
void stopInLoop();
void connect();
void connecting(int sockfd);
void handleWrite();
void handleError();
void retry(int sockfd);
int removeAndResetChannel();
void resetChannel();
private:
EventLoop* m_pLoop;
InetAddress m_nServerAddr;
bool m_bConnect;
States m_nState;
std::unique_ptr<Channel> m_pChannel;
NewConnectionCallback m_nNewConnectionCallback;
int m_nRetryDelayMs;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/MuduoApp/codec.h
|
#ifndef MUDUO_APP_CODEC_H
#define MUDUO_APP_CODEC_H
#include "header.h"
// 消息编码格式:
// 4字节长度[长度指的是数据部分的长度]+数据本身
// 消息解码:
// 先取出4字节
// 在取出该长度表示的数据部分
//
//
// 直接通过Tcp传递数值类型时,
// 需要
// 传递前将本机数值转换为网络字节序数值再写入
// 接收时,先取出数据内容,再将其转化为本机字节序再实际使用
//
// 如果传递的是字符串,
// 不需要上述处理
//
//
// Tcp的消息编码和解码其实就是应用层协议
class LengthHeaderCodec
{
public:
typedef std::function<void (
const TcpConnectionPtr&,
const string& message,
TimeStamp)> StringMessageCallback;
explicit LengthHeaderCodec(
const StringMessageCallback& cb)
: m_nMessageCallback(cb)
{
}
// 每次套接字读出消息先是放入参数2的Buffer对象
// 并触发回调
// 但应用层回调里面要分析Buffer内容
// 看是否有一条完整信息取出一条或多条
// 还是本次略过,但后续累计到一条完整信息再处理
void onMessage(
const TcpConnectionPtr& conn,
Buffer* buf,
TimeStamp receiveTime)
{
while (buf->readableBytes() >= s_nHeaderLen)
{
const void* data = buf->peek();
int32_t be32 = *static_cast<const int32_t*>(data);
const int32_t len = networkToHost32(be32);
if (len > 65536
|| len < 0)
{
LOG_ERROR
<< "Invalid length "
<< len;
conn->shutdown();
break;
}
else if (buf->readableBytes() >= len + s_nHeaderLen)
{
buf->retrieve(s_nHeaderLen);
string message(
buf->peek(),
len);
// 这里应用层将协议打包和解码抽离为一个独立的类
// 用将解码好的消息执行应用层回调
m_nMessageCallback(
conn,
message,
receiveTime);
buf->retrieve(len);
}
else
{
break;
}
}
}
void send(
TcpConnection* conn,
const StringPiece& message)
{
Buffer buf;
buf.append(
message.data(),
message.size());
int32_t len = static_cast<int32_t>(message.size());
int32_t be32 = hostToNetwork32(len);
buf.prepend(
&be32,
sizeof be32);
conn->send(&buf);
}
private:
StringMessageCallback m_nMessageCallback;
const static size_t s_nHeaderLen = sizeof(int32_t);
};
#endif // CODEC_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Thread.h
|
#ifndef NLIB_THREAD_H
#define NLIB_THREAD_H
#include "header.h"
#include "Atomic.h"
#include "CountDownLatch.h"
// 提供线程启动接口
// 包含线程回调指定,线程信息保持
// 通过一个Thread类成员函数内部调线程api
// 为线程api提供了语境
// 成员函数内部通过this指向对象的数据成员
// 可以得到调用发生时需要的语境信息
// 并可据此作对应的处理
//
class Thread
{
public:
typedef std::function<void ()> ThreadFunc;
explicit Thread(
ThreadFunc,
const string& name = string());
~Thread();
void start();
int join();
bool started() const
{
return m_bStarted;
}
pid_t tid() const
{
return m_nTid;
}
const string& name() const
{
return m_strName;
}
static int numCreated()
{
return s_nNumCreated.get();
}
private:
void setDefaultName();
private:
bool m_bStarted;
bool m_bJoined;
pthread_t m_nPthreadId;
pid_t m_nTid;
ThreadFunc m_nFunc;
string m_strName;
CountDownLatch m_nLatch;
static AtomicInt32 s_nNumCreated;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Socket.h
|
#ifndef NLIB_SOCKET_H
#define NLIB_SOCKET_H
struct tcp_info;
class InetAddress;
class Socket
{
public:
explicit Socket(int sockfd)
: m_nSockFd(sockfd)
{ }
~Socket();
int fd() const
{
return m_nSockFd;
}
bool getTcpInfo(struct tcp_info*) const;
bool getTcpInfoString(char* buf, int len) const;
void bindAddress(const InetAddress& localaddr);
void listen();
int accept(InetAddress* peeraddr);
void shutdownWrite();
void setTcpNoDelay(bool on);
void setReuseAddr(bool on);
void setReusePort(bool on);
void setKeepAlive(bool on);
private:
const int m_nSockFd;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/SocketOps.h
|
#ifndef NLIB_SOCKETSOPS_H
#define NLIB_SOCKETSOPS_H
int createNonblockingOrDie(
sa_family_t family);
int connect(
int sockfd,
const struct sockaddr* addr);
void bindOrDie(
int sockfd,
const struct sockaddr* addr);
void listenOrDie(int sockfd);
int accept(
int sockfd,
struct sockaddr_in6* addr);
ssize_t Read(
int sockfd,
void *buf,
size_t count);
ssize_t Readv(
int sockfd,
const struct iovec *iov,
int iovcnt);
ssize_t Write(
int sockfd,
const void *buf,
size_t count);
void Close(int sockfd);
void shutdownWrite(int sockfd);
void toIpPort(
char* buf,
size_t size,
const struct sockaddr* addr);
void toIp(
char* buf,
size_t size,
const struct sockaddr* addr);
void fromIpPort(
const char* ip,
uint16_t port,
struct sockaddr_in* addr);
void fromIpPort(
const char* ip,
uint16_t port,
struct sockaddr_in6* addr);
int getSocketError(int sockfd);
const struct sockaddr* sockaddr_cast(
const struct sockaddr_in* addr);
const struct sockaddr* sockaddr_cast(
const struct sockaddr_in6* addr);
struct sockaddr* sockaddr_cast(
struct sockaddr_in6* addr);
const struct sockaddr_in* sockaddr_in_cast(
const struct sockaddr* addr);
const struct sockaddr_in6* sockaddr_in6_cast(
const struct sockaddr* addr);
struct sockaddr_in6 getLocalAddr(
int sockfd);
struct sockaddr_in6 getPeerAddr(
int sockfd);
bool isSelfConnect(int sockfd);
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/DataStruct/dynqueue.h
|
// Author : XuBenHao
// Version : 1.0.0
// Mail : <EMAIL>
// Copyright : XuBenHao 2020 - 2030
#ifndef DATA_STRUCT_DYNQUEUE_H
#define DATA_STRUCT_DYNQUEUE_H
#include "header.h"
#include "doublelist.h"
namespace NDataStruct
{
template <typename T>
class DynQueue
{
public:
DynQueue();
virtual ~DynQueue();
DynQueue(const DynQueue& dqA_);
DynQueue& operator=(const DynQueue& dqA_);
void In(const T& nValue_);
T Out();
T Peek() const;
bool IsEmpty() const;
int Size() const;
DoubleList<T> GetList() const
{
return m_List;
}
private:
DoubleList<T> m_List;
};
template <typename T>
DynQueue<T>::DynQueue()
{
}
template <typename T>
DynQueue<T>::~DynQueue()
{
}
template <typename T>
DynQueue<T>::DynQueue(const DynQueue& dqA_)
{
m_List = dqA_.m_List;
}
template <typename T>
DynQueue<T>& DynQueue<T>::operator=(const DynQueue& dqA_)
{
if (this == &dqA_)
{
return *this;
}
m_List = dqA_.m_List;
return *this;
}
template <typename T>
void DynQueue<T>::In(const T& nValue_)
{
m_List.InsertLast(nValue_);
}
template <typename T>
T DynQueue<T>::Out()
{
if (IsEmpty())
{
throw "queue is empty";
}
typename DoubleList<T>::Node* _pFirst = m_List.GetFirst();
T _nValue = _pFirst->GetValue();
m_List.DeleteFirst();
return _nValue;
}
template <typename T>
T DynQueue<T>::Peek() const
{
if (IsEmpty())
{
throw "queue is empty";
}
typename DoubleList<T>::Node* _pFirst = m_List.GetFirst();
return _pFirst->GetValue();
}
template <typename T>
bool DynQueue<T>::IsEmpty() const
{
return m_List.IsEmpty();
}
template <typename T>
int DynQueue<T>::Size() const
{
return m_List.GetSize();
}
}
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/CurrentThread.h
|
#ifndef NLIB_CURRENTTHREAD_H
#define NLIB_CURRENTTHREAD_H
#include "header.h"
#include "TimeStamp.h"
// __thread修饰的全局对象
// 每个线程有各自独立的一份,
// 天然就是线程特定的数据
extern __thread int t_cachedTid;
extern __thread char t_tidString[32];
extern __thread int t_tidStringLength;
extern __thread const char* t_threadName;
pid_t gettid();
void cacheTid();
bool isMainThread();
void sleepUsec(int64_t usec);
string stackTrace(bool demangle);
inline int tid()
{
cacheTid();
return t_cachedTid;
}
inline const char* tidString()
{
return t_tidString;
}
inline int tidStringLength()
{
return t_tidStringLength;
}
inline const char* name()
{
return t_threadName;
}
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/Global/header.h
|
<filename>MuduoServer/Global/header.h
#ifndef GLOBAL_HEADER_H
#define GLOBAL_HEADER_H
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
#include <iostream>
#include <bitset>
#include <time.h>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <math.h>
#include <vector>
#include <functional>
#include <exception>
#include <QObject>
#include <QPoint>
#include <QFile>
#include <QDir>
#include <QDebug>
#include <QMap>
#include <QThread>
#include <QSemaphore>
#include <QMutex>
#include <QMutexLocker>
#endif // HEADER_H
|
Fragrant-Yang/git-test-copy
|
MuduoServer/DataStruct/dynarray.h
|
// Author : XuBenHao
// Version : 1.0.0
// Mail : <EMAIL>
// Copyright : XuBenHao 2020 - 2030
#ifndef DATA_STRUCT_DYNARRAY_H
#define DATA_STRUCT_DYNARRAY_H
#include "header.h"
namespace NDataStruct
{
// 突破固定容量数组限制
// 容量可以动态增加和减少的数组
// 适合作为管理动态元素集合的容器
template<typename T>
class DynArray
{
public:
DynArray();
DynArray(int nInitialSize_, const T& nInitialValue_);
virtual ~DynArray();
void Add(const T& value_);
void AddRange(const DynArray& arrItems_);
void Insert(int nIndex_, const T& value_);
void DeleteByIndex(int nIndex_ = -1);
void DeleteByValue(const T& value_);
void DeleteAll();
bool SetValue(int nIndex_, const T& value_);
bool GetValue(int nIndex_, T& value_) const;
int GetSize() const;
int GetCapacity() const;
int Find(std::function<bool(const T&)> fun_) const;
T& operator[](int nIndex_);
const T& operator[](int nIndex_) const;
void Free();
//T* DeepCopy(int& nSize_);
DynArray(const DynArray<T>& arrElements_);
DynArray<T>& operator=(const DynArray<T>& arrElements_);
private:
void Check(int nSize_);
void Shrink();
private:
T* m_pSource;// 当T为引用类型时,sizeof无法获得其真实大小
int m_nSize;
int m_nCapacity;
std::allocator<T> m_alloc;
};
template<typename T>
DynArray<T>::DynArray(const DynArray<T>& arrElements_)
: m_pSource(nullptr), m_nSize(0), m_nCapacity(0)
{
T* _pSource = m_alloc.allocate(arrElements_.m_nCapacity);
if (_pSource == nullptr)
{
throw "out of memory";
}
std::uninitialized_copy_n(arrElements_.m_pSource, arrElements_.m_nSize, _pSource);
m_pSource = _pSource;
m_nSize = arrElements_.m_nSize;
m_nCapacity = arrElements_.m_nCapacity;
}
template<typename T>
DynArray<T>& DynArray<T>::operator=(const DynArray<T>& arrElements_)
{
T* _pSource = m_alloc.allocate(arrElements_.m_nCapacity);
if (_pSource == nullptr)
{
throw "out of memory";
}
std::uninitialized_copy_n(arrElements_.m_pSource, arrElements_.m_nSize, _pSource);
Free();
m_pSource = _pSource;
m_nSize = arrElements_.m_nSize;
m_nCapacity = arrElements_.m_nCapacity;
return *this;
}
template<typename T>
int DynArray<T>::Find(std::function<bool(const T&)> fun_) const
{
int _nPosIndex = -1;
for (int _i = 0; _i < m_nSize; _i++)
{
if (fun_(*(m_pSource + _i)))
{
_nPosIndex = _i;
break;
}
}
return _nPosIndex;
}
template<typename T>
DynArray<T>::DynArray()
:m_pSource(nullptr), m_nSize(0), m_nCapacity(0)
{
}
template<typename T>
DynArray<T>::DynArray(int nInitialSize_, const T& nInitialValue_)
: m_pSource(nullptr), m_nSize(0), m_nCapacity(0)
{
T* _pSource = m_alloc.allocate(nInitialSize_ * 2);
if (_pSource == nullptr)
{
throw "out of memory";
}
std::uninitialized_fill_n(_pSource, m_nSize, nInitialValue_);
m_nSize = nInitialSize_;
m_nCapacity = nInitialSize_ * 2;
m_pSource = _pSource;
}
template<typename T>
void DynArray<T>::Free()
{
//if(m_nSize > 0)
//{
for(int i = 0; i < m_nSize; i++)
{
m_alloc.destroy(m_pSource + i);
}
//}
if(m_nCapacity > 0)
{
m_alloc.deallocate(m_pSource, m_nCapacity);
}
m_pSource = nullptr;
m_nSize = 0;
m_nCapacity = 0;
}
/*template<typename T>
T* DynArray<T>::DeepCopy(int& nSize_)
{
T* _pP = (T*)malloc(sizeof(T) * m_nSize);
if(_pP == nullptr)
{
nSize_ = 0;
return _pP;
}
for(int i = 0; i < m_nSize; i++)
{
*(_pP + i) = *(m_pSource + i);
}
nSize_ = m_nSize;
return _pP;
}*/
template<typename T>
DynArray<T>::~DynArray()
{
Free();
}
template<typename T>
void DynArray<T>::Add(const T& value_)
{
Check(m_nSize + 1);
T* _pEnd = m_pSource + m_nSize;
m_alloc.construct(_pEnd, value_);
m_nSize++;
}
template<typename T>
void DynArray<T>::AddRange(const DynArray& arrItems_)
{
Check(m_nSize + arrItems_.GetSize());
for (int _i = 0; _i < arrItems_.m_nSize; _i++)
{
m_alloc.construct(m_pSource + m_nSize + _i, *(arrItems_.m_pSource + _i));
}
m_nSize += arrItems_.m_nSize;
}
template<typename T>
void DynArray<T>::Check(int nSize_)
{
if (m_nCapacity >= nSize_)
{
return;
}
int _nCapacity = nSize_ * 2;
T* _pSource = m_alloc.allocate(_nCapacity);
if (_pSource == nullptr)
{
throw "out of memory";
}
//std::uninitialized_copy_n(m_pSource, m_nSize, _pSource);
for(int i = 0; i < m_nSize; i++)
{
m_alloc.construct(_pSource + i, (*(m_pSource + i)));
}
int _nOldSize = m_nSize;
Free();
m_pSource = _pSource;
m_nSize = _nOldSize;
m_nCapacity = _nCapacity;
}
template<typename T>
void DynArray<T>::Insert(int nIndex_, const T& value_)
{
if (nIndex_ > m_nSize)
{
throw "Insert position error";
}
Check(m_nSize + 1);
m_alloc.construct(m_pSource + m_nSize, value_);
for (int _i = m_nSize - 1; _i >= nIndex_; _i--)
{
*(m_pSource + _i + 1) = *(m_pSource + _i);
}
*(m_pSource + nIndex_) = value_;
m_nSize++;
}
template<typename T>
void DynArray<T>::DeleteByIndex(int nIndex_)
{
if (nIndex_ < 0
|| nIndex_ >= m_nSize)
{
return;
}
// 前移
for (int _i = nIndex_ + 1; _i < m_nSize; _i++)
{
*(m_pSource + _i - 1) = *(m_pSource + _i);
}
m_alloc.destroy(m_pSource + m_nSize - 1);
m_nSize--;
if (m_nSize < m_nCapacity / 4)
{
Shrink();
}
}
template<typename T>
void DynArray<T>::DeleteByValue(const T& value_)
{
int _nIndex = Find([value_](const T& nT_)->bool
{
if (nT_ == value_)
{
return true;
}
else
{
return false;
}
});
if (_nIndex == -1)
{
return;
}
DeleteByIndex(_nIndex);
}
template<typename T>
void DynArray<T>::Shrink()
{
int _nSize = m_nSize;
int _nCapacity = (m_nCapacity / 2);
T* _pSource = m_alloc.allocate(_nCapacity);
if (_pSource == nullptr)
{
throw "out of memory";
}
std::uninitialized_copy_n(m_pSource, m_nSize, _pSource);
Free();
m_pSource = _pSource;
m_nSize = _nSize;
m_nCapacity = _nCapacity;
}
template<typename T>
void DynArray<T>::DeleteAll()
{
Free();
}
template<typename T>
bool DynArray<T>::SetValue(int nIndex_, const T& value_)
{
if (nIndex_ < 0
|| nIndex_ >= m_nSize)
{
return false;
}
*(m_pSource + nIndex_) = value_;
return true;
}
template<typename T>
bool DynArray<T>::GetValue(int nIndex_, T& value_) const
{
if (nIndex_ < 0
|| nIndex_ >= m_nSize)
{
return false;
}
value_ = *(m_pSource + nIndex_);
return true;
}
template<typename T>
int DynArray<T>::GetSize() const
{
return m_nSize;
}
template<typename T>
int DynArray<T>::GetCapacity() const
{
return m_nCapacity;
}
template<typename T>
T& DynArray<T>::operator[](int nIndex_)
{
if (nIndex_ < 0
|| nIndex_ >= m_nSize)
{
throw "index is error";
}
return *(m_pSource + nIndex_);
}
template<typename T>
const T& DynArray<T>::operator[](int nIndex_) const
{
if (nIndex_ < 0
|| nIndex_ >= m_nSize)
{
throw "index is error";
}
return *(m_pSource + nIndex_);
}
}
#endif // DYNARRAY_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Date.h
|
#ifndef NLIB_DATE_H
#define NLIB_DATE_H
#include "header.h"
struct tm;
class Date
{
public:
struct YearMonthDay
{
int year; // [1900..2500]
int month; // [1..12]
int day; // [1..31]
};
static const int s_nDaysPerWeek = 7;
static const int s_nDayOf1970_01_01;
Date()
: m_nDayNumber(0)
{
}
Date(
int year,
int month,
int day);
explicit Date(int DayNum)
: m_nDayNumber(DayNum)
{}
explicit Date(const struct tm&);
void swap(Date& that)
{
std::swap(m_nDayNumber, that.m_nDayNumber);
}
bool valid() const
{
return m_nDayNumber > 0;
}
std::string toIsoString() const;
struct YearMonthDay yearMonthDay() const;
int year() const
{
return yearMonthDay().year;
}
int month() const
{
return yearMonthDay().month;
}
int day() const
{
return yearMonthDay().day;
}
int weekDay() const
{
return (m_nDayNumber+1) % s_nDaysPerWeek;
}
int DayNumber() const
{
return m_nDayNumber;
}
private:
int m_nDayNumber;
};
inline bool operator<(Date x, Date y)
{
return x.DayNumber() < y.DayNumber();
}
inline bool operator==(Date x, Date y)
{
return x.DayNumber() == y.DayNumber();
}
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/MuduoApp/muduocodec.h
|
// Author : XuBenHao
// Version : 1.0.0
// Mail : <EMAIL>
// Copyright : XuBenHao 2020 - 2030
//
#ifndef MUDUO_APP_MUDUOCODEC_H
#define MUDUO_APP_MUDUOCODEC_H
#include "header.h"
// 消息编码格式:
// 4字节长度[长度指的是数据部分的长度]+数据本身
// 消息解码:
// 先取出4字节
// 在取出该长度表示的数据部分
//
//
// 直接通过Tcp传递数值类型时,
// 需要
// 传递前将本机数值转换为网络字节序数值再写入
// 接收时,先取出数据内容,再将其转化为本机字节序再实际使用
//
// 如果传递的是字符串,
// 不需要上述处理
//
//
// Tcp的消息编码和解码其实就是应用层协议
class MuduoCodec
{
public:
explicit MuduoCodec();
// 每次套接字读出消息先是放入参数2的Buffer对象
// 并触发回调
// 但应用层回调里面要分析Buffer内容
// 看是否有一条完整信息取出一条或多条
// 还是本次略过,但后续累计到一条完整信息再处理
void onMessage(
const TcpConnectionPtr& conn,
Buffer* buf,
TimeStamp receiveTime);
void send(
TcpConnection* conn,
const StringPiece& message);
private:
const static size_t s_nHeaderLen = sizeof(int32_t);
};
#endif // MUDUOCODEC_H
|
Fragrant-Yang/git-test-copy
|
MuduoClient/Ui/lib.h
|
<filename>MuduoClient/Ui/lib.h
#ifndef APP_UI_LIB_H
#define APP_UI_LIB_H
#include "mainwindow.h"
#include "registerandloginwidget.h"
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/TimerQueue.h
|
#ifndef LIB_TIMERQUEUE_H
#define LIB_TIMERQUEUE_H
#include "Mutex.h"
#include "TimeStamp.h"
#include "CallBacks.h"
#include "Channel.h"
class EventLoop;
class Timer;
class TimerId;
class TimerQueue
{
public:
explicit TimerQueue(
EventLoop* loop);
~TimerQueue();
TimerId addTimer(
TimerCallback cb,
TimeStamp when,
double interval);
void cancel(
TimerId timerId);
private:
typedef std::pair<TimeStamp, Timer*>
Entry;
typedef std::set<Entry> TimerList;
typedef std::pair<Timer*, int64_t>
ActiveTimer;
typedef std::set<ActiveTimer>
ActiveTimerSet;
void addTimerInLoop(
Timer* timer);
void cancelInLoop(
TimerId timerId);
void handleRead();
std::vector<Entry> getExpired(
TimeStamp now);
void reset(
const std::vector<Entry>& expired,
TimeStamp now);
bool insert(
Timer* timer);
private:
EventLoop* m_pLoop;
const int m_nTimerFd;
Channel m_nTimerFdChannel;
// 二者总是保持一致
TimerList m_nTimers;
ActiveTimerSet m_nActiveTimers;
bool m_bCallingExpiredTimers;
ActiveTimerSet m_nCancelingTimers;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/MySqlAgent/header.h
|
<reponame>Fragrant-Yang/git-test-copy<gh_stars>1-10
#ifndef MYSQL_AGENT_HEADER_H
#define MYSQL_AGENT_HEADER_H
#include "Global/lib.h"
#include "../MyMuduo/Tcp/lib.h"
#include "../MyMuduo/Tcp/lib.h"
#include <mysql.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#endif // HEADER_H
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/EventLoopThreadPool.h
|
#ifndef NLIB_EVENTLOOPTHREADPOOL_H
#define NLIB_EVENTLOOPTHREADPOOL_H
#include "header.h"
// 事件循环线程池对象
// 可由可访问者用以实现
// 1.开启多个并行线程
// 2.获得开启的每个线程的属性/状态
// 3.与每个开启的线程进行交互
//
//
// 这里假定了
// 事件循环线程池对象的访问者
// 存在于一个线程中.
// 所以,
// 线程池对象成员访问中没有进行多线程下访问共享对象的互斥/同步处理
class EventLoop;
class EventLoopThread;
class EventLoopThreadPool
{
public:
typedef std::function<void(EventLoop*)> ThreadInitCallback;
EventLoopThreadPool(
EventLoop* baseLoop,
const string& nameArg);
~EventLoopThreadPool();
void setThreadNum(
int numThreads)
{
m_nNumThreads = numThreads;
}
void start(
const ThreadInitCallback& cb = ThreadInitCallback());
EventLoop* getNextLoop();
EventLoop* getLoopForHash(
size_t hashCode);
std::vector<EventLoop*> getAllLoops();
bool started() const
{
return m_bStarted;
}
const string& name() const
{
return m_strName;
}
private:
EventLoop* m_pBaseLoop;
string m_strName;
bool m_bStarted;
int m_nNumThreads;
int m_nNext;
std::vector<std::unique_ptr<EventLoopThread>> m_vecThreads;
std::vector<EventLoop*> m_vecLoops;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/LogStream.h
|
<filename>MyMuduo/Lib/LogStream.h
#ifndef NLIB_LOGSTREAM_H
#define NLIB_LOGSTREAM_H
#include "StringPiece.h"
const int s_nSmallBuffer = 4000;
const int s_nLargeBuffer = 4000*1000;
template<int SIZE>
class FixedBuffer
{
public:
FixedBuffer()
: m_pCur(m_arrData)
{
setCookie(cookieStart);
}
~FixedBuffer()
{
setCookie(cookieEnd);
}
void append(
const char* buf,
size_t len)
{
// 剩余空间可以容纳参数指定内容
if ((size_t)(avail()) > len)
{
memcpy(m_pCur, buf, len);
m_pCur += len;
// m_pCur指向下一可用字节位置
}
}
const char* data() const
{
return m_arrData;
}
// 返回已经存储数据长度
int length() const
{
return (int)(m_pCur - m_arrData);
}
// 返回下一可用字节位置指针
char* current()
{
return m_pCur;
}
// 返回剩余可用空间大小
int avail() const
{
return (int)(end() - m_pCur);
}
// 无条件移动
void add(size_t len)
{
m_pCur += len;
}
// 重置
void reset()
{
m_pCur = m_arrData;
}
// 缓冲区内容置0
void bzero()
{
memset(m_arrData, 0, sizeof(m_arrData));
}
const char* debugString();
// 设置函数指针
void setCookie(void (*cookie)())
{
m_pCookie = cookie;
}
// 类型转换,转化为string类型
string toString() const
{
return string(m_arrData, length());
}
// 转化为StringPiece类型
StringPiece toStringPiece() const
{
return StringPiece(m_arrData, length());
}
private:
// 移动到缓冲区尾后字节位置
const char* end() const
{
return m_arrData + sizeof(m_arrData);
}
static void cookieStart();
static void cookieEnd();
void (*m_pCookie)();
char m_arrData[SIZE];
char* m_pCur;
};
class LogStream
{
typedef LogStream Self;
public:
// Buffer是一个固定大小的缓冲区
typedef FixedBuffer<s_nSmallBuffer> Buffer;
// LogStream支持<<操作符
Self& operator<<(bool v)
{
// 往缓冲区写入bool类型对象
m_nBuffer.append(v ? "1" : "0", 1);
return *this;
}
Self& operator<<(short);
Self& operator<<(unsigned short);
Self& operator<<(int);
Self& operator<<(unsigned int);
Self& operator<<(long);
Self& operator<<(unsigned long);
Self& operator<<(long long);
Self& operator<<(unsigned long long);
Self& operator<<(const void*);
Self& operator<<(float v)
{
*this << (double)(v);
return *this;
}
Self& operator<<(double);
Self& operator<<(char v)
{
m_nBuffer.append(&v, 1);
return *this;
}
Self& operator<<(const char* str)
{
if (str)
{
m_nBuffer.append(str, strlen(str));
}
else
{
m_nBuffer.append("(null)", 6);
}
return *this;
}
Self& operator<<(const unsigned char* str)
{
return operator<<((const char*)(str));
}
Self& operator<<(const string& v)
{
m_nBuffer.append(v.c_str(), v.size());
return *this;
}
Self& operator<<(const StringPiece& v)
{
m_nBuffer.append(v.data(), v.size());
return *this;
}
Self& operator<<(const Buffer& v)
{
*this << v.toStringPiece();
return *this;
}
void append(const char* data, int len)
{
m_nBuffer.append(data, len);
}
const Buffer& buffer() const
{
return m_nBuffer;
}
void resetBuffer()
{
m_nBuffer.reset();
}
private:
void staticCheck();
template<typename T>
void formatInteger(T);
Buffer m_nBuffer;
static const int s_nMaxNumericSize = 32;
};
class Fmt
{
public:
template<typename T>
Fmt(const char* fmt, T val);
const char* data() const
{
return m_arrBuf;
}
int length() const
{
return m_nLength;
}
private:
char m_arrBuf[32];
int m_nLength;
};
inline LogStream& operator<<(
LogStream& s,
const Fmt& fmt)
{
s.append(fmt.data(), fmt.length());
return s;
}
string formatSI(int64_t n);
string formatIEC(int64_t n);
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/DataStruct/doublelist.h
|
<gh_stars>1-10
// Author : XuBenHao
// Version : 1.0.0
// Mail : <EMAIL>
// Copyright : XuBenHao 2020 - 2030
#ifndef DATA_STRUCT_DOUBLELIST_H
#define DATA_STRUCT_DOUBLELIST_H
#include "header.h"
namespace NDataStruct
{
template <typename T>
class DoubleList
{
public:
class Node
{
public:
T GetValue() const
{
return m_nValue;
}
void SetValue(const T& nValue_)
{
m_nValue = nValue_;
}
private:
Node()
{
m_pPre = nullptr;
m_pNext = nullptr;
}
~Node()
{
}
T m_nValue;
Node *m_pPre;
Node *m_pNext;
friend class DoubleList < T >;
};
DoubleList();
// 拷贝构造
DoubleList(const DoubleList& list_);
// 赋值
DoubleList<T>& operator=(const DoubleList& list_);
virtual ~DoubleList();
// 判空
bool IsEmpty() const;
// 容量
int GetSize() const;
// 插入:
// 插入元素成为首元素
void InsertFirst(const T& nNewValue_);
// 插入元素成为尾元素
void InsertLast(const T& nNewValue_);
// 插入元素成为尾元素
void Add(const T& nNewValue_);
// 在指定元素前面插入
void InsertBefore(Node* pElement_, const T& nNewValue_);
// 在指定元素后面插入
void InsertAfter(Node* pElement_, const T& nNewValue_);
// 删除
// 删除首元素
void DeleteFirst();
// 删除尾元素
void DeleteLast();
// 删除指定位置元素
void Delete(Node* pElement_);
// 删除指定值的首个元素
void Delete(const T& nValue_);
// 元素访问:
// 获取首个元素
Node* GetFirst() const;
// 获取尾部元素
Node* GetLast() const;
// 搜索
Node* Find(std::function<bool(const T&)> predictFunction_) const;
// 容器遍历:
// 获取输入元素下一元素
Node* GetNext(Node* pElement_) const;
// 获取输入元素上一元素
Node* GetPre(Node* pElement_) const;
private:
Node *m_pFirst;
Node *m_pLast;
};
template<typename T>
DoubleList<T>::DoubleList() :
m_pFirst(nullptr), m_pLast(nullptr)
{
}
template<typename T>
DoubleList<T>::~DoubleList()
{
// 保证:
// 非空时,尾元素下一元素指针为空。
// 为空时,m_pBegin,m_pEnd均为null。
Node *_pCur = m_pFirst;
while (_pCur)
{
Node* _pTemp = _pCur;
_pCur = _pCur->m_pNext;
delete _pTemp;
_pTemp = nullptr;
}
m_pFirst = nullptr;
m_pLast = nullptr;
}
template<typename T>
DoubleList<T>::DoubleList(const DoubleList& list_) :
m_pFirst(nullptr), m_pLast(nullptr)
{
Node *_pCur = list_.m_pFirst;
while (_pCur)
{
Node* _pTemp = _pCur;
_pCur = _pCur->m_pNext;
Add(_pTemp->GetValue());
}
}
template<typename T>
DoubleList<T>& DoubleList<T>::operator=(const DoubleList& list_)
{
if (this == &list_)
{
return *this;
}
this->~DoubleList();
// 假定:
Node *_pCur = list_.m_pFirst;
while (_pCur)
{
Node* _pTemp = _pCur;
_pCur = _pCur->m_pNext;
Add(_pTemp->GetValue());
}
return *this;
}
template<typename T>
bool DoubleList<T>::IsEmpty() const
{
if (m_pFirst == nullptr)
{
assert(m_pLast == nullptr);
return true;
}
else
{
return false;
}
}
template<typename T>
int DoubleList<T>::GetSize() const
{
Node *_pCur = m_pFirst;
int _nSize = 0;
while (_pCur)
{
_nSize++;
_pCur = _pCur->m_pNext;
}
return _nSize;
}
template<typename T>
void DoubleList<T>::InsertFirst(const T& nNewValue_)
{
Node *_pElement = nullptr;
try
{
_pElement = new Node();
}
catch (...)
{
_pElement = nullptr;
throw "out of memory";
}
_pElement->SetValue(nNewValue_);
if (IsEmpty() == true)
{
m_pFirst = _pElement;
m_pLast = _pElement;
}
else
{
_pElement->m_pNext = m_pFirst;
m_pFirst->m_pPre = _pElement;
m_pFirst = _pElement;
}
}
template<typename T>
void DoubleList<T>::InsertLast(const T& nNewValue_)
{
Node *_pElement = nullptr;
try
{
_pElement = new Node();
}
catch (...)
{
_pElement = nullptr;
throw "out of memory";
}
_pElement->SetValue(nNewValue_);
if (IsEmpty() == true)
{
m_pFirst = _pElement;
m_pLast = _pElement;
}
else
{
m_pLast->m_pNext = _pElement;
_pElement->m_pPre = m_pLast;
m_pLast = _pElement;
}
}
template<typename T>
void DoubleList<T>::Add(const T& nNewValue_)
{
InsertLast(nNewValue_);
}
template<typename T>
void DoubleList<T>::InsertBefore(Node* pElement_, const T& nNewValue_)
{
if (pElement_ == nullptr)
{
return;
}
Node* _pPre = pElement_->m_pPre;
if (_pPre == nullptr)
{
InsertFirst(nNewValue_);
}
else
{
Node *_pNewElement = nullptr;
try
{
_pNewElement = new Node();
}
catch (...)
{
_pNewElement = nullptr;
throw "out of memory";
}
_pNewElement->SetValue(nNewValue_);
_pPre->m_pNext = _pNewElement;
_pNewElement->m_pPre = _pPre;
pElement_->m_pPre = _pNewElement;
_pNewElement->m_pNext = pElement_;
}
}
template<typename T>
void DoubleList<T>::InsertAfter(Node* pElement_, const T& nNewValue_)
{
if (pElement_ == nullptr)
{
return;
}
Node* _pNext = pElement_->m_pNext;
if (_pNext == nullptr)
{
InsertLast(nNewValue_);
}
else
{
Node *_pNewElement = nullptr;
try
{
_pNewElement = new Node();
}
catch (...)
{
_pNewElement = nullptr;
throw "out of memory";
}
_pNewElement->SetValue(nNewValue_);
pElement_->m_pNext = _pNewElement;
_pNewElement->m_pPre = pElement_;
_pNext->m_pPre = _pNewElement;
_pNewElement->m_pNext = _pNext;
}
}
template<typename T>
void DoubleList<T>::DeleteFirst()
{
if (IsEmpty())
{
return;
}
else if (m_pFirst == m_pLast && m_pFirst != nullptr)
{
delete m_pFirst;
m_pFirst = nullptr;
m_pLast = nullptr;
}
else
{
Node* _pDelete = m_pFirst;
m_pFirst = _pDelete->m_pNext;
m_pFirst->m_pPre = nullptr;
delete _pDelete;
_pDelete = nullptr;
}
}
template<typename T>
void DoubleList<T>::DeleteLast()
{
if (IsEmpty())
{
return;
}
else if (m_pFirst == m_pLast && m_pFirst != nullptr)
{
delete m_pFirst;
m_pFirst = nullptr;
m_pLast = nullptr;
}
else
{
Node* _pDelete = m_pLast;
m_pLast = m_pLast->m_pPre;
m_pLast->m_pNext = nullptr;
delete _pDelete;
_pDelete = nullptr;
}
}
template<typename T>
void DoubleList<T>::Delete(Node* pElement_)
{
if (pElement_ == nullptr)
{
return;
}
Node* _pPre = pElement_->m_pPre;
Node* _pNext = pElement_->m_pNext;
if (_pPre == nullptr)
{
DeleteFirst();
}
else if (_pNext == nullptr)
{
DeleteLast();
}
else
{
_pPre->m_pNext = _pNext;
_pNext->m_pPre = _pPre;
delete pElement_;
pElement_ = nullptr;
}
}
template<typename T>
void DoubleList<T>::Delete(const T& nValue_)
{
Node* _pDeletedElement = Find([nValue_](const T& nT_)->bool
{
if (nT_ == nValue_)
{
return true;
}
else
{
return false;
}
});
Delete(_pDeletedElement);
}
template<typename T>
typename DoubleList<T>::Node* DoubleList<T>::GetFirst() const
{
return m_pFirst;
}
template<typename T>
typename DoubleList<T>::Node* DoubleList<T>::GetLast() const
{
return m_pLast;
}
template<typename T>
typename DoubleList<T>::Node* DoubleList<T>::Find(std::function<bool(const T&)> predictFunction_) const
{
Node *_pCur = m_pFirst;
while (_pCur)
{
if (predictFunction_(_pCur->GetValue()) == true)
{
break;
}
_pCur = _pCur->m_pNext;
}
return _pCur;
}
template<typename T>
typename DoubleList<T>::Node* DoubleList<T>::GetNext(Node* pElement_) const
{
if (pElement_ == nullptr)
{
return nullptr;
}
return pElement_->m_pNext;
}
template<typename T>
typename DoubleList<T>::Node* DoubleList<T>::GetPre(Node* pElement_) const
{
if (pElement_ == nullptr)
{
return nullptr;
}
return pElement_->m_pPre;
}
}
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Logging.h
|
#ifndef NLIB_LOGGING_H
#define NLIB_LOGGING_H
#include "LogStream.h"
#include "TimeStamp.h"
class TimeZone;
class Logger
{
public:
enum LogLevel
{
TRACE,
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
NUM_LOG_LEVELS,
};
// 类
class SourceFile
{
public:
// 类成员函数是模板函数
template<int N>
SourceFile(const char (&arr_)[N])
: m_pData(arr_),
m_nSize(N-1)// 有效字符个数
{
// 寻找子串
const char* slash = strrchr(m_pData, '/');
//
if (slash)
{
// 移动到/字符下一字符位置
m_pData = slash + 1;
m_nSize -= (int)(m_pData - arr_);
}
}
// m_pData只保存文件名,不含路径信息
explicit SourceFile(
const char* filename)
: m_pData(filename)
{
const char* slash = strrchr(filename, '/');
if (slash)
{
m_pData = slash + 1;
}
m_nSize = (int)(strlen(m_pData));
}
const char* m_pData;
int m_nSize;
};
class Impl
{
public:
typedef Logger::LogLevel LogLevel;
Impl(LogLevel level,
int old_errno,
const SourceFile& file,
int line);
void formatTime();
void finish();
TimeStamp m_nTime;
LogStream m_nStream;
LogLevel m_nLevel;
int m_nLine;
SourceFile m_nBaseName;
};
public:
Logger(
SourceFile file,
int line);
Logger(
SourceFile file,
int line,
LogLevel level);
Logger(
SourceFile file,
int line,
LogLevel level,
const char* func);
Logger(
SourceFile file,
int line,
bool toAbort);
~Logger();
LogStream& stream()
{
return m_nImpl.m_nStream;
}
static LogLevel logLevel();
static void setLogLevel(
LogLevel level);
typedef void (*OutputFunc)(
const char* msg,
int len);
typedef void (*FlushFunc)();
static void setOutput(OutputFunc);
static void setFlush(FlushFunc);
static void setTimeZone(const TimeZone& tz);
private:
Impl m_nImpl;
};
extern Logger::LogLevel g_logLevel;
inline Logger::LogLevel Logger::logLevel()
{
return g_logLevel;
}
#define LOG_TRACE if(g_logLevel >= Logger::TRACE)\
Logger(\
__FILE__, \
__LINE__,\
Logger::TRACE,\
__func__).stream()
#define LOG_DEBUG if(g_logLevel >= Logger::DEBUG)\
Logger(\
__FILE__, \
__LINE__, \
Logger::DEBUG, \
__func__).stream()
#define LOG_INFO if(g_logLevel >= Logger::INFO)\
Logger(\
__FILE__, \
__LINE__).stream()
#define LOG_WARN if(g_logLevel >= Logger::WARN)\
Logger(\
__FILE__, \
__LINE__, \
Logger::WARN).stream()
#define LOG_ERROR if(g_logLevel >= Logger::ERROR)\
Logger(\
__FILE__, \
__LINE__, \
Logger::ERROR).stream()
#define LOG_FATAL if(g_logLevel >= Logger::FATAL)\
Logger(\
__FILE__, \
__LINE__, \
Logger::FATAL).stream()
#define LOG_SYSERR Logger(\
__FILE__, \
__LINE__, \
false).stream()
#define LOG_SYSFATAL Logger(\
__FILE__, \
__LINE__, \
true).stream()
const char* strerror_tl(int savedErrno);
#define CHECK_NOTNULL(val) \
CheckNotNull(\
__FILE__, \
__LINE__, \
"'" #val "' Must be non NULL", \
(val))
template <typename T>
T* CheckNotNull(
Logger::SourceFile file,
int line,
const char *names,
T* ptr)
{
if (ptr == NULL)
{
Logger(
file,
line,
Logger::FATAL).stream() << names;
}
return ptr;
}
#endif
|
Fragrant-Yang/git-test-copy
|
MyMuduo/Lib/Exception.h
|
<gh_stars>1-10
#ifndef NLIB_EXCEPTION_H
#define NLIB_EXCEPTION_H
#include "header.h"
class Exception : public std::exception
{
public:
Exception(string what);
~Exception() noexcept override = default;
const char* what() const noexcept override
{
return m_strMessage.c_str();
}
const char* stackTrace() const noexcept
{
return m_strStack.c_str();
}
private:
string m_strMessage;
string m_strStack;
};
#endif
|
Fragrant-Yang/git-test-copy
|
MuduoServer/Application/header.h
|
#ifndef APPLICATION_HEADER_H
#define APPLICATION_HEADER_H
#include "Global/lib.h"
#include "MuduoApp/lib.h"
#endif // HEADER_H
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.