Skip to content

Instantly share code, notes, and snippets.

View geektoni's full-sized avatar

Giovanni De Toni geektoni

View GitHub Profile

Shogun Style Guidelines

Shogun is a large project with many contributors and we have decided to define some general coding guidelines which form a "Shogun Standard" which should be followed when writing code for the toolbox. That was made to maintain a clean and polished code-base. Shogun use an automatic style checker (namely Clang Format) to verify if code follows Shogun's coding guidelines. Please make sure that your patches conform to these guidelines, otherwise our Continuous Integration tools will spot these errors and they will mark your pull requests as failed.

You can use our custom script, located in <your_shogun_source_dir>/scripts/check_format.sh to see if the code you have written follows our guidelines. The script will also give you instruction on how to fix style errors. Note that to use the script, clang-format-3.8 must be installed on your system.

Formatting Guidelines

Function Parameters

init_shogun(bool active=true) {
Some<CSignal> sg_signal = some<CSignal>(active);
std::signal(SIGINT, sg_signal.handler());
std::signal(SIGURG, sg_signal.handler());
}
CSignal {
Scanning dependencies of target libshogun
[ 5%] Building CXX object src/shogun/CMakeFiles/libshogun.dir/distance/Distance.cpp.o
/tmp/ccfEJFLM.s: Assembler messages:
/tmp/ccfEJFLM.s:200: Error: symbol `_ZNSt17_Function_handlerIFbvEN6shogunUlvE_EE9_M_invokeERKSt9_Any_data' is already defined
/tmp/ccfEJFLM.s:1023: Error: symbol `_ZNSt14_Function_base13_Base_managerIN6shogunUlvE_EE10_M_managerERSt9_Any_dataRKS4_St18_Manager_operation' is already defined
src/shogun/CMakeFiles/libshogun.dir/build.make:15718: recipe for target 'src/shogun/CMakeFiles/libshogun.dir/distance/Distance.cpp.o' failed
make[2]: *** [src/shogun/CMakeFiles/libshogun.dir/distance/Distance.cpp.o] Error 1
CMakeFiles/Makefile2:126: recipe for target 'src/shogun/CMakeFiles/libshogun.dir/all' failed
make[1]: *** [src/shogun/CMakeFiles/libshogun.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
// General version
// Works with multi threaded environment and imposes no constraints
// to the for() loop. This means that can be used inside a #pragma
// without problems.
pr = progress(range(0,10), io, ASCII)
for (int i=0; i<10; i++)
{
/* Do stuff */
pr.print_progress()
#include <thread>
#include <shogun/base/progress.h>
#include <shogun/io/SGIO.h>
#include <shogun/base/init.h>
using namespace shogun;
int main() {
init_shogun_with_defaults();
/*
* Written (W) 2017 Giovanni De Toni
*/
#ifndef __SG_PROGRESS_H__
#define __SG_PROGRESS_H__
#include <iterator>
#include <memory>
#include <string>
#include <shogun/base/some.h>
#include <iostream>
class base {
public:
base() : val(1) {};
virtual void print() {std::cout << val << std::endl;}
int ref() {};
int unref() {};
private:
#ifndef __SGOBJECT_H__
#define __SGOBJECT_H__
#include <shogun/lib/config.h>
#include <shogun/lib/common.h>
#include <shogun/lib/DataType.h>
#include <shogun/lib/ShogunException.h>
#include <shogun/base/Version.h>
#include <shogun/base/unique.h>
#include <shogun/io/SGIO.h>
Shogun's Progress Bar
1) Base features:
- UTF-8/ASCII progress bar mode switch (prevents Windows madness);
- Display current SG_PROGRESS information (maybe others like iterations/second);
- Three range types:
-> prange(0, 100): range with bound;
-> prange(100): range with upper bound;
-> prange(it.begin(), it.end()): range using an iterators (range over a custom set of values);
-> prange_mt(100): range multi-threaded;
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===========================================================-=============================================-============-================================================================================
ii a11y-profile-manager-indicator 0.1.10-0ubuntu3 amd64 Accessibility Profile Manager - Unity desktop indicator
ii account-plugin-facebook 0.12+16.04.20160126-0ubuntu1 all GNOME Control Center account plugin for single signon - facebook
ii account-plugin-flickr 0.12+16.04.20160126-0ubuntu1 all GNOME Control C