├── README.md ├── source ├── Makefile └── main │ ├── Makefile │ ├── error.h │ ├── main.cpp │ ├── roster.h │ ├── match.h │ ├── team.h │ ├── brackets.h │ ├── team.cpp │ ├── roster.cpp │ ├── match.cpp │ └── brackets.cpp ├── Makefile ├── samples ├── 2_teams.csv ├── 3_teams.csv ├── 5_teams_csv ├── 8_teams.csv ├── 16_teams.csv ├── 16_teams_seq.csv ├── 29_teams.csv ├── 32_teams.csv └── 29_teams_seq.csv ├── documentation ├── file-header.template └── project_standards.html └── LICENSE.txt /README.md: -------------------------------------------------------------------------------- 1 | # text-tourney-brackets 2 | Simple tool to build and process brackets using a text input and output. 3 | -------------------------------------------------------------------------------- /source/Makefile: -------------------------------------------------------------------------------- 1 | SOURCE_DIR = main 2 | BRACKETS_DIR = $(SOURCE_DIR) 3 | BRACKETS_EXE = $(BRACKETS_DIR)/brackets 4 | BIN_DIR = bin 5 | 6 | .PHONY: brackets 7 | 8 | brackets: 9 | $(MAKE) -C $(SOURCE_DIR) 10 | cp $(BRACKETS_EXE) $(BIN_DIR) 11 | 12 | clean: 13 | $(MAKE) -C $(SOURCE_DIR) clean 14 | 15 | all: brackets 16 | -------------------------------------------------------------------------------- /source/main/Makefile: -------------------------------------------------------------------------------- 1 | # First pass ultra simple Makefile 2 | 3 | SOURCES = main.cpp brackets.cpp team.cpp roster.cpp match.cpp 4 | HEADERS = brackets.h 5 | 6 | CFLAGS=-fmessage-length=0 7 | 8 | brackets: $(SOURCES) $(HEADERS) 9 | g++ $(DEBUG) $(CFLAGS) -o brackets $(SOURCES) 10 | 11 | clean: 12 | rm -f *.o brackets 13 | 14 | all: brackets 15 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SOURCE_DIR = source 2 | BRACKETS_DIR = $(SOURCE_DIR)/main 3 | BRACKETS_EXE = brackets 4 | BRACKETS_PATH = $(BRACKETS_DIR)/$(BRACKETS_EXE) 5 | BIN_DIR = bin 6 | DEBUG = -g 7 | 8 | .PHONY: brackets 9 | 10 | brackets: 11 | $(MAKE) -C $(SOURCE_DIR) 12 | mkdir -p $(BIN_DIR) 13 | cp $(BRACKETS_PATH) $(BIN_DIR) 14 | 15 | clean: 16 | $(MAKE) -C $(SOURCE_DIR) clean 17 | rm -f $(BIN_DIR)/$(BRACKETS_EXE) 18 | 19 | all: brackets 20 | -------------------------------------------------------------------------------- /samples/2_teams.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | a2w47,Potolsky,Adam,USA,3 12 | a2w48,Potolsky,Liam,USA,1 13 | 14 | # Notice: Lexi has no seed defined, this is legal 15 | # Notice: Alicia has seed defined as zero, this is legal 16 | -------------------------------------------------------------------------------- /samples/3_teams.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | a2w47,Potolsky,Adam,USA,3 12 | a2w48,Potolsky,Liam,USA,1 13 | a2w49,Potolsky,Genevieve,USA,2 14 | 15 | # Notice: Lexi has no seed defined, this is legal 16 | # Notice: Alicia has seed defined as zero, this is legal 17 | -------------------------------------------------------------------------------- /samples/5_teams_csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | a2w47,Potolsky,Adam,USA,3 12 | a2w48,Potolsky,Liam,USA,1 13 | a2w49,Potolsky,Genevieve,USA,2 14 | a2w50,Potolsky,Lexi,USA, 15 | a2w51,Potolsky,Alicia,USA,0 16 | 17 | # Notice: Lexi has no seed defined, this is legal 18 | # Notice: Alicia has seed defined as zero, this is legal 19 | -------------------------------------------------------------------------------- /samples/8_teams.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | a2w47,Potolsky,Adam,USA,3 12 | a2w48,Potolsky,Liam,USA,1 13 | a2w49,Potolsky,Genevieve,USA,2 14 | a2w50,Potolsky,Lexi,USA, 15 | a2w51,Potolsky,Alicia,USA,0 16 | 17 | a2w52,Foonman, Mario,Slobobia,0 18 | 19 | a2w53,Cart, Mario,Sumerland,0 20 | a2w54,Cart, Wario,Sumerland,0 21 | 22 | # Notice: Lexi has no seed defined, this is legal 23 | # Notice: Alicia has seed defined as zero, this is legal 24 | -------------------------------------------------------------------------------- /samples/16_teams.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | a2w47,Potolsky,Adam,USA,3 12 | a2w48,Potolsky,Liam,USA,1 13 | a2w49,Potolsky,Genevieve,USA,2 14 | a2w50,Potolsky,Lexi,USA, 15 | a2w51,Potolsky,Alicia,USA,0 16 | a2w52,Foonman, Mario,Slobobia,0 17 | a2w53,Cart,Mario,Sumerland,0 18 | a2w54,Cart,Wario,Sumerland,0 19 | a2w55,Smith,Adam,USA,4 20 | a2w56,Smith,Liam,USA,5 21 | a2w57,Smith,Genevieve,USA,6 22 | a2w58,Smith,Lexi,USA, 23 | a2w59,Smith,Alicia,USA,0 24 | a2w60,Smith,Mario,Slobobia,0 25 | a2w61,Smith,Egbert,Sumerland,0 26 | a2w62,Smith,Wario,Sumerland,0 27 | 28 | # Notice: Lexi has no seed defined, this is legal 29 | # Notice: Alicia has seed defined as zero, this is legal 30 | -------------------------------------------------------------------------------- /samples/16_teams_seq.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | ID_00,team_01_last,team_01_first,USA_01,1 12 | ID_01,team_02_last,team_02_first,USA_02,2 13 | ID_02,team_03_last,team_03_first,USA_03,3 14 | ID_03,team_04_last,team_04_first,USA_04,4 15 | ID_04,team_05_last,team_05_first,USA_05,5 16 | ID_05,team_06_last,team_06_first,USA_06,6 17 | ID_06,team_07_last,team_07_first,USA_07,7 18 | ID_07,team_08_last,team_08_first,USA_08,8 19 | ID_08,team_09_last,team_09_first,USA_09,9 20 | ID_09,team_10_last,team_10_first,USA_10,10 21 | ID_10,team_11_last,team_11_first,USA_11,11 22 | ID_11,team_12_last,team_12_first,USA_12,12 23 | ID_12,team_13_last,team_13_first,USA_13,13 24 | ID_13,team_14_last,team_14_first,USA_14,14 25 | ID_14,team_15_last,team_15_first,USA_15,15 26 | ID_15,team_16_last,team_16_first,USA_16,16 27 | 28 | # Notice: Lexi has no seed defined, this is legal 29 | # Notice: Alicia has seed defined as zero, this is legal 30 | -------------------------------------------------------------------------------- /documentation/file-header.template: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * text-tourney-brackets 4 | * 5 | * Simple text driven tournament bracketing tool 6 | * 7 | * Copyright (C) 2015 Adam Potolsky 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with this program; if not, write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | * 23 | * Filename: main.cpp 24 | * Description: main.cpp contains the execuation entry routine 25 | * Notations: 26 | * 27 | * Author: Adam Potolsky 28 | * 29 | * Revision History: Under Revision Control 30 | * 31 | * Public Routines: 32 | * 33 | * Private routines: 34 | * 35 | *******************************************************************************/ 36 | -------------------------------------------------------------------------------- /samples/29_teams.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | a2w47,Potolsky,Adam,USA,3 12 | a2w48,Potolsky,Liam,USA,1 13 | a2w49,Potolsky,Genevieve,USA,2 14 | a2w50,Potolsky,Lexi,USA, 15 | a2w51,Potolsky,Alicia,USA,0 16 | a2w52,Foonman, Mario,Slobobia,0 17 | a2w53,Cart,Mario,Sumerland,0 18 | a2w54,Cart,Wario,Sumerland,0 19 | a2w55,Smith,Adam,USA,4 20 | a2w56,Smith,Liam,USA,5 21 | a2w57,Smith,Genevieve,USA,6 22 | a2w58,Smith,Lexi,USA, 23 | a2w59,Smith,Alicia,USA,0 24 | a2w60,Smith,Mario,Slobobia,0 25 | a2w61,Smith,Egbert,Sumerland,0 26 | a2w62,Smith,Wario,Sumerland,0 27 | 28 | a2w63,Johnson,Adam,USA,3 29 | a2w64,Johnson,Liam,USA,1 30 | a2w65,Johnson,Genevieve,USA,2 31 | a2w66,Johnson,Lexi,USA, 32 | a2w67,Johnson,Alicia,USA,0 33 | a2w68,Johnson, Mario,Slobobia,0 34 | a2w69,Cart,Mario,Sumerland,0 35 | a2w70,Johnson, Wario,Sumerland,0 36 | a2w71,Chang,Adam,USA,4 37 | a2w72,Chang,Liam,USA,5 38 | a2w73,Chang,Genevieve,USA,6 39 | a2w74,Chang,Lexi,USA, 40 | a2w75,Chang,Alicia,USA,0 41 | 42 | # Notice: Lexi has no seed defined, this is legal 43 | # Notice: Alicia has seed defined as zero, this is legal 44 | -------------------------------------------------------------------------------- /samples/32_teams.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | a2w47,Potolsky,Adam,USA,3 12 | a2w48,Potolsky,Liam,USA,1 13 | a2w49,Potolsky,Genevieve,USA,2 14 | a2w50,Potolsky,Lexi,USA, 15 | a2w51,Potolsky,Alicia,USA,0 16 | a2w52,Foonman, Mario,Slobobia,0 17 | a2w53,Cart,Mario,Sumerland,0 18 | a2w54,Cart,Wario,Sumerland,0 19 | a2w55,Smith,Adam,USA,4 20 | a2w56,Smith,Liam,USA,5 21 | a2w57,Smith,Genevieve,USA,6 22 | a2w58,Smith,Lexi,USA, 23 | a2w59,Smith,Alicia,USA,0 24 | a2w60,Smith,Mario,Slobobia,0 25 | a2w61,Smith,Egbert,Sumerland,0 26 | a2w62,Smith,Wario,Sumerland,0 27 | 28 | a2w63,Johnson,Adam,USA,3 29 | a2w64,Johnson,Liam,USA,1 30 | a2w65,Johnson,Genevieve,USA,2 31 | a2w66,Johnson,Lexi,USA, 32 | a2w67,Johnson,Alicia,USA,0 33 | a2w68,Johnson, Mario,Slobobia,0 34 | a2w69,Cart,Mario,Sumerland,0 35 | a2w70,Johnson, Wario,Sumerland,0 36 | a2w71,Chang,Adam,USA,4 37 | a2w72,Chang,Liam,USA,5 38 | a2w73,Chang,Genevieve,USA,6 39 | a2w74,Chang,Lexi,USA, 40 | a2w75,Chang,Alicia,USA,0 41 | a2w76,Chang,Mario,Slobobia,0 42 | a2w77,Chang,Egbert,Sumerland,0 43 | a2w78,Chang,Wario,Sumerland,0 44 | 45 | # Notice: Lexi has no seed defined, this is legal 46 | # Notice: Alicia has seed defined as zero, this is legal 47 | -------------------------------------------------------------------------------- /source/main/error.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /******************************************************************************* 4 | * 5 | * text-tourney-brackets 6 | * 7 | * Simple text driven tournament bracketing tool 8 | * 9 | * Copyright (C) 2015 Adam Potolsky 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with this program; if not, write to the Free Software Foundation, Inc., 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | * 25 | * Filename: error.h 26 | * 27 | * Description: error.h contains definitions for routines that use error.cpp 28 | * 29 | * Notations: 30 | * 31 | * Author: Adam Potolsky 32 | * 33 | * Revision History: Under Revision Control 34 | * 35 | * Public Routines: 36 | * 37 | * Private routines: 38 | * 39 | *******************************************************************************/ 40 | #include 41 | 42 | typedef enum ttb_error_codes { 43 | ttb_unknown = -1, 44 | ttb_OK = 0, 45 | ttb_EOF = 10, 46 | ttb_no_roster = 20, 47 | ttb_match_full = 30, 48 | 49 | 50 | // Do not add error codes below this entry 51 | ttb_last_error_code 52 | 53 | } ttb_error_t; 54 | -------------------------------------------------------------------------------- /samples/29_teams_seq.csv: -------------------------------------------------------------------------------- 1 | # Comments may only be whole lines and the first character on the line must be a # 2 | # Comments and blank lines are ignored 3 | 4 | # Seed values are optional but must be uniquie if not '0' (zero) 5 | # A seed of 0 is the same as no seed defined 6 | 7 | # Each team (competitor) is defined in a comma separated value list 8 | 9 | # ID, Last Name, First Name, Residence, Seed 10 | 11 | ID_00,team_01_last,team_01_first,USA_01,1 12 | ID_01,team_02_last,team_02_first,USA_02,2 13 | ID_02,team_03_last,team_03_first,USA_03,3 14 | ID_03,team_04_last,team_04_first,USA_04,4 15 | ID_04,team_05_last,team_05_first,USA_05,5 16 | ID_05,team_06_last,team_06_first,USA_06,6 17 | ID_06,team_07_last,team_07_first,USA_07,7 18 | ID_07,team_08_last,team_08_first,USA_08,8 19 | ID_08,team_09_last,team_09_first,USA_09,9 20 | ID_09,team_10_last,team_10_first,USA_10,10 21 | ID_10,team_11_last,team_11_first,USA_11,11 22 | ID_11,team_12_last,team_12_first,USA_12,12 23 | ID_12,team_13_last,team_13_first,USA_13,13 24 | ID_13,team_14_last,team_14_first,USA_14,14 25 | ID_14,team_15_last,team_15_first,USA_15,15 26 | ID_15,team_16_last,team_16_first,USA_16,16 27 | ID_16,team_17_last,team_17_first,USA_17,17 28 | ID_17,team_18_last,team_18_first,USA_18,18 29 | ID_18,team_19_last,team_19_first,USA_19,19 30 | ID_19,team_20_last,team_10_first,USA_20,20 31 | ID_20,team_21_last,team_21_first,USA_21,21 32 | ID_21,team_22_last,team_22_first,USA_22,22 33 | ID_22,team_23_last,team_23_first,USA_23,23 34 | ID_23,team_24_last,team_24_first,USA_24,24 35 | ID_24,team_25_last,team_25_first,USA_25,25 36 | ID_25,team_26_last,team_26_first,USA_26,26 37 | ID_26,team_27_last,team_27_first,USA_27,27 38 | ID_27,team_28_last,team_28_first,USA_28,28 39 | ID_28,team_29_last,team_29_first,USA_29,29 40 | 41 | # Notice: Lexi has no seed defined, this is legal 42 | # Notice: Alicia has seed defined as zero, this is legal 43 | -------------------------------------------------------------------------------- /source/main/main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * text-tourney-brackets 4 | * 5 | * Simple text driven tournament bracketing tool 6 | * 7 | * Copyright (C) 2015 Adam Potolsky 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with this program; if not, write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | * 23 | * Filename: main.cpp 24 | * Description: main.cpp contains the execuation entry routine 25 | * Notations: 26 | * 27 | * Author: Adam Potolsky 28 | * 29 | * Revision History: Under Revision Control 30 | * 31 | * Public Routines: 32 | * int main(int argc , char *argv[] ); 33 | * 34 | * Private routines: 35 | * 36 | *******************************************************************************/ 37 | #include "error.h" 38 | #include "team.h" 39 | #include "roster.h" 40 | #include "brackets.h" 41 | #include 42 | #include 43 | 44 | // TODO: fill in usage 45 | void usage() 46 | { 47 | std::cout << "USAGE:" << std::endl; 48 | std::cout << " Eventually this will be filled in" << std::endl; 49 | 50 | } 51 | 52 | int main( int argc , char *argv[]) 53 | { 54 | int cnt = 1; // Start at 1, 0 is the name of the executable 55 | 56 | std::string sTeamFilename; 57 | 58 | while(NULL != argv[cnt]) 59 | { 60 | if(argv[cnt][0] == '-') { 61 | if(argv[cnt][1] == 'h') { 62 | usage(); 63 | return 0; 64 | } 65 | } else { 66 | sTeamFilename.assign(argv[cnt]); 67 | } 68 | cnt++; 69 | } 70 | 71 | //std::cout << "DEBUG: sTeamFilename:" << sTeamFilename << std::endl; 72 | 73 | Brackets bracket(sTeamFilename); 74 | 75 | bracket.setup_brackets(); 76 | 77 | bracket.display_heats(); 78 | 79 | bracket.show_bracket(); 80 | 81 | bracket.resolve(); 82 | 83 | bracket.show_bracket(); 84 | 85 | 86 | //std::cout << "DEBUG: number of teams:" << bracket.team_count() << std::endl; 87 | 88 | //std::cout << "DEBUG: bracket size:" << bracket.size() << std::endl; 89 | 90 | //std::cout << "DEBUG: bracket depth:" << bracket.get_depth() << std::endl; 91 | 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /source/main/roster.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /******************************************************************************* 4 | * 5 | * text-tourney-brackets 6 | * 7 | * Simple text driven tournament bracketing tool 8 | * 9 | * Copyright (C) 2015 Adam Potolsky 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with this program; if not, write to the Free Software Foundation, Inc., 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | * 25 | * Filename: roster.h 26 | * Description: roster.h contains the definitions for roster.cpp 27 | * Notations: 28 | * 29 | * Author: Adam Potolsky 30 | * 31 | * Revision History: Under Revision Control 32 | * 33 | * Public Routines: 34 | * int load_teams(std::string filename); 35 | * 36 | * Private routines: 37 | * 38 | *******************************************************************************/ 39 | #include 40 | #include 41 | #include 42 | #include "error.h" 43 | #include "team.h" 44 | 45 | /******************************************************************************* 46 | * * 47 | * Class Roster * 48 | * * 49 | * Description: Class the defines a roster of teams * 50 | * * 51 | * Requirements: team * 52 | * * 53 | * NOTE: team_list contains the real teams in the bracket. It must not include * 54 | * bye-teams. The bye-teams are added when the brackets are built. * 55 | * * 56 | *******************************************************************************/ 57 | 58 | class Roster 59 | { 60 | public: 61 | Roster(); 62 | 63 | Roster(std::string filename); 64 | 65 | std::vector team_list; 66 | 67 | ttb_error_t display_team_list(); 68 | ttb_error_t add_team(team t); 69 | ttb_error_t read_next_team(); 70 | ttb_error_t load_roster(std::string filename); 71 | 72 | team make_a_bye(); 73 | 74 | int size() { return team_list.size(); } 75 | 76 | private: 77 | std::ifstream file; 78 | 79 | 80 | }; 81 | -------------------------------------------------------------------------------- /source/main/match.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /******************************************************************************* 4 | * 5 | * text-tourney-brackets 6 | * 7 | * Simple text driven tournament bracketing tool 8 | * 9 | * Copyright (C) 2015 Adam Potolsky 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with this program; if not, write to the Free Software Foundation, Inc., 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | * 25 | * Filename: match.h 26 | * Description: match.h contains the definitions for match.cpp 27 | * Notations: 28 | * 29 | * Author: Adam Potolsky 30 | * 31 | * Revision History: Under Revision Control 32 | * 33 | * Public Routines: 34 | * 35 | * Private routines: 36 | * 37 | *******************************************************************************/ 38 | 39 | #include 40 | #include 41 | #include 42 | #include "team.h" 43 | #include "roster.h" 44 | 45 | /******************************************************************************* 46 | * * 47 | * Class Match * 48 | * * 49 | * Description: Class that defines a match and it's components * 50 | * * 51 | * Requirements: Uses: Class team * 52 | * * 53 | *******************************************************************************/ 54 | 55 | class Match 56 | { 57 | public: 58 | Match(Match * m1, Match * m2); 59 | Match(team t1, team t2); 60 | Match(team t1); 61 | Match(); 62 | 63 | ttb_error_t play_match(); 64 | ttb_error_t play_match_by_seed(); 65 | ttb_error_t match_one(Match * m) { match_1=m; return ttb_OK; } 66 | ttb_error_t match_two(Match * m) { match_2=m; return ttb_OK; } 67 | ttb_error_t add_team(team); 68 | Match match_one() { return *match_1; } 69 | Match match_two() { return *match_2; } 70 | bool match_one_defined(); 71 | bool match_two_defined(); 72 | team team_one() { return team_1; } 73 | team team_two() { return team_2; } 74 | team get_winner() { return winner; } 75 | team get_loser() { return loser; } 76 | bool defined(); 77 | 78 | 79 | private: 80 | // TODO: Should a match really understand the structure of the bracket other than 2 teams? 81 | std::bitset<2> left_or_right; 82 | bool go_left(); 83 | team winner; 84 | team loser; 85 | team team_1; 86 | team team_2; 87 | Match * match_1; 88 | Match * match_2; 89 | }; 90 | -------------------------------------------------------------------------------- /source/main/team.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /******************************************************************************* 4 | * 5 | * text-tourney-brackets 6 | * 7 | * Simple text driven tournament bracketing tool 8 | * 9 | * Copyright (C) 2015 Adam Potolsky 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with this program; if not, write to the Free Software Foundation, Inc., 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | * 25 | * Filename: team.h 26 | * Description: team.h contains the definitions for team.cpp 27 | * Notations: 28 | * 29 | * Author: Adam Potolsky 30 | * 31 | * Revision History: Under Revision Control 32 | * 33 | * Public Routines: 34 | * int load_teams(std::string filename); 35 | * 36 | * Private routines: 37 | * 38 | *******************************************************************************/ 39 | #include 40 | #include 41 | #include 42 | #include "error.h" 43 | 44 | /******************************************************************************* 45 | * * 46 | * Class team * 47 | * * 48 | * Description: Class that defines a team and it's components * 49 | * * 50 | * Requirements: none * 51 | * * 52 | *******************************************************************************/ 53 | class team 54 | { 55 | public: 56 | team(std::string, std::string, std::string, std::string, int); 57 | team(const char *, const char *, const char *, const char *, int); 58 | team(); 59 | 60 | const std::string id() const { return _id; } 61 | const std::string last() const { return _last; } 62 | const std::string first() const { return _first; } 63 | const std::string residence() const { return _nationality; } 64 | const int seed() const { return _seed; } 65 | 66 | ttb_error_t id(std::string str) { _id = str; return ttb_OK; } 67 | ttb_error_t last(std::string str) { _last = str; return ttb_OK; } 68 | ttb_error_t first(std::string str) { _first = str; return ttb_OK; } 69 | ttb_error_t nation(std::string str) { _nationality = str; return ttb_OK; } 70 | ttb_error_t seed(int i) { _seed = i; return ttb_OK;} 71 | 72 | const std::string to_str() const; 73 | 74 | bool operator==(const team& A); 75 | 76 | bool defined() { if(_id == "!NDEF") return false; return true; } 77 | 78 | bool a_bye() { if(_id == "!BYE") return true; return false; } 79 | 80 | private: 81 | std::string _id; 82 | std::string _last; 83 | std::string _first; 84 | std::string _nationality; 85 | int _seed; 86 | }; 87 | -------------------------------------------------------------------------------- /source/main/brackets.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /******************************************************************************* 4 | * 5 | * text-tourney-brackets 6 | * 7 | * Simple text driven tournament bracketing tool 8 | * 9 | * Copyright (C) 2015 Adam Potolsky 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License along 22 | * with this program; if not, write to the Free Software Foundation, Inc., 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 24 | * 25 | * Filename: brackets.h 26 | * Description: brackets.h contains the definitions for brackets.cpp 27 | * Notations: 28 | * 29 | * Author: Adam Potolsky 30 | * 31 | * Revision History: Under Revision Control 32 | * 33 | * Public Routines: 34 | * 35 | * Private routines: 36 | * 37 | *******************************************************************************/ 38 | 39 | #include 40 | #include 41 | #include "team.h" 42 | #include "roster.h" 43 | #include "match.h" 44 | 45 | /******************************************************************************* 46 | * * 47 | * Class Brackets : public Roster * 48 | * * 49 | * Description: master class of a whole bracket. * 50 | * * 51 | * Requirements: Roster * 52 | * * 53 | * NOTE: team_list contains the real teams in the bracket. It must not include * 54 | * bye-teams. The bye-teams are added when the brackets are built. * 55 | * * 56 | *******************************************************************************/ 57 | class Brackets : public Roster 58 | { 59 | public: 60 | Brackets(std::string); 61 | 62 | ttb_error_t setup_brackets(); // Builds empty bracket tree 63 | 64 | ttb_error_t show_bracket(); // displays "pretty" match tree 65 | ttb_error_t display_heats(); // dumps the matches 66 | 67 | // TODO: define resolve routine 68 | ttb_error_t resolve(); // starts playing matches 69 | ttb_error_t resolve_by_seed(); // plays matches using seed to pick winner 70 | 71 | 72 | int get_depth(); // returns the # of bracket levels 73 | 74 | // number of matches in complete tree 75 | int size() { return pow(2,depth); } 76 | 77 | // returns the number of real teams in the bracket (no byes) 78 | int team_count() { return team_list.size(); } 79 | 80 | 81 | 82 | 83 | private: 84 | int depth; // The number of levels of the bracket 85 | Match finals; // Head of the tree 86 | 87 | team the_bye(); // returns true is this is a bye 88 | team team_not_defined(); // returns frue if the team isn't defined 89 | 90 | // See function Header 91 | int calc_left_match_start(int , int ); 92 | 93 | // workhorse routine to display the matches in the tree 94 | ttb_error_t _display_heat( Match , int, int, int); 95 | 96 | // workhorse routine to disply the bracket in a pretty way 97 | ttb_error_t _show_bracket(Match,int); 98 | 99 | // Routine that kicks off the building of the bracket tree 100 | ttb_error_t start_bracket_tree(); 101 | 102 | // workhorse routine to build the bracket tree 103 | Match * build_bracket_node(int cur_depth); 104 | 105 | }; 106 | 107 | 108 | -------------------------------------------------------------------------------- /source/main/team.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * text-tourney-brackets 4 | * 5 | * Simple text driven tournament bracketing tool 6 | * 7 | * Copyright (C) 2015 Adam Potolsky 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with this program; if not, write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | * 23 | * Filename: team.cpp 24 | * Description: team.cpp contains the execuation entry routine 25 | * Notations: 26 | * 27 | * Author: Adam Potolsky 28 | * 29 | * Revision History: Under Revision Control 30 | * 31 | * Public Routines: 32 | * int load_teams(std::string filename); 33 | * 34 | * Private routines: 35 | * 36 | *******************************************************************************/ 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "team.h" 43 | 44 | bool team::operator==(const team& A) 45 | { 46 | if( id() == A.id() ) return true; 47 | 48 | return false; 49 | } 50 | /******************************************************************************* 51 | * * 52 | * Constructor team::team( std::string id * 53 | * std::string last, * 54 | * std::string first, * 55 | * std::string res, * 56 | * int seed) * 57 | * * 58 | * Description: constructs a team with the given data * 59 | * * 60 | * Inputs: string id The ID to use for this team * 61 | * string last Last name of team * 62 | * string first First name of team * 63 | * string res Country of residency * 64 | * int seed the seed or ranking of this team * 65 | * * 66 | * Requirements: Inputs must be valid * 67 | * * 68 | * Outputs: New instance of a team is allocated * 69 | * * 70 | * Effects: Constructor... * 71 | * * 72 | *******************************************************************************/ 73 | team::team(std::string id, std::string last, std::string first, std::string res, int seed) 74 | { 75 | _id = id; 76 | _last = last; 77 | _first = first; 78 | _nationality = res; 79 | _seed = seed; 80 | } 81 | 82 | /******************************************************************************* 83 | * * 84 | * Constructor team::team( char * id * 85 | * char * last, * 86 | * char * first, * 87 | * char * res, * 88 | * int seed) * 89 | * * 90 | * Description: constructs a team with the given data * 91 | * * 92 | * Inputs: char * id The ID to use for this team * 93 | * char * last Last name of team * 94 | * char * first First name of team * 95 | * char * res Country of residency * 96 | * int seed the seed or ranking of this team * 97 | * * 98 | * Requirements: Inputs must be valid * 99 | * * 100 | * Outputs: New instance of a team is allocated * 101 | * * 102 | * Effects: Constructor... * 103 | * * 104 | *******************************************************************************/ 105 | team::team(const char * id, const char * last, const char * first, const char * res, int seed) 106 | { 107 | _id = id; 108 | _last = last; 109 | _first = first; 110 | _nationality = res; 111 | _seed = seed; 112 | } 113 | 114 | /******************************************************************************* 115 | * * 116 | * Constructor team::team() * 117 | * * 118 | * Description: constructs a team that is "not defined" * 119 | * * 120 | * Inputs: none * 121 | * * 122 | * Requirements: none * 123 | * * 124 | * Outputs: New instance of a team is allocated * 125 | * * 126 | * Effects: Constructor... * 127 | * * 128 | *******************************************************************************/ 129 | team::team() 130 | { 131 | _id = "!NDEF"; 132 | _last = "!NDEF"; 133 | _first = "!NDEF"; 134 | _nationality = "!NDEF"; 135 | _seed = -2; 136 | } 137 | 138 | /******************************************************************************* 139 | * * 140 | * const std::string team::to_str() const * 141 | * * 142 | * Description: builds a string to represent the team data * 143 | * * 144 | * Inputs: none * 145 | * * 146 | * Requirements: none * 147 | * * 148 | * Outputs: string const * 149 | * * 150 | * Effects: none * 151 | * * 152 | *******************************************************************************/ 153 | const std::string team::to_str() const 154 | { 155 | std::string str("ID:"); 156 | str.append(id()); 157 | str.append(" Last:"); 158 | str.append(last()); 159 | str.append(" First:"); 160 | str.append(first()); 161 | str.append(" Res:"); 162 | str.append(residence()); 163 | 164 | std::ostringstream tmp; 165 | tmp << seed(); 166 | std::string seed_str(tmp.str()); 167 | 168 | str.append(" Seed:"); 169 | str.append(seed_str); 170 | 171 | return str; 172 | } 173 | -------------------------------------------------------------------------------- /source/main/roster.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * text-tourney-brackets 4 | * 5 | * Simple text driven tournament bracketing tool 6 | * 7 | * Copyright (C) 2015 Adam Potolsky 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with this program; if not, write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | * 23 | * Filename: roster.cpp 24 | * Description: roster.cpp contains the execuation entry routine 25 | * Notations: 26 | * 27 | * Author: Adam Potolsky 28 | * 29 | * Revision History: Under Revision Control 30 | * 31 | * Public Routines: 32 | * int load_teams(std::string filename); 33 | * 34 | * Private routines: 35 | * 36 | *******************************************************************************/ 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "roster.h" 43 | #include "team.h" 44 | 45 | /******************************************************************************* 46 | * * 47 | * Constructor Roster::Roster(std::string filename) * 48 | * * 49 | * Description: constructs a roster using "filename" as the team data * 50 | * * 51 | * Inputs: filename Name of the file from which the teams are read * 52 | * * 53 | * Requirements: filename is valid * 54 | * * 55 | * Outputs: A Roster * 56 | * * 57 | * Effects: Constructor... * 58 | * * 59 | *******************************************************************************/ 60 | Roster::Roster(std::string filename) 61 | { 62 | load_roster(filename); 63 | } 64 | /******************************************************************************* 65 | * * 66 | * team Roster::make_a_bye() * 67 | * * 68 | * Description: constructs a bye team * 69 | * * 70 | * Inputs: none * 71 | * * 72 | * Requirements: none * 73 | * * 74 | * Outputs: A bye team * 75 | * * 76 | * Effects: a bye team is created * 77 | * * 78 | *******************************************************************************/ 79 | team Roster::make_a_bye() 80 | { 81 | return team("!BYE","!BYE","!BYE","!BYE",-1); 82 | } 83 | 84 | /******************************************************************************* 85 | * * 86 | * ttb_error_t Roster::read_next_team() * 87 | * * 88 | * Description: Reads in the next line with valid data for the roster * 89 | * * 90 | * Inputs: none * 91 | * * 92 | * Requirements: file should already be created and ready for processing * 93 | * * 94 | * Outputs: ttb_EOF End of File has been reached * 95 | * ttb_OK Normal completion * 96 | * * 97 | * Effects: File pointer is altered * 98 | * * 99 | *******************************************************************************/ 100 | ttb_error_t Roster::read_next_team() 101 | { 102 | std::string sOneLine("#"); 103 | 104 | while ('#' == sOneLine[0] || 0 == sOneLine.size()) // Skip comments 105 | { 106 | // If it's the end of file, we;re done. 107 | if(file.eof()) return ttb_EOF; 108 | 109 | std::getline(file, sOneLine); 110 | } 111 | 112 | std::stringstream sstream(sOneLine); 113 | 114 | 115 | std::string seed_str = ""; 116 | 117 | std::string tmp_id = ""; 118 | std::string tmp_last = ""; 119 | std::string tmp_first = ""; 120 | std::string tmp_residence = ""; 121 | 122 | getline(sstream, tmp_id, ',' ); 123 | getline(sstream, tmp_last, ',' ); 124 | getline(sstream, tmp_first, ',' ); 125 | getline(sstream, tmp_residence, ',' ); 126 | 127 | getline(sstream, seed_str, ',' ); 128 | 129 | int tmp_seed = -1; 130 | 131 | if( "" == seed_str ) 132 | { 133 | tmp_seed = 0; 134 | } 135 | else 136 | { 137 | std::stringstream( seed_str ) >> tmp_seed; 138 | } 139 | 140 | team t(tmp_id, tmp_last, tmp_first,tmp_residence, tmp_seed); 141 | 142 | add_team(t); 143 | 144 | return ttb_OK; 145 | } 146 | 147 | /******************************************************************************* 148 | * * 149 | * ttb_error_t Roster::display_team_list() * 150 | * * 151 | * Description: Dumps the list of teams to standard out * 152 | * * 153 | * Inputs: none * 154 | * * 155 | * Requirements: none * 156 | * * 157 | * Outputs: ttb_OK Normal completion * 158 | * * 159 | * Effects: Standard Output generated * 160 | * * 161 | *******************************************************************************/ 162 | ttb_error_t Roster::display_team_list() 163 | { 164 | std::cout << "\n\t\tTeam List Dump:" << std::endl; 165 | 166 | std::vector::const_iterator i = team_list.begin(); 167 | 168 | for( ; i != team_list.end() ; i++) 169 | { 170 | std::cout << i->id() << ": "; 171 | std::cout << i->last() << ", "; 172 | std::cout << i->first() << ", From: "; 173 | std::cout << i->residence() << ", Seed:"; 174 | std::cout << i->seed() << std::endl; 175 | } 176 | 177 | std::cout << "\t\tEnd of List" << std::endl; 178 | 179 | return ttb_OK; 180 | } 181 | 182 | /******************************************************************************* 183 | * * 184 | * ttb_error_t Roster::add_team(team t) * 185 | * * 186 | * Description: Adds team 't' to the roster * 187 | * * 188 | * Inputs: t team to add to the roster * 189 | * * 190 | * Requirements: t shoudl be a valid team * 191 | * * 192 | * Outputs: ttb_OK Normal completion * 193 | * * 194 | * Effects: team list is modified * 195 | * * 196 | *******************************************************************************/ 197 | ttb_error_t Roster::add_team(team t) 198 | { 199 | // nothing for now 200 | team_list.push_back(t); 201 | return ttb_OK; 202 | } 203 | 204 | /******************************************************************************* 205 | * * 206 | * ttb_error_t Roster::load_roster(std::string filename) * 207 | * * 208 | * Description: Loads the roster of teams * 209 | * * 210 | * Inputs: filename Name of the file from which the teams are read * 211 | * * 212 | * Requirements: filename is valid * 213 | * * 214 | * Outputs: ttb_OK Normal completion * 215 | * * 216 | * Effects: team list is modified * 217 | * * 218 | *******************************************************************************/ 219 | ttb_error_t Roster::load_roster(std::string filename) 220 | { 221 | file.open(filename.c_str(),std::ios::in); 222 | 223 | if( ! file.is_open()) { 224 | std::cerr << "There was an error opening file:" << filename << std::endl; 225 | return ttb_unknown; 226 | } 227 | 228 | std::cout << "Filename:" << filename << std::endl; 229 | 230 | do{}while(ttb_OK == read_next_team()); 231 | 232 | display_team_list(); 233 | 234 | return ttb_OK; 235 | } 236 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | -------------------------------------------------------------------------------- /source/main/match.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * text-tourney-brackets 4 | * 5 | * Simple text driven tournament bracketing tool 6 | * 7 | * Copyright (C) 2015 Adam Potolsky 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with this program; if not, write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | * 23 | * Filename: match.cpp 24 | * Description: match.cpp contains the match source 25 | * Notations: 26 | * 27 | * Author: Adam Potolsky 28 | * 29 | * Revision History: Under Revision Control 30 | * 31 | * Public Routines: 32 | * 33 | * Private routines: 34 | * 35 | *******************************************************************************/ 36 | 37 | #include "brackets.h" 38 | #include "match.h" 39 | #include 40 | #include 41 | 42 | /******************************************************************************* 43 | * * 44 | * Match::Match(team t1, team t2) * 45 | * * 46 | * Description: Constructor that builds a Match given 2 teams * 47 | * * 48 | * Inputs: t1 "left" team of new match * 49 | * t2 "right" team of new match * 50 | * * 51 | * Requirements: N/A * 52 | * * 53 | * Outputs: a Match is created * 54 | * * 55 | * Effects: N/A * 56 | * * 57 | *******************************************************************************/ 58 | Match::Match(team t1, team t2) 59 | { 60 | winner = team(); 61 | loser = team(); 62 | left_or_right = 0; 63 | team_1 = t1; 64 | team_2 = t2; 65 | match_1 = NULL; 66 | match_2 = NULL; 67 | } 68 | 69 | /******************************************************************************* 70 | * * 71 | * Match::Match() * 72 | * * 73 | * Description: Constructor default * 74 | * * 75 | * Inputs: t1 "left" team of new match * 76 | * t2 "right" team of new match * 77 | * * 78 | * Requirements: N/A * 79 | * * 80 | * Outputs: a Match is created with not defined teams * 81 | * * 82 | * Effects: N/A * 83 | * * 84 | *******************************************************************************/ 85 | Match::Match() 86 | { 87 | winner = team(); 88 | loser = team(); 89 | left_or_right = 0; 90 | match_1 = NULL; 91 | match_2 = NULL; 92 | } 93 | 94 | /******************************************************************************* 95 | * * 96 | * Match::Match(Match * m1, Match * m2) * 97 | * * 98 | * Description: Constructor that builds a Match given 2 matches * 99 | * * 100 | * Inputs: m1 "left" match * 101 | * m2 "right" match * 102 | * * 103 | * Requirements: Matches must be valid or NULL * 104 | * * 105 | * Outputs: a Match is created * 106 | * * 107 | * Effects: N/A * 108 | * * 109 | *******************************************************************************/ 110 | Match::Match(Match * m1, Match * m2) 111 | { 112 | winner = team(); 113 | loser = team(); 114 | left_or_right = 0; 115 | match_1 = m1; 116 | match_2 = m2; 117 | } 118 | 119 | /******************************************************************************* 120 | * * 121 | * bool Match::go_left() * 122 | * * 123 | * Description: method that determines whether the next object should go * 124 | * down the left branch or right. The Pattern is LRRLLRRL * 125 | * * 126 | * Inputs: N/A * 127 | * * 128 | * Requirements: N/A * 129 | * * 130 | * Outputs: bool true on left * 131 | * * 132 | * Effects: N/A * 133 | * * 134 | *******************************************************************************/ 135 | bool Match::go_left() 136 | { 137 | if( left_or_right[0] == left_or_right[1] ) return true; 138 | return false; 139 | } 140 | 141 | /******************************************************************************* 142 | * * 143 | * ttb_error_t Match::add_team(team t) * 144 | * * 145 | * Description: method to add a team to this bracket reference. Recursion * 146 | * is used to climb down the branches as appropriate. If all sub-matches are * 147 | * full, then add the team to this match. * 148 | * * 149 | * Inputs: t team to add to this structure * 150 | * * 151 | * Requirements: t must be a valid team * 152 | * * 153 | * Outputs: ttb_OK normal completion * 154 | * ttb_match_full this and all bub-matches are full * 155 | * * 156 | * Effects: contents of the match tree is modified * 157 | * * 158 | * Notes: * 159 | * * 160 | * Bracket trees are complete. They always have a full set of matches even if * 161 | * every competitor has a bye except 2. For this reason, it is safe to assume * 162 | * If there is one match there are 2. * 163 | * If there are no matches, populate myself * 164 | * If there are subordinate matches, pass the team to the correct one of them. * 165 | * Once the subordinate matches are full, this one shoudl populate itself. * 166 | * When full, it should return ttb_match_full * 167 | * * 168 | *******************************************************************************/ 169 | ttb_error_t Match::add_team(team t) 170 | { 171 | // If both teams are defined, the match is full. 172 | if(team_1.defined() && team_2.defined()) return ttb_match_full; 173 | 174 | // No match means populate this match. 175 | if(NULL == match_1) 176 | { 177 | if( true == go_left()) 178 | { 179 | team_1 = t; 180 | } 181 | else 182 | { 183 | team_2 = t; 184 | } 185 | left_or_right = left_or_right.to_ulong() + 1; // TODO: This is a kludge 186 | 187 | return ttb_OK; 188 | } 189 | 190 | // Need to load the match beneath us 191 | 192 | if( true == go_left()) 193 | { 194 | match_1->add_team(t); 195 | } 196 | else 197 | { 198 | match_2->add_team(t); 199 | } 200 | left_or_right = left_or_right.to_ulong() + 1; 201 | 202 | return ttb_OK; 203 | 204 | } 205 | 206 | /******************************************************************************* 207 | * * 208 | * bool Match::defined() * 209 | * * 210 | * Description: method to play out the matches using the seed as the * 211 | * victory condition * 212 | * * 213 | * Inputs: N/A * 214 | * * 215 | * Requirements: Bracket Tree must be set up * 216 | * * 217 | * Outputs: ttb_OK normal completion * 218 | * ttb_match_full this and all bub-matches are full * 219 | * * 220 | * Effects: contents of the match tree is modified * 221 | * * 222 | * Notes: * 223 | * * 224 | * If a seed cannot resolve the match, the "right" team wins * 225 | * * 226 | *******************************************************************************/ 227 | ttb_error_t Match::play_match_by_seed() 228 | { 229 | if(false == team_1.defined()) 230 | { 231 | match_1->play_match_by_seed(); 232 | team_1 = match_1->winner; 233 | } 234 | 235 | if(false == team_2.defined()) 236 | { 237 | match_2->play_match_by_seed(); 238 | team_2 = match_2->winner; 239 | } 240 | 241 | if(team_2.a_bye() == true) // This is ok, bye always looses 242 | { 243 | winner = team_1; 244 | } 245 | else if(team_1.seed() <= team_2.seed()) //TODO: Some way to solve a match 246 | { 247 | winner = team_1; 248 | loser = team_2; 249 | } 250 | else 251 | { 252 | winner = team_2; 253 | loser = team_1; 254 | } 255 | 256 | return ttb_OK; 257 | } 258 | 259 | 260 | /******************************************************************************* 261 | * * 262 | * bool Match::defined() * 263 | * * 264 | * Description: method to determine if this match has been defined * 265 | * * 266 | * Inputs: t team to add to this structure * 267 | * * 268 | * Requirements: t must be a valid team * 269 | * * 270 | * Outputs: true team is defined * 271 | * false team is not defined * 272 | * * 273 | * Effects: contents of the match tree is modified * 274 | * * 275 | * Notes: * 276 | * * 277 | * if there is a team or match in _1_ and a team or match in _2_ than it's * 278 | * defined otherwise it's not defined or partially defined. This routine treats * 279 | * either as not defined * 280 | * * 281 | *******************************************************************************/ 282 | bool Match::defined() 283 | { 284 | // if there is a team or match in _1_ and a team or match in _2_ than it's defined otherwise it's not defined or partially defined. This routine treats either as not defined 285 | 286 | if( (team_1.defined() || (NULL != match_1) ) && (team_2.defined() || (NULL != match_2) ) ) 287 | { 288 | return true; 289 | } 290 | return false; 291 | } 292 | 293 | /******************************************************************************* 294 | * * 295 | * bool Match::match_one_defined() * 296 | * * 297 | * Description: Returns whether or not match_1 has been defined * 298 | * * 299 | * Inputs: N/A * 300 | * * 301 | * Requirements: N/A * 302 | * * 303 | * Outputs: true Match_1 is defined * 304 | * false Match_1 is not defined * 305 | * * 306 | * Effects: none * 307 | * * 308 | * Notes: * 309 | * * 310 | * Does not test validity of the match * 311 | * * 312 | *******************************************************************************/ 313 | bool Match::match_one_defined() 314 | { 315 | if(NULL == match_1) 316 | { 317 | return false; 318 | } 319 | return true; 320 | } 321 | 322 | /******************************************************************************* 323 | * * 324 | * bool Match::match_two_defined() * 325 | * * 326 | * Description: Returns whether or not match_2 has been defined * 327 | * * 328 | * Inputs: N/A * 329 | * * 330 | * Requirements: N/A * 331 | * * 332 | * Outputs: true Match_2 is defined * 333 | * false Match_2 is not defined * 334 | * * 335 | * Effects: none * 336 | * * 337 | * Notes: * 338 | * * 339 | * Does not test validity of the match * 340 | * * 341 | *******************************************************************************/ 342 | bool Match::match_two_defined() 343 | { 344 | if(NULL == match_2) 345 | { 346 | return false; 347 | } 348 | return true; 349 | } 350 | -------------------------------------------------------------------------------- /source/main/brackets.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * text-tourney-brackets 4 | * 5 | * Simple text driven tournament bracketing tool 6 | * 7 | * Copyright (C) 2015 Adam Potolsky 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License along 20 | * with this program; if not, write to the Free Software Foundation, Inc., 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 22 | * 23 | * Filename: brackets.cpp 24 | * Description: brackets.cpp contains the bracketing source 25 | * Notations: 26 | * 27 | * Author: Adam Potolsky 28 | * 29 | * Revision History: Under Revision Control 30 | * 31 | * Public Routines: 32 | * 33 | * Private routines: 34 | * 35 | *******************************************************************************/ 36 | 37 | #include "brackets.h" 38 | #include "match.h" 39 | #include 40 | #include 41 | #include 42 | 43 | /******************************************************************************* 44 | * * 45 | * Brackets::Brackets(std::string f ) : Roster(f) * 46 | * * 47 | * Description: Constructor for a Brackets * 48 | * * 49 | * Inputs: f filename given to Roster * 50 | * * 51 | * Requirements: f must be a valid filename * 52 | * * 53 | * Outputs: Constructor... * 54 | * * 55 | * Effects: Constructor... * 56 | * * 57 | * Notes: * 58 | * * 59 | ********************************************************************************/ 60 | Brackets::Brackets(std::string f ) : Roster(f) 61 | { 62 | depth = (int)std::ceil( log2(team_list.size())); 63 | 64 | start_bracket_tree(); 65 | } 66 | 67 | /******************************************************************************* 68 | * * 69 | * ttb_error_t Brackets::show_bracket() * 70 | * * 71 | * Description: initial routine to output the human readable bracket tree * 72 | * * 73 | * Inputs: none * 74 | * * 75 | * Requirements: none * 76 | * * 77 | * Outputs: none * 78 | * * 79 | * Effects: standard output is generated * 80 | * * 81 | * Notes: * 82 | * Each match will display: * 83 | * 1) It's left-subordinate match _XOR_ it's left-team if there are none * 84 | * 2) It's winner or --------- if it's not determined * 85 | * 3) It's right-subordinate match _XOR_ it's right-team if there are none * 86 | * * 87 | * The Any match with subordinate matches will have it's team displayed as the * 88 | * winner of that subordinate match. * 89 | * * 90 | ********************************************************************************/ 91 | ttb_error_t Brackets::show_bracket() 92 | { 93 | std::cout << std::endl; 94 | std::cout << "show_bracket" << std::endl; 95 | 96 | _show_bracket(finals,1); 97 | 98 | std::cout << std::endl; 99 | std::cout << std::endl; 100 | return ttb_OK; 101 | } 102 | 103 | /******************************************************************************* 104 | * * 105 | * void tab_out(int cnt) * 106 | * * 107 | * Description: prints to standard out 2 x cnt tabs * 108 | * * 109 | * Inputs: cnt count used to determine the bumber of two-tabs * 110 | * * 111 | * Requirements: none * 112 | * * 113 | * Outputs: none * 114 | * * 115 | * Effects: standard output is generated * 116 | * * 117 | * Notes: * 118 | * * 119 | ********************************************************************************/ 120 | void tab_out(int cnt) 121 | { 122 | for(int i = 0 ; i < cnt ; i++) std::cout << "\t\t"; 123 | } 124 | 125 | /******************************************************************************* 126 | * * 127 | * ttb_error_t Brackets::_show_bracket(Match m, int curr_depth) * 128 | * * 129 | * Description: Routine to recursively display matches. (See Notes.) * 130 | * * 131 | * Inputs: m Match from which display begins (recursive) * 132 | * curr_depth Current depth of this Match * 133 | * * 134 | * Requirements: The tree must be defined * 135 | * * 136 | * Outputs: ttb_OK normal completion * 137 | * * 138 | * Effects: standard output is generated * 139 | * * 140 | * Notes: * 141 | * This method displayed output in a human readable text format. It can be * 142 | * to generate a bracket with only the leaf nodes populated, or one with some * 143 | * or all matches complete. * 144 | * * 145 | *TODO: Explain this better..... * 146 | *TODO: Strings should be defined in an external system that allows for L10N & * 147 | * I18N as well as sports specific terms * 148 | ********************************************************************************/ 149 | ttb_error_t Brackets::_show_bracket(Match m, int curr_depth) 150 | { 151 | // Display all matches to the left, or else the team to the left. 152 | if(m.match_one_defined()) 153 | { 154 | _show_bracket(m.match_one(),curr_depth+1); 155 | } 156 | else 157 | { 158 | tab_out(depth-curr_depth); 159 | std::cout << m.team_one().last() << std::endl; 160 | } 161 | 162 | // Display the winner of the finals if there is one 163 | tab_out(depth-curr_depth+1); 164 | 165 | if(m.get_winner().defined()) 166 | { 167 | std::cout << m.get_winner().last() << std::endl; 168 | } 169 | else 170 | { 171 | std::cout << "--------" << std::endl; 172 | } 173 | 174 | // Display all matches to the right, or else the team to the right. 175 | if(m.match_two_defined()) 176 | { 177 | _show_bracket(m.match_two(),curr_depth+1); 178 | } 179 | else 180 | { 181 | tab_out(depth-curr_depth); 182 | std::cout << m.team_two().last() << std::endl; 183 | } 184 | 185 | return ttb_OK; 186 | 187 | } 188 | 189 | /******************************************************************************* 190 | * * 191 | * ttb_error_t Brackets::_display_heats() * 192 | * * 193 | * Description: Routine to recursively display matches. (See Notes.) * 194 | * * 195 | * Inputs: none * 196 | * * 197 | * Requirements: The tree must be defined * 198 | * * 199 | * Outputs: ttb_OK normal completion * 200 | * * 201 | * Effects: standard output is generated * 202 | * * 203 | * Notes: * 204 | * * 205 | *TODO: Explain this better..... * 206 | *TODO: Strings should be defined in an external system that allows for L10N & * 207 | * I18N as well as sports specific terms 208 | ********************************************************************************/ 209 | ttb_error_t Brackets::display_heats() 210 | { 211 | int curr_depth = 0; 212 | if(finals.get_winner().defined()) 213 | { 214 | std::cout << "1st: " << finals.get_winner().last() << ", " << finals.get_winner().first() << std::endl; 215 | std::cout << "2nd: " << finals.get_loser().last() << ", " << finals.get_loser().first() << std::endl; //TODO: handle bye 216 | 217 | if(finals.match_one_defined()) 218 | { 219 | std::cout << "3rd: " << finals.match_one().get_loser().last() << ", " << finals.match_one().get_loser().first() << std::endl; 220 | } 221 | if(finals.match_two_defined()) 222 | { 223 | std::cout << "3rd: " << finals.match_two().get_loser().last() << ", " << finals.match_two().get_loser().first() << std::endl; 224 | } 225 | std::cout << std::endl; 226 | std::cout << "Full Bracket results:" << std::endl; 227 | } 228 | 229 | // Note: The match numbers are easy for the finals. The rest of the matches, not so much 230 | 231 | std::cout << "Match " << ( size()-1 ) << ":"; 232 | 233 | if(finals.match_one().get_winner().defined()) 234 | { 235 | std::cout << finals.match_one().get_winner().last() << " vs. "; 236 | } 237 | else 238 | { 239 | std::cout << "Winner of match " << ( size()-3 ) <<" vs. "; 240 | } 241 | 242 | if(finals.match_two().get_winner().defined()) 243 | { 244 | std::cout << finals.match_two().get_winner().last() << " vs. "; 245 | } 246 | else 247 | { 248 | std::cout << "Winner of match " << ( size()-2 ) << std::endl; 249 | } 250 | 251 | // The 3rd argument to display heat is the depth of that match. This is needed so it can predict 252 | // the match numbers it will call. 253 | 254 | if(finals.match_one_defined()) _display_heat(finals.match_one(), size()-3 , 1, 0); 255 | 256 | if(finals.match_two_defined()) _display_heat(finals.match_two(), size()-2 , 1, 1); 257 | 258 | 259 | return ttb_OK; 260 | } 261 | 262 | /******************************************************************************* 263 | * * 264 | * int Brackets::calc_left_match_start(int depth_start_count, int curr_depth) * 265 | * * 266 | * Description: Calculates the value of the first match at this depth * 267 | * * 268 | * Inputs: depth_start_count *See Notes * 269 | * curr_depth depth in the tree of this match * 270 | * * 271 | * Requirements: none * 272 | * * 273 | * Outputs: int value of the first match at this depth * 274 | * * 275 | * Effects: none * 276 | * * 277 | * Notes: The caller is reporting the start point for it's depth. * 278 | * From this 2^(depth of caller-1) is subtracted. * 279 | * * 280 | ********************************************************************************/ 281 | int Brackets::calc_left_match_start(int depth_start_count, int curr_depth) 282 | { 283 | int num = depth_start_count-pow(2,curr_depth); 284 | 285 | return num; 286 | } 287 | 288 | /******************************************************************************* 289 | * * 290 | * ttb_error_t Brackets::_display_heat( Match m, * 291 | * int depth_start_count, * 292 | * int curr_depth, * 293 | * int bit_mask) * 294 | * * 295 | * Description: Routine to recursively display matches. (See Notes.) * 296 | * * 297 | * Inputs: m Match to display * 298 | * depth_start_count *See Notes * 299 | * curr_depth depth in the tree of this match * 300 | * bit_mask *See notes * 301 | * * 302 | * Requirements: m must be a valid match * 303 | * depth_start_count range 1-depth * 304 | * curr_depth range 1-depth * 305 | * bit_mask *See notes * 306 | * * 307 | * Outputs: ttb_OK normal completion * 308 | * * 309 | * Effects: standard output is generated * 310 | * * 311 | * Notes: * 312 | * The output of this routine is one match per line. Each depth level of the * 313 | * tree can be represented by an equal number of bits. Finals needs 0 bits, * 314 | * semi-finals needs 1 bit (2 Matches), quarter finals needs 2 bits (4 teams), * 315 | * and so forth. The position of that match in a tier is the sum of the first * 316 | * match in the tier and the bit value represented by it's position. (bit_mask) * 317 | * When a subordinate Match is being calculated, the bit_mask is left shifted * 318 | * with either a 0 (left) or a 1 (right) pushed in. The depth_start_count is * 319 | * constant for a given tier, so when added to the bit_mask that specific match * 320 | * number is calculated. * 321 | * * 322 | *TODO: Explain this better..... * 323 | *TODO: bit_mask is not a very good name * 324 | ********************************************************************************/ 325 | ttb_error_t Brackets::_display_heat(Match m, int depth_start_count, int curr_depth, int bit_mask) 326 | { 327 | int match_number = depth_start_count + bit_mask; 328 | 329 | int left_sub_match_number = calc_left_match_start(depth_start_count,curr_depth+1); 330 | 331 | std::cout << "Match " << match_number << "("<< bit_mask <<"):"; 332 | 333 | if(m.team_one().defined()) 334 | { 335 | std::cout << m.team_one().last() << " vs. "; 336 | } 337 | else 338 | { 339 | std::cout << "Winner of match " << left_sub_match_number <<" vs. "; 340 | } 341 | 342 | if(m.team_two().defined()) 343 | { 344 | std::cout << m.team_two().last() << std::endl; 345 | } 346 | else 347 | { 348 | std::cout << "Winner of match " << left_sub_match_number+1 << std::endl; 349 | } 350 | 351 | if(m.match_one_defined()) _display_heat(m.match_one(),left_sub_match_number,curr_depth+1, (0 + (bit_mask <<= 1)) ); 352 | 353 | if(m.match_two_defined()) _display_heat(m.match_two(),left_sub_match_number,curr_depth+1, (1 + (bit_mask <<= 1)) ); 354 | 355 | return ttb_OK; 356 | } 357 | 358 | int Brackets::get_depth() 359 | { 360 | return depth; 361 | } 362 | 363 | /******************************************************************************* 364 | * * 365 | * ttb_error_t Brackets::setup_brackets() * 366 | * * 367 | * Description: populates the bracket tree with matches. * 368 | * * 369 | * Inputs: none * 370 | * * 371 | * Requirements: cur_depth must be a valid depth of this bracket tree * 372 | * * 373 | * Outputs: ttb_OK normal completion * 374 | * * 375 | * Effects: tree structure is allocated * 376 | * * 377 | * Note: This routines expects the team list is in seed order. * 378 | * Bye teams are expected to be lowest seed and thus placed * 379 | * at the end of the list. The algorithm that populates the * 380 | * tree uses seed order placement, so if there needs to be * 381 | * randomness in the list, it had to be done prior. * 382 | * * 383 | *******************************************************************************/ 384 | ttb_error_t Brackets::setup_brackets() 385 | { 386 | 387 | // This is a temp list to hold the teams and the byes used to fill the 1st round 388 | std::vector bracket_list; // this is a copy of the team_list with byes added 389 | 390 | bracket_list = team_list; 391 | 392 | // Add a number of byes to fill the list 393 | int add_byes = size() - bracket_list.size(); 394 | 395 | for( ; 0 < add_byes ; add_byes-- ) 396 | { 397 | bracket_list.push_back(make_a_bye()); 398 | } 399 | 400 | std::vector::const_iterator i = bracket_list.begin(); 401 | 402 | for( ; i != bracket_list.end() ; i++) 403 | { 404 | std::cout << "DEBUG ADDING: " << i->to_str() << std::endl; 405 | 406 | finals.add_team(*i); 407 | } 408 | 409 | // TODO: nothing yet 410 | return ttb_OK; 411 | 412 | } 413 | 414 | /******************************************************************************* 415 | * * 416 | * ttb_error_t Brackets::start_bracket_tree() * 417 | * * 418 | * Description: Creates an empty tree structure. * 419 | * * 420 | * Inputs: none * 421 | * * 422 | * Requirements: cur_depth must be a valid depth of this bracket tree * 423 | * * 424 | * Outputs: ttb_no_roster No roster exists * 425 | * ttb_OK normal completion * 426 | * * 427 | * Effects: tree structure is allocated * 428 | * * 429 | *******************************************************************************/ 430 | ttb_error_t Brackets::start_bracket_tree() 431 | { 432 | 433 | // There must be a competitor 434 | if(team_list.size() == 0) 435 | { 436 | return ttb_no_roster; 437 | } 438 | 439 | // The winner is the only team in the bracket 440 | if(team_list.size() == 1) 441 | { 442 | return ttb_OK; 443 | } 444 | 445 | finals.match_one( build_bracket_node(1) ); 446 | 447 | finals.match_two( build_bracket_node(1) ); 448 | 449 | return ttb_OK; 450 | } 451 | 452 | /******************************************************************************* 453 | * * 454 | * Match * Brackets::build_bracket_node(int cur_depth) * 455 | * * 456 | * Description: Creates a new instance of a match. When a match is created * 457 | * It is created with the subordinate matches attached. When * 458 | * a leaf match would be created, the teams of the requesting * 459 | * match are already that match, so none is actually built. * 460 | * * 461 | * Inputs: cur_depth the depth the match is being created at * 462 | * * 463 | * Requirements: cur_depth must be a valid depth of this bracket tree * 464 | * * 465 | * Outputs: Match * new created instance of a Match * 466 | * * 467 | * Effects: new instance... * 468 | * * 469 | *******************************************************************************/ 470 | Match * Brackets::build_bracket_node(int cur_depth) 471 | { 472 | if(cur_depth == depth) return NULL; 473 | 474 | Match * m1 = build_bracket_node(cur_depth+1); 475 | Match * m2 = build_bracket_node(cur_depth+1); 476 | 477 | return (new Match(m1,m2)); 478 | } 479 | 480 | // TODO: Need to make this really work 481 | /******************************************************************************* 482 | * * 483 | * ttb_error_t Brackets::resolve_by_seed() * 484 | * * 485 | * Description: Plays out the matches * 486 | * * 487 | * Inputs: none * 488 | * * 489 | * Requirements: Roster should be complete * 490 | * * 491 | * Outputs: ttb_OK Normal completion * 492 | * * 493 | * Effects: bracket tree is modified * 494 | * * 495 | *******************************************************************************/ 496 | 497 | ttb_error_t Brackets::resolve() 498 | { 499 | return finals.play_match_by_seed(); 500 | } 501 | 502 | /******************************************************************************* 503 | * * 504 | * ttb_error_t Brackets::resolve_by_seed() * 505 | * * 506 | * Description: Plays out the matches using the seed as the 1st victory * 507 | * condition. "Right wins" if seed doesn't decide. * 508 | * * 509 | * Inputs: none * 510 | * * 511 | * Requirements: Roster should be complete * 512 | * * 513 | * Outputs: ttb_OK Normal completion * 514 | * * 515 | * Effects: bracket tree is modified * 516 | * * 517 | *******************************************************************************/ 518 | ttb_error_t Brackets::resolve_by_seed() 519 | { 520 | return finals.play_match_by_seed(); 521 | } 522 | 523 | 524 | -------------------------------------------------------------------------------- /documentation/project_standards.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Open Source Development Standards 7 | 8 | 10 | 11 | 12 |
13 |
14 |

15 | Open Software 16 | Development Standards

17 | 18 |

Open Source Version

19 | 20 |

Version 0.8.1

21 | 22 |

Latest Revision: Sept 9, 2008

23 | 24 |

Revision History at end of document

25 | 26 |
    27 |
  1. Forward 28 |
      29 |
    1. These standards are being written without a specific project in mind. 30 | Because of this, they will likely need some latitude to fit properly 31 | into any development environment.
    2. 32 |
    3. I am releasing the Open Source Coding Standards under the Gnu Free 33 | Documentation License (GFDL): http://www.gnu.org/copyleft/fdl.html for release of 34 | these standards.
    4. 35 |
    5. The current process of revision for this document will be through 36 | Adam Potolsky (adam.potolsky_at_gmail_dot_com).
    6. 37 |
    7. Outstanding Issues -- Specific request for comments 38 |
        39 |
      1. <This space intentionally left blank>
      2. 40 |
      41 |
    8. 42 |
    9. Pending 43 |
        44 |
      1. <This space intentionally left blank>
      2. 45 |
      46 |
    10. 47 |
    11. Closed 48 |
        49 |
      1. none
      2. 50 |
      51 |
    12. 52 |
    53 |
  2. 54 |
  3. Introduction 55 |
      56 |
    1. This document describes conventions that can be adopted by any 57 | Software Engineering project. These conventions provide standards for 58 | arranging directories, storing software under version control, and 59 | writing source code. The purpose of these conventions is to make 60 | software easier to understand and maintain. It is important to use 61 | these standards throughout the lifetime of a project, from the first 62 | requirements through the maintenance cycle. It is always easier to 63 | conform to a common style from the outset than it is to apply the style 64 | later on. In particular, tasks such as writing comments, handling 65 | exceptions, and internationalization take longer if done after the rest 66 | of the source code is written and tested.
    2. 67 |
    3. These are not optional! 68 |
        69 |
      1. These coding standards shall be treated as requirements, or they 70 | will not provide any real benefit. There is no getting around this. 71 | It is better to change the standards internally and use 100% of 72 | them then to pick and choose which section to use. This sets a bad 73 | precedent, and goes against good process.
      2. 74 |
      75 |
    4. 76 |
    5. One should break the convention only if there is a compelling reason 77 | to do so, and even then after extensive review. 78 |
        79 |
      1. A violation of any of these coding standards should be discussed 80 | with at least one other member of the programming team to determine 81 | if the violation is sensible, and to determine if these coding 82 | standards should be altered to include the exception as a general 83 | case.
      2. 84 |
      85 |
    6. 86 |
    7. The use and presentation style of any construct not specifically 87 | mentioned in this standard shall be implemented as desired by the 88 | programmer, but still adhering to the intent of the document. 89 |
        90 |
      1. For example, the programmer may insert extra spaces and extra 91 | blank lines beyond those given in this standard to promote 92 | readability. (See 2.3)
      2. 93 |
      94 |
    8. 95 |
    9. For continuing development purposes, this standard should be applied 96 | as strictly as possible to any future languages and systems possible. 97 |
        98 |
      1. The document is designed with ‘C’ programming as its 99 | core; however, it is not intended to be limited to ‘C’ 100 | as a language. In some cases languages may not have the concept of 101 | header files, for example, and thus the header notations may be 102 | ignored. This does not exempt those systems from following a sane 103 | and strict standard. This document should be amended through time 104 | to add concepts. Amendments to the official documentation can be 105 | made through Adam Potolsky (mailto:adam.potolsky_at_gmail_dot_com). 106 |
      2. 107 |
      108 |
    10. 109 |
    11. The standards apply at all times, with limited coverage on other 110 | projects. 111 |
        112 |
      1. The introduction of open source has changed the landscape a bit 113 | with regard to development standards. This means that source from 114 | developers not part of a project are not expected to follow this 115 | standard unless the source is primarily owned and originated using 116 | these standards. For example, changes to Samba could be made 117 | without following the standards. There is an expectation of 118 | quality, however, and any code written for Open Source projects 119 | should still follow a high standard. Just because the code being 120 | modified or added to is bad does not give license to write bad 121 | code.
      2. 122 |
      123 |
    12. 124 |
    125 |
  4. 126 |
  5. Project and Architectural Guidelines 127 |
      128 |
    1. Design 129 |
        130 |
      1. 131 | In general, Object Oriented Design (OOD) should be used 132 | during the architectural phases of the project. 133 |
          134 |
        1. The concept of OOD is a good one. It provides an overall 135 | understandable structure for source code. In a greater sense, 136 | it provides a basis for seeing the big picture easily as well 137 | as making the process of digging down into the details less 138 | painful.
        2. 139 |
        140 |
      2. 141 |
      142 |
    2. 143 |
    3. File Editing 144 |
        145 |
      1. A width of 80 characters is not an option ­ it’s the 146 | rule. 147 |
          148 |
        1. Much of this project is done using textual interfaces such as 149 | vim or emacs. Although most systems allow for windows to be of 150 | varying sizes, the ideal size is either 80x24 or 80x40. Assume 151 | for the purposes of this documentation, the window size is 152 | 80x40. Ultimately, someone is going to be sitting at an vt100 153 | terminal which cannot display a width wider then 80, and if the 154 | code is already formatted for 80, then there will not be the 155 | pain of poorly word-wrapped code
        2. 156 |
        157 |
      2. 158 |
      3. Use a mono-spaced font for all source code. 159 |
          160 |
        1. Courier is a good choice. It helps to keep indenting as you 161 | expect. This will make sure that when code is printed it will 162 | look as good on paper as on the screen.
        2. 163 |
        164 |
      4. 165 |
      166 |
    4. 167 |
    5. File Names 168 |
        169 |
      1. File names should be descriptive, and the names must be unique in 170 | the first 20 characters except in the case where an 8.3 rule must 171 | be adhered to. This applies to all files within a single scope -- 172 | usually a directory.
      2. 173 |
      3. Filenames should not contain abbreviations except for the most 174 | obvious ones. I.e. TCPDump.c, HTMLParse.c, xml2text.c
      4. 175 |
      5. Use the upper/lower case naming scheme for filenames. As an 176 | example, doSomething.c is a proper name. 177 |
          178 |
        1. In the case that an acronym is used as the first part of the 179 | name, the acronym can be either upper or lower case. As an 180 | example, the routines for accessing the LED on the box are in a 181 | file called ‘ledAccess.c’, but could also be 182 | ‘LEDAccess.c’.
        2. 183 |
        184 |
      6. 185 |
      7. Each source file or logical set of source files should have its 186 | own public header file, which matches the name of the compiled 187 | object.
      8. 188 |
      9. In an effort to make the overall source code more object like, 189 | especially for non-object oriented languages such as 190 | ‘c’, headers files as well as source files should use a 191 | public and private naming convention. 192 |
          193 |
        1. If there are private routines in a source file or logical set 194 | of source’ files, a header ending in 195 | ‘_private.h’ should be used and reside with the 196 | source files.
        2. 197 |
        3. The ‘_public.h’ header is not necessary as it is 198 | implied by omission.
        4. 199 |
        5. If the overall grouping of files makes a single top-level 200 | package or object, there should be an overall header that is 201 | public to the world. The child headers of the files in this 202 | grouping are really private to the object but public within the 203 | object thus the _private header addition MAY be unnecessary. 204 |
        6. 205 |
        7. The following is an example.
        8. 206 |
        207 |
        208 |
        …/stack
         209 |    /stack.c
         210 |    /stack.h
         211 |    /StackArethmetic.h
         212 |    /linkedlist/
         213 |       /LinkedList_private.h
         214 |       /LinkedList.c
         215 |    /StackArithmetic/
         216 |       /StackArethmetic_private.h
         217 |       /StackArethmetic.c
         218 | 
        219 |
          220 |
        1. There is no stack_private.h because there is nothing 221 | private at this level.
        2. 222 |
        3. LinkedList_private.h, and StackArethmetic_private.h contain 223 | data and routines that ONLY their respective source files 224 | use. LinkedList.c cannot use StackArethmetic _private.h, 225 | however it can use StackArethmetic.h.
        4. 226 |
        5. stack.c uses StackArethmetic.h because the routines to 227 | perform push() and pop() action on the stack exist here, but 228 | it’s completely blind to the linked list routines.
        6. 229 |
        7. One interpretation would be that /LinkedList/ is only 230 | private methods and data, /StackArethmetic/ is both public 231 | and private methods and data, and /stack/ is only public 232 | methods and data.
        8. 233 |
        234 |
        235 |
      10. 236 |
      11. Any project wide ‘#define’s, types, etc… 237 | should be placed in a series of header files called: 238 |
          239 |
        1. For typedefs, enum types, etc… 240 |
            241 |
          1. ProjectNameTypes.h
          2. 242 |
          243 |
        2. 244 |
        3. For #defines 245 |
            246 |
          1. ProjectNameDefines.h
          2. 247 |
          248 |
        4. 249 |
        5. Used as a last resort to remove implicit declaration warning 250 | for those routines that have no prototype. 251 |
            252 |
          1. ProjectNameForwardDeclares.h
          2. 253 |
          3. It is important to note that NO source from any project 254 | written under these standards should have this problem. If 255 | it happens, it is very likely that the project has missed 256 | the standards, or more likely a privately defined routine 257 | is being called outside it's scope.
          4. 258 |
          259 |
        6. 260 |
        261 |
      12. 262 |
      263 |
    6. 264 |
    7. Directory Layout 265 |
        266 |
      1. The typical project should have a directory layout that follows 267 | the flow of the program. Subordinate directories should be used for 268 | subordinate functionality. Directory names should be descriptive, 269 | and the names must be unique in the first 20 characters. This 270 | applies to all directories within a single scope -- usually a 271 | parent directory. The directory hierarchies for a project should 272 | look like: 273 |
          274 |
        1. 275 |
           276 | …/ProjectName
           277 |    /build
           278 |    /tools
           279 |    /core
           280 |    /buzzword
           281 |    /otherBuzWord
           282 |    /include
           283 |    /web
           284 |       /cgi-bin
           285 |       /cgi-src
           286 |       /graphics
           287 |       /help
           288 |    /application
           289 |    /development
           290 |    /library
           291 | 
          292 |
        2. 293 |
        294 |
      2. 295 |
      296 |
    8. 297 |
    298 |
  6. 299 |
  7. Version Control 300 |
      301 |
    1. Source Control 302 |
        303 |
      1. For the time being, CVS is the source control of choice. It is, 304 | however, important to note that the decision to choose source 305 | control should not be taken lightly. Every project is different, 306 | and the wrong decision could cost time and money.
      2. 307 |
      3. Only check files out of CVS when they need to be modified.
      4. 308 |
      5. Delete all obsolete or duplicate source files from the CVS 309 | project before each release.
      6. 310 |
      7. Use a recursive directory diff to compare the local source 311 | directory hierarchy with the corresponding CVS directory hierarchy. 312 | This ensures that all new or modified files have been checked in. 313 |
      8. 314 |
      9. When checking in a file always write a comment describing the 315 | change. If the change fixes a bug, include the bug number in the 316 | comment. Prepend the # character to the bug number to facilitate 317 | easy searching for bug fixes. For example, the following comment 318 | describes the fix for bug 196 in doSomething.java. 319 |

        Bug 320 | #196. Clone the margin and text margin when installing the UI for 321 | the icon button so that changing the margin in the client will not 322 | modify the margin in the UI default hash table (which is shared by 323 | all icon buttons.)

        324 | 325 |
      10. 326 |
      327 |
    2. 328 |
    3. Release control 329 |
        330 |
      1. There should be 4 numeric fields in a software project. Version, 331 | Revision, Maintenance, Fix. Generally, the Version and revision are 332 | relevant except in cases where support for a product is necessary. 333 | In that case, the 3rd or 4th fields can be 334 | used for more accurate accounting. No version of the code should 335 | ever duplicate this numbering. Note that the version of Internet 336 | Explorer I’m using is 5.50.4134.0600. Most humans refer to it 337 | as IE 5.5. 338 |
          339 |
        1. The first number is the Version field, and refers to Major 340 | changes in functionality.
        2. 341 |
        3. The second number is the Revision digit, and refers to minor 342 | functionality additions, and major bug fixes, or major 343 | serviceability changes.
        4. 344 |
        5. The third number refers to maintenance and should only be 345 | used for minor bug fixes, and serviceability changes.
        6. 346 |
        7. The fourth number refers to ‘one customer’ fixes. 347 | That is a single customer has hit a bug and needs an immediate 348 | fix. Increment this number, build and ship it.
        8. 349 |
        350 |
      2. 351 |
      352 |
    4. 353 |
    5. Defect and Feature Tracking 354 |
        355 |
      1. TBA
      2. 356 |
      357 |
    6. 358 |
    359 |
  8. 360 |
  9. Source Code Standards 361 |
      362 |
    1. Purpose 363 |
        364 |
      1. Coding guidelines make the source code easier to read during code 365 | reviews and easier to modify by someone other than the original 366 | developer. If everyone adopts the same style, each reviewer can 367 | spend more time reviewing algorithms and program logic instead of 368 | interpreting an unfamiliar style. Likewise, if someone has to 369 | modify the source code, they can use the common coding conventions 370 | instead of adjusting their style to match what is already there. 371 |
      2. 372 |
      373 |
    2. 374 |
    3. Naming Conventions 375 |
        376 |
      1. Naming conventions are one of the most sticky of all subjects. 377 | Naming can make source code more readable and easier to maintain. 378 |
      2. 379 |
      3. Variable Names 380 |
          381 |
        1. All variable names should be descriptive. Abbreviations 382 | should be minimized. Acronyms used in external documentation 383 | are acceptable. Certain shorter names may be used as array 384 | indices or as local variables of minimal scope. Minimal scope 385 | generally refers to fitting within one window. These shorter 386 | names include the following: 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 |
          i, m, n, x, y, zArray indices
          string, str, sTemporary strings having no particular meaning
          next, prevNext and previous struct pointers.
          pointer, ptr, pTemporary pointers having no particular meaning
          errSimple error code
          411 |
        2. 412 |
        3. Variable names may be longer than 31 characters, but they 413 | should differ by the 31st character, since many flavors of UNIX 414 | only consider 31 characters significant. This applies to 415 | variables within the same scope.
        4. 416 |
        5. Names of private and protected static variables, functions, 417 | and methods should have a leading underscore. The remainder of 418 | the variable name should comply with other rules.
        6. 419 |
        7. Whenever Possible, private routines and variables are to be 420 | declared static and/or const to keep the scope to a minimum. 421 |
        8. 422 |
        9. The code should follow “Hungarian Notation.” The 423 | first character (prefix) of each variable name should indicate 424 | the type of the variable according to the following table. The 425 | pointer (p), unsigned (u), array (a), and void (v), can appear 426 | before another prefix. Otherwise, names should not contain more 427 | than one prefix. 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 |
          PrefixMeaning
          bboolean
          cchar
          iint
          llong
          ffloat
          ddouble
          scharacter string
          oC++ object, class, structure
          uunsigned
          ppointer (includes pointers to pointers)
          vvoid
          aArray
          globalGlobal variables*
          488 | * use the whole word global!
        10. 489 |
        11. Following the first character of the name (prefix), the first 490 | character of each word of a variable name should be 491 | capitalized. Acronyms should appear in upper case. For example: 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 |
          fDistance
          iNumberOfCoverages
          uiNumberOfCoverages
          sACT
          508 |
        12. 509 |
        13. A member function that logically doesn’t change the 510 | object through which it was called should be declared const. 511 |
        14. 512 |
        15. Arguments to a function that are passed by reference and 513 | aren't modified by the function should be declared const.
        16. 514 |
        515 |
      4. 516 |
      5. Type Names 517 |
          518 |
        1. For portability between operating systems, the following type 519 | definitions should be used: 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 |
          intintegers of various sizes
          longinteger number guaranteed to be at least 32bit
          float, doublefloats of various sizes
          boollogical, only 1 and 0 are considered
          540 |
        2. 541 |
        3. It is very likely that size specific types are needed 542 | throughout the source code. These types could include int64, 543 | char32, etc... They should be defined as appropriate in a 544 | single project header file. DoSomethingTypes.h is a good 545 | example of a name for a header file that contains project wide 546 | types.
        4. 547 |
        5. The names of abstract data types, structures, typedefs, and 548 | enumerated types should begin with an uppercase letter (with 549 | the exception of the basic types mentioned in V-b-3-a).
        6. 550 |
        7. Typedefs should always end in ‘_t’ for example: 551 |
            552 |
          1. 553 |
             554 | typedef struct FileListStrucure{
             555 |    char                          *sFileName;
             556 |    struct    FileListStructure   *next;
             557 |    struct    FileListStructure   *prev;
             558 | } FileList_t;
             559 | 
            560 |
          2. 561 |
          562 |
        8. 563 |
        564 |
      6. 565 |
      7. Function Names 566 |
          567 |
        1. Assessor functions which "get" a value should have the prefix 568 | "get" attached to the name. Functions which "set" a value 569 | should have the prefix "set" attached to the name. For 570 | example, getName() and setName().
        2. 571 |
        3. The following table contains examples that follow the 572 | previous naming rules: 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 |
          TypesPrivate variableScope variable
          variables_iVariableiVariable
          constants_CONSTA_CONST
          functions_functionaFunction
          objects_oStructureoAStructure
          typedefs_TypedefATypedef
          enumerated types_EnumAnEnum
          #define_LISTA_LIST
          enumerations_ENUMAN_ENUM
          Classes_oClassoClass
          Array_sNameArraysNameArray
          global_globaliValueiValue
          637 |
        4. 638 |
        639 |
      8. 640 |
      9. File Layout 641 |
          642 |
        1. The layout of any source code file should follow a clear and 643 | logical sequence. There are a number of fields which may not be 644 | used. Empty fields should be included in the headers for 645 | consistency purposes. 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 |

          Copyright

          Legal header

          Filename

          Name of file

          Description

          Detailed description of the file, including its purpose and use.

          Notations

          Additional information

          Author

          Who created the file

          Revision History

          This is not filled in by CVS

          Public Routines

          Routines allowed outside the scope of the file.

          Private routines

          Routines for internal use only

          698 |
        2. 699 |
        3. The following example summarizes the essential elements and 700 | the order in which they should appear. 701 |
            702 |
          1. 703 |
             704 | /*******************************************************************************
             705 | * Copyleft 2000, CodeHazard, Inc. No Rights Reserved.                          *
             706 | *                                                                              *
             707 | * Filename:      DoSomething.c                                                 *  
             708 | * Description:   DoSomething.c contains…                                       * 
             709 | * Notations:     The memset()'s used…                                          *
             710 | *                                                                              *    
             711 | * Author:        Mario Foonman                                                 *
             712 | *                                                                              *
             713 | * Revision History:                                                            *
             714 | *    10/01/99    Mario      Creation                                           *
             715 | *    10/20/99    Mario      Added…                                             *
             716 | *                                                                              *
             717 | * Public Routines:                                                             *
             718 | *  int  SetSomething( char  *sName );                                          *
             719 | *  int  GetSomething     ( char  *sName );                                     *
             720 | *                                                                              *
             721 | * Private routines:                                                            *
             722 | * void _ModifySomething ( char *sName );                                       *
             723 | *                                                                              *
             724 | *******************************************************************************/
             725 | #include <stdlib.h>
             726 | #include “DoSomething.h”
             727 | 
            728 |
          2. 729 |
          730 |
        4. 731 |
        732 |
      10. 733 |
      11. Routine Layout 734 |
          735 |
        1. Routines Should be concise without compromising readability. 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 |
          <Name>Name of procedure
          DescriptionDetailed description of the routine, including its purpose and use.
          InputsDescription of arguments.
          RequirementsAny requirements the arguments may have
          OutputsWhat is returned by the routine.
          EffectsThe effects of running the routine. Usually refers to the memory pointed to, but may be other effects.
          764 |
        2. 765 |
        3. The following example summarizes the essential elements and 766 | the order in which they should appear. Note on the following 767 | example, the routine’s main purpose is to retrieve the 768 | name, but that is NOT output. Output is the status of the 769 | routine, the Effect the routine has is to load the name of the 770 | thing into the memory pointed to by the passed in pointer 771 |
            772 |
          1. 773 |
             774 | /*******************************************************************************
             775 | *                                                                              *
             776 | * Status_t  GetSomething( char *sName );                                       *
             777 | *                                                                              *
             778 | * Description:      This routine populates the string sName with something.    *
             779 | *                                                                              *
             780 | * Inputs:           sName     sName points to allocated…                       *
             781 | *                                                                              *
             782 | * Requirements:     sName     The name of the thing must…                      *
             783 | *                                                                              *
             784 | * Outputs:          Status_t  returns PASS or FAIL                             *
             785 | *                                                                              *
             786 | * Effects:          sName     The value sName points to is changed.            *
             787 | *                                                                              *
             788 | *******************************************************************************/
             789 | Status_t SetSomething ( char *sName )
             790 | {
             791 |    Procedure body…
             792 | }
             793 | 
            794 |
          2. 795 |
          796 |
        4. 797 |
        798 |
      12. 799 |
      800 |
    4. 801 |
    5. Source Code Formatting 802 |
        803 |
      1. As a design goal, a function should not exceed one page of code 804 | nor should source code lines exceed 80 characters in length 805 | (including leading spaces). Any line that would be longer than the 806 | maximum should either continue on a subsequent line or be 807 | rewritten. Consider using a semicolon as a break first, then a 808 | comma. If one break is made, it is often preferable to break on 809 | each instance instead of just as necessary. For example: 810 |
          811 |
        1. 812 |
           813 | for( iCntr = 0 ;
           814 |    ( SrcAry[iCntr] != DestAry[iCntr] ) && iCntr < MAX);
           815 |      iCntr++ )
           816 | 
          817 |
        2. 818 |
        819 |
      2. 820 |
      3. Braces 821 |
          822 |
        1. Always use braces with control statements such as 823 | if-then-else statements, even if there is only one statement 824 | within the control statement. This prevents statements from 825 | being omitted from a control statement accidentally.
        2. 826 |
        3. Left braces ('{') should appear on a line containing no other 827 | code (with the exception of optional supporting comments) at 828 | the same indent level of the item preceding that brace. Right 829 | braces ('}') should appear on a line containing no other code 830 | (with the exception of optional supporting comments) at the 831 | same indent level of the matching left brace.
        4. 832 |
        5. Only one style should be used for if statements: 833 |
            834 |
          1. 835 |
             836 | /*The Allowed Style */
             837 | if( I == j )
             838 | {
             839 |    x = y;
             840 | }
             841 | /* The following styles violate this rule */
             842 | if( I == j )
             843 |    x = y;
             844 | 
             845 | if( I == j ) x = y;
             846 | 
            847 |
          2. 848 |
          849 |
        6. 850 |
        7. switct() statement special case: There is a case when a 851 | switch statement is performing a function which is 852 | substantially more readable if the overall format is compact. 853 | If the only action of the entire set of case statements are 854 | return commands, each case and return can be placed on one 855 | line. Similiar considerations are allowed for if-then blocks. 856 | For example: 857 |
            858 |
          1. 859 |
             860 | /* The Allowed Style */
             861 | switch( iWeek )
             862 | {
             863 |    case(1): return(“Sunday”);
             864 |    case(2): return(“Monday”);
             865 |    case(3): return(“Tuesday”);
             866 |    case(4): return(“Wednesday”);
             867 |    case(5): return(“Thursday”);
             868 |    case(6): return(“Friday”);
             869 |    case(7): return(“Saturday”);
             870 |    default: return(“Otherday”);
             871 | }
             872 | 
            873 |
          2. 874 |
          875 |
        8. 876 |
        877 |
      4. 878 |
      5. Spacing 879 |
          880 |
        1. Under most circumstances, put spaces between logical tokens. 881 |
            882 |
          1. For example: 883 |
            while( (iLatitude != iLongitude) && (iCntr < MAX_CNTR) )
             884 | {
             885 |   doSomething(iLatitude, iLongitude);
             886 | }
             887 | 
            888 |
          2. 889 |
          3. Notice there are not spaces preceeding the parands on the 890 | innermost conditionals, while there is a space on the 891 | outermost. This helps to show the logical blocks of the the 892 | greater while() statement.
          4. 893 |
          5. Further, the doSomething() call has an English style 894 | comma separated list without other spaces. This is very 895 | readable w/o spaces and thus is acceptable.
          6. 896 |
          7. The following is not acceptable: 897 |
            if((iLatitude==iLongitude)||(iCntr>=MAX_CNTR))
             898 | {
             899 |   doSomethingElse(iLatitude,iLongitude);
             900 | }
             901 | 
            902 |
          8. 903 |
          9. In this case, the lexical complexity in terms of readability is not as good.
          10. 904 |
          905 |
        2. 906 |
        907 |
      6. 908 |
      7. Indention 909 |
          910 |
        1. Tabs characters should be used in source code with a tab 911 | width of 3. 912 |
            913 |
          1. This can be set in CodeWarrior under: 914 | Edit->Preferences->[Editor->Font & 915 | Tabs]->(Tab Setting)
          2. 916 |
          3. This can be set in vi with: :set ts=3 set sw=3 or by 917 | adding the following statement to the profile.ksh 918 | file:export EXINIT="set Ts=3 SW=3 autoindent"
          4. 919 |
          5. This can be set in tornado 920 | under:tools->options->editor…->[Tab Stops] 921 |
          6. 922 |
          7. Here is one method of setting a code indent of 3 in 923 | emacs: 924 |
              925 |
            1. 926 |
               927 | include the following in the .emacs file:
               928 | ;; codehazard setup
               929 | (defun codehazard-c-mode () 
               930 |   "C mode with adjusted defaults for coding standards."
               931 |   (interactive)
               932 |   (c-mode)
               933 |   (c-set-style "K&R")
               934 |   (setq c-basic-offset 3))
               935 | 
              936 |
            2. 937 |
            3. Then somewhere in the first two lines of each .c or 938 | .h file I put: /* -*- codehazard-c -*- */ That causes 939 | emacs to automatically apply the c-mode.
            4. 940 |
            5. You can also do a command from the minibuffer to 941 | apply the mode, but I'd have to look that up. (I put 942 | the line at the beginning of the file so I don't _have_ 943 | to remember the command, or do it.)
            6. 944 |
            945 |
          8. 946 |
          947 |
        2. 948 |
        3. Code between braces should appear one indent level to the 949 | right of the corresponding braces: 950 |
            951 |
          1. 952 |
             953 | while(lFlag == TRUE)
             954 | {
             955 |    ++x;
             956 | }
             957 | 
            958 |
          2. 959 |
          3. The command indent can be used with the option -bli0 960 | (--brace-indent0) that is, the braces indenting is set to 961 | zero.
          4. 962 |
          963 |
        4. 964 |
        5. Statements that are part of a switch should appear two indent 965 | levels to the right of the corresponding braces, while case and 966 | default statements should appear one indent level to the right 967 | of the corresponding braces. 968 |
            969 |
          1. 970 |
             971 | switch ( x )
             972 | {
             973 |   case 1:            /* 1 level for case        */                    
             974 |     ++x;             /* 2 levels for statements */
             975 |     break;           /* 2 levels for statements */
             976 |   default:           /* 1 level for default     */
             977 |     x += y;          /* 2 levels for statements */
             978 | }
             979 | 
            980 |
          2. 981 |
          982 |
        6. 983 |
        7. Comments should be indented to match the relevant code. 984 | Function header comments should use slash-asterisk ("/*") and 985 | asterisk-slash ("*/") to begin and end comments. 986 |
            987 |
          1. 988 |
             989 | /* This comment describes the while if statement. */
             990 | if ( i == 0 )
             991 | {
             992 |    /* This comment describes the following block of statements */
             993 |    DoSomething();
             994 | }
             995 | 
            996 |
          2. 997 |
          998 |
        8. 999 |
        9. In_Line comments should be spaced away from the code they are 1000 | commenting. 1001 |
            1002 |
          1. ++x;/* comments are too close to actual code */
          2. 1003 |
          3. ++y; /* better indentation */
          4. 1004 |
          1005 |
        10. 1006 |
        11. As an exception to other style and indentation rules, short 1007 | inline functions and Macros may appear on a single line: 1008 |
            1009 |
          1. inline char *getString(void) { return "A String"; }
          2. 1010 |
          1011 |
        12. 1012 |
        1013 |
      8. 1014 |
      9. Comments 1015 |
          1016 |
        1. Comments are a critical part of source code. They help make 1017 | the code more readable, and identify to the code reviewer where 1018 | problems could exist.
        2. 1019 |
        3. Good comments not only describe what a section of code does, 1020 | but why the process was chosen if there are obvious choices. 1021 |
        4. 1022 |
        5. Comments should also include ‘gotchas’ and 1023 | pitfalls that were encountered during the writing or altering 1024 | of code
        6. 1025 |
        7. Comment types not part of a language specification should not 1026 | be used to comment a language. 1027 |
            1028 |
          1. For example, the ‘//’ comment type is ONLY 1029 | for ‘C++’ Although many ‘C’ 1030 | compilers will allow its use the ‘//’ 1031 | construct is NOT part of the ‘C’ 1032 | language.
          2. 1033 |
          1034 |
        8. 1035 |
        9. In some instances inline comments are better and others, 1036 | header comments are better. It is up to the programmer where 1037 | each should be used. V-C-4-d is an example of inline comments. 1038 |
        10. 1039 |
        1040 |
      10. 1041 |
      11. Style 1042 |
          1043 |
        1. Complexity should be reduced whenever possible. 1044 |
            1045 |
          1. Any compiler worth it's salt is going to optimize beyond 1046 | anything that the programmer can do on their own, and will 1047 | recognize where loops can be unfurled, registeres can be 1048 | shared, etc... In reality, most systems will compile 1049 | 6-a-ii-1 into 6-a-ii-2 as each assignment must be done 1050 | separately.
          2. 1051 |
          3. Break a large statement or expression into smaller pieces and then combine the pieces at the end. For Example: 1052 |
              1053 |
            1. 1054 |
              1055 | /* insert newblock between firstBlock and secondBlock */
              1056 | (newBlock->next = secondBlock)->prev = (newBlock->prev = firstBlock)->next = newBlock;
              1057 | 
              1058 |
            2. 1059 |
            3. 1060 |
              1061 | /* NewBlock->next = secondBlock;
              1062 | NewBlock->prev = firstBlock;
              1063 | SecondBlock->prev = newBlock;
              1064 | FirstBlock->next = newBlock;
              1065 | 
              1066 |
            4. 1067 |
            1068 |
          4. 1069 |
          5. Error checking should be used whenever possible. 1070 | V.C.6.a.iii.2 has an example.
          6. 1071 |
          7. No more than one function call should appear on a line.

            1072 | 1073 |
              1074 |
            1. /* This example has too many function calls on one line */

              1075 | 1076 |
              char *GetName( void ); /* Prototype for Document */
              1077 | 
              1078 | CodeTrace(NOTE,”%s(%d):Name:&percnt;s”,__FILE__,__LINE__,GetName());
              1079 | 
              1080 |
            2. 1081 |
            3. /* The following is better because it reduces the 1082 | number of calls on the CodeTrace() function call, and 1083 | makes sure that an ABEND does not happen due to a NULL 1084 | return value. */

              1085 | 1086 |
              char *GetName( void ); /* Prototype for Document */
              1087 | char *sName = NULL;
              1088 | sName = GetName();
              1089 | if(sName == NULL)
              1090 | {
              1091 |    CodeTrace(NOTE,”%s(%d):Returned NULL instead of a name”,__FILE__,__LINE__);
              1092 | }
              1093 | else
              1094 | {
              1095 |    CodeTrace(NOTE,”%s(%d):Name:%s”,__FILE__,__LINE__,sName);
              1096 | }
              1097 | 
              1098 |
            4. 1099 |
            1100 |
          8. 1101 |
          1102 |
        2. 1103 |
        1104 |
      12. 1105 |
      1106 |
    6. 1107 |
    1108 |
  10. 1109 |
  11. Serviceability, Sustaining, and Maintaining 1110 |
      1111 |
    1. The intent of this section is to address issues related to sustaining 1112 | engineering efforts, serviceability of the product, as well as 1113 | maintenance issues
    2. 1114 |
    3. Tracing and Debug statements 1115 |
        1116 |
      1. The intent of this section is to describe how tracing and 1117 | debugging statements will be laid out. It is first important to 1118 | recognize that any statements, which are added with the intent to 1119 | debug from a development standpoint, are also invaluable to service 1120 | and support for gathering data.
      2. 1121 |
      3. Trace methodology 1122 |
          1123 |
        1. There should be no #define statements which are used for 1124 | debugging in ‘checked-in’ code. 1125 |
            1126 |
          1. #define debugging statements require that a product needs 1127 | to be recompiled if it is to be debugged. This is VERY 1128 | undesirable from a support stance. When a problem occures 1129 | at a customer site, they should ne be required to 1130 | recompile, or install a new executable in order to gather 1131 | the necessary information. Tracing is a much better 1132 | solution.
          2. 1133 |
          3. #define statement durring development for "my machine" 1134 | purposes is fine, but production code should not contain 1135 | these statements.
          4. 1136 |
          1137 |
        2. 1138 |
        3. Tracing should be used liberally except where it would effect 1139 | performance.
        4. 1140 |
        5. Use the __FILE__ and __LINE__ Pre-Compiler constants to fill 1141 | in the filename and line number in any output statements.
        6. 1142 |
        1143 |
      4. 1144 |
      5. Trace output routines 1145 |
          1146 |
        1. Tracing is an important part of the continuing maintenance of 1147 | a product. It can also be an invaluable tool in the testing of 1148 | a product. Each project needs to have it’s own method of 1149 | tracing.
        2. 1150 |
        1151 |
      6. 1152 |
      1153 |
    4. 1154 |
    1155 |
  12. 1156 |
  13. Prior Outstanding Issues 1157 |
      1158 |
    1. Regarding VC3a: I disagree with the way you've written your spacing 1159 | requirements. I don't think it improves readability to have a space 1160 | after an opening parenthesis and before a closing one, and I think it 1161 | hinders readability to put spaces before commas and semicolons. If I 1162 | were designing the standard I'd probably require spaces around 1163 | operators, after commas and colons, and between adjacent parentheses, 1164 | e.g. '( (x + y) * (a - b) )' instead of '((x + y) * (a - b))'. 1165 |
        1166 |
      1. (Pending) Agree to change.
      2. 1167 |
      3. Reason: agreed with submitter. Change will be to add more 1168 | examples of good style.
      4. 1169 |
      1170 |
    2. 1171 |
    3. Proposal to change rule VC2a: The if statement 'if( I == j ) x = y;' 1172 | should be generally allowed. 1173 |
        1174 |
      1. (Pending) Decline to change.
      2. 1175 |
      3. Reason: The purpose of the standard is not just to normalize how 1176 | code looks for readability purposes but also to prevent problems 1177 | during the lifecycle of the product. It is certainly an accepted 1178 | practice to leave off the braces {} for single line blocks it leads 1179 | to a potential booby-trap in future revisions of the product. For 1180 | example, The statement: 1181 |
        if( I == j ) x = y;
        1182 | 
        1183 |

        has to be changed so one more thing happens then the following 1184 | error is too easy to make:

        1185 | 1186 |
        if( I == j ) x = y;
        1187 | fMessageOut(MYP_DEBUG,stderr,”I:%d y=%d\n”,I,y);
        1188 | 
        1189 |

        Perhaps an exception for if() return; or a string of single line ifs.

        1190 | 1191 |
      4. 1192 |
      1193 |
    4. 1194 |
    1195 |
  14. 1196 |
  15. Revision History
  16. 1197 |
1198 |
1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 |
VerDescriptionAuthorReviewerApprove
0.1Draft revisionAPotolskyN/AN/A
0.2Draft, Deviation from word format. Going to HTMLAPotolskyN/AN/A
0.3Removing over 3000 Word specific HTML items, combining 2 disjoint documents.APotolskyN/AN/A
0.4Added the indent command with option for altering braces indention. Minor versioning corrections.APotolskyN/AN/A
0.5Added emacs in VC4iv, changes in IIIC2, VB2D, VB2e, VB2f, VB3b, Vb3c, VB4b, VB5a, VC1, also fixed some spelling errorsAPotolskyDGordonAPotolsky
0.6Added Request for comment on style. Corrections in: IVB1, VB2e, VC4d, VC5d, VIBa, IIIC5dAPotolskyN/AN/A
0.7Response to VIBa: Declined Response to VC3a: AgreedBHoffmanAPotolskyAPotolsky
0.8Formatting Changes.APotolskyN/AN/A
0.8.1More Formatting changes; Addition of historicle appendix; beutification; changed html pre tags for beautification; APotolskyN/AN/A
1273 |
1274 | 1275 | 1276 | --------------------------------------------------------------------------------