Assignment Library |
Copyright © 2003-2006 Thorsten Ottosen
Copyright © 2010- Erwann Rogard
Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see http://www.boost.org/LICENSE_1_0.txt).
operator+=()
operator()()
list_of()
map_list_of()
tuple_list_of()
repeat()
, repeat_fun()
and range()
operator &&
ref_list_of()
, cref_list_of()
and variants
ref_csv()
, cref_csv()
and variants
ptr_push_back()
, ptr_push_front()
,
ptr_insert()
and ptr_map_insert()
ptr_list_of()
list_of()
, map_list_of()
and ref_list_of<int>()
make_list_inserter()
ref_list_of()
, cref_list_of()
, and variantsref_csv()
, cref_csv()
, and variants+=
for standard containersrepeat()
, repeat_fun()
and
range()
&&
AnonymousList
AutoSize
Converter
RangeComparable
RangeExtensible
RefWrapper
RefArray
Repeatable
generic_list<>
list_inserter<>
static_generic_list<>
chain_impl_l<>
chain_impl_r<>
expr<>
static_array<>
There appear to be few
practical uses of operator,()
.
Bjarne
Stroustrup, The Design and Evolution of C++
The purpose of this
library is to make it easy to fill containers with data by overloading
operator,()
and operator()()
. These two operators
make it possible to construct lists of values with range and/or conversion capabilities:
vector<int> v; v += 1,2,3,4,5,6,7,8,9;
map<string,int> m; insert( m )( "Bar", 1 )( "Foo", 2 );
boost::array<int,9> a = cref_csv( 1,2,3,4,5,6,7,8,9 )
These lists are particularly useful in learning, testing, and prototyping situations, but can also be handy otherwise. The library comes with predefined operators for the containers of the standard library, but most functionality will work with any standard compliant container. The library also makes it possible to extend user defined types so for example a member function can be called for a list of values instead of its normal arguments.
Within two minutes you should be able to use this library. The main components are explained in these sections: Tutorial
operator+=()
operator()()
list_of()
map_list_of()
tuple_list_of()
repeat()
, repeat_fun()
and range()
operator&&
ref_list_of()
, cref_list_of()
and variants
ref_csv()
, cref_csv()
and variants
ptr_push_back()
, ptr_push_front()
,
ptr_insert()
and ptr_map_insert()
ptr_list_of()
operator+=()
To fill a vector (or any standard container) with values using
operator+=()
you write
Here we only stuffed constants into the container, but the list can consists of arbitrary expressions as long as the result of each expression is convertible to the#include <boost/assign/std/vector.hpp> // for 'operator+=()' #include <boost/assert.hpp>; using namespace std; using namespace boost::assign; // bring 'operator+=()' into scope { vector<int> values; values += 1,2,3,4,5,6,7,8,9; // insert values at the end of the container BOOST_ASSERT( values.size() == 9 ); BOOST_ASSERT( values[0] == 1 ); BOOST_ASSERT( values[8] == 9 ); }
value_type
of the container.
operator()()
We do not call operator()()
directly, but instead we call a
function that returns a proxy-object that defines operator()()
.
The function that returns the proxy object is always named after the member
function that is used to copy the values in the list into the container.
So to fill a map with pairs of values you write
Note that#include <boost/assign/list_inserter.hpp> // for 'insert()' #include <boost/assert.hpp> #include <string> using namespace std; using namespace boost::assign; // bring 'insert()' into scope { map<string,int> months; insert( months ) ( "january", 31 )( "february", 28 ) ( "march", 31 )( "april", 30 ) ( "may", 31 )( "june", 30 ) ( "july", 31 )( "august", 31 ) ( "september", 30 )( "october", 31 ) ( "november", 30 )( "december", 31 ); BOOST_ASSERT( months.size() == 12 ); BOOST_ASSERT( months["january"] == 31 ); }
operator()()
is much more handy when
we need to construct objects using several arguments
(up to five arguments are supported by default, but the limit can be customized).
This is also true for sequences:
Besides#include <boost/assign/list_inserter.hpp> // for 'push_front()' #include <boost/assert.hpp> #include <string> #include <utility> using namespace std; using namespace boost::assign; // bring 'push_front()' into scope { typedef pair< string,string > str_pair; deque<str_pair> deq; push_front( deq )( "foo", "bar")( "boo", "far" ); BOOST_ASSERT( deq.size() == 2 ); BOOST_ASSERT( deq.front().first == "boo" ); BOOST_ASSERT( deq.back().second == "bar" ); }
push_front()
we could also have used
push_back()
if the container has a corresponding member
function. Empty parentheses can be used to insert default-constructed
objects, for example,
push_front( deq )()()
will insert two default-constructed
str_pair
objects.
If operator()()
is too cumbersome to use with eg.
push_front()
we can also say
deque<int> di; push_front( di ) = 1,2,3,4,5,6,7,8,9; BOOST_ASSERT( di.size() == 9 ); BOOST_ASSERT( di[0] == 9 );
Just to make it perfectly clear, the code above is not restricted to the
standard containers, but will work with all standard compliant containers
with the right member function. It is only operator+=()
that has been restricted to
the standard containers.
list_of()
list_of()
comes into play. With list_of()
we can create anonymous lists that automatically converts to
any container:
If we need to initialize a container adapter, we need to help the compiler a little by calling#include <boost/assign/list_of.hpp> // for 'list_of()' #include <boost/assert.hpp> #include <list> #include <stack> #include <string> using namespace std; using namespace boost::assign; // bring 'list_of()' into scope { const list<int> primes = list_of(2)(3)(5)(7)(11); BOOST_ASSERT( primes.size() == 5 ); BOOST_ASSERT( primes.back() == 11 ); BOOST_ASSERT( primes.front() == 2 ); const stack<string> names = list_of( "Mr. Foo" )( "Mr. Bar")( "Mrs. FooBar" ).to_adapter(); const stack<string> names2 = (list_of( "Mr. Foo" ), "Mr. Bar", "Mrs. FooBar" ).to_adapter(); BOOST_ASSERT( names.size() == 3 ); BOOST_ASSERT( names.top() == "Mrs. FooBar" ); }
to_adapter()
. As the second example also shows,
we can use a comma-separated
list with list_of()
if we add parenthesis around the
entire right hand side. It is worth noticing that the first argument
of list_of()
determines the type of the anonymous list.
In case of the stack, the anonymous list consists of
const char*
objects which are then converted to
a stack of string
objects. The conversion is always
possible as long as the conversion between the stored types is possible.
Please notice that list_of()
can even convert to a
boost::array<T,sz>
and see also the list
of supported libraries .
Note that the type returned by
list_of()
(and its variants) has overloaded comparison operators. This allows you to
write test code such as
BOOST_CHECK_EQUAL( my_container, list_of(2)(3)(4)(5) );.
map_list_of()
The function#include <boost/assign/list_of.hpp> // for 'map_list_of()' #include <boost/assert.hpp> #include <map> using namespace std; using namespace boost::assign; // bring 'map_list_of()' into scope { map<int,int> next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6); BOOST_ASSERT( next.size() == 5 ); BOOST_ASSERT( next[ 1 ] == 2 ); BOOST_ASSERT( next[ 5 ] == 6 ); // or we can use 'list_of()' by specifying what type // the list consists of next = list_of< pair<int,int> >(6,7)(7,8)(8,9); BOOST_ASSERT( next.size() == 3 ); BOOST_ASSERT( next[ 6 ] == 7 ); BOOST_ASSERT( next[ 8 ] == 9 ); }
pair_list_of()
may also be used.
tuple_list_of()
tuple_list_of()
:
#include <boost/assign/list_of.hpp> #include <vector> using namespace std; using namespace boost::assign; { typedef boost::tuple<int,std::string,int> tuple; vector<tuple> v = tuple_list_of( 1, "foo", 2 )( 3, "bar", 4 ); BOOST_CHECK( v.size() == 2 ); BOOST_CHECK( boost::get<0>( v[1] ) == 3 ); }
repeat()
, repeat_fun()
and range()
Sometimes it is too irritating to repeat the same value many times. This is
where repeat()
can be handy:
As we can see, then the first argument to#include <boost/assign/list_of.hpp> #include <boost/assign/std/vector.hpp> #include <boost/assert.hpp> using namespace std; using namespace boost::assign; { vector<int> v; v += 1,2,3,repeat(10,4),5,6,7,8,9; // v = [1,2,3,4,4,4,4,4,4,4,4,4,4,5,6,7,8,9] BOOST_ASSERT( v.size() == 3 + 10 + 5 ); v = list_of(1).repeat(5,2)(3); // v = [1,2,2,2,2,2,3] BOOST_ASSERT( v.size() == 1 + 5 + 1 ); push_back( v )(1).repeat(1,2)(3); // v = old v + [1,2,3] BOOST_ASSERT( v.size() == 10 ); }
repeat()
is the number
of times to repeat the second argument.
A more general list can be constructed with repeat_fun()
:
The only requirement of the second argument to#include <boost/assign/std/vector.hpp> #include <boost/assert.hpp> #include <cstdlib> // for 'rand()' using namespace std; using namespace boost::assign; template< class T > struct next { T seed; next( T seed ) : seed(seed) { } T operator()() { return seed++; } }; { vector<int> v; v += 1,2,repeat_fun(4,&rand),4; // v = [1,2,?,?,?,?,4] BOOST_ASSERT( v.size() == 7 ); push_back( v ).repeat_fun(4,next<int>(0))(4).repeat_fun(4,next<int>(5)); // v = old v + [0,1,2,3,4,5,6,7,8] BOOST_ASSERT( v.size() == 16 ); }
repeat_fun()
is that
it is a nullary function.
If you just need to insert an iterator-range somewhere in the list, the member function range()
provides just what you want.
It is based on Boost.Range, so you can pass all the ranges supported by that library. For example
As you can see, one can also pass two iterators if that is more appropriate. The last example also introduces list of references. More about that below.#include <boost/assign/list_inserter.hpp> // for 'push_back()' #include <boost/assign/list_of.hpp> // for 'list_of()' and 'ref_list_of<int>()' #include <boost/assert.hpp> using namespace std; using namespace boost::assign; { vector<int> v, v2; v = list_of(1)(2)(3); v2 = list_of(0).range(v).range(v.begin(),v.end())(4); // v2 = [0,1,2,3,1,2,3,4] BOOST_ASSERT( v2.size() == 8u ); push_back( v ).range(v2)(5); // v = [1,2,3,0,1,2,3,1,2,3,4,5] BOOST_ASSERT( v.size() == 12u ); // // create a list of references, some coming from a container, others from the stack // int x = 0; int y = 1; BOOST_ASSERT( ref_list_of<10>(x).range(v2)(y).size() == 10u ); }
&&
range()
works in combination with functions
such as list_of()
, it is not compatible with
ref_csv()
, ref_list_of()
and their variants,
which are part of a different framework. The function operator&&
,
achieves a similar goal by chaining ranges at compile time, which is typically the faster option.
Continuing the example above,
#include <boost/assign/auto_size/chain.hpp> #include <boost/assign/auto_size/ref_list_of.hpp> { BOOST_ASSERT( ( cref_list_of( x )&& v2 && cref_list_of( y ) ).size() == 10u ); }
ref_list_of()
, cref_list_of()
and variantsYou can only use lvalues with#include <boost/assign/auto_size/ref_list_of.hpp> #include <boost/range/algorithm/max_element.hpp> using namespace boost::assign; { int a=1,b=5,c=3,d=4,e=2,f=9,g=0,h=7; int& max = *boost::max_element( ref_list_of(a)(b)(c)(d)(e)(f)(g)(h) ); BOOST_CHECK_EQUAL( max, f ); max = 8; BOOST_CHECK_EQUAL( f, 8 ); const int& const_max = *boost::max_element( cref_list_of(1)(5)(3)(d)(e)(f)(g)(h) ); BOOST_CHECK_EQUAL( max, const_max ); }
ref_list_of()
while
cref_list_of()
accepts rvalues too, as exemplified by the first three arguments of the
corresponding function call in this example.
A collection built from ref_list_of()
and cref_list_of()
has most of the functionality of boost::array<>
, and
the same conversion capabilities as a collection built from list_of()
. However, the user can customize his own functionality via a policy and
call it with the overloaded functions ref_list_of<P>()
and cref_list_of<P>()
, where P
is an associated policy tag.
See the reference for details
There are overloads which predate the above functions,
ref_list_of<int>()
and cref_list_of<int>()
, whose integer template parameter specifies the maximum number of arguments.
The resulting collection exposes a similar interface to that above, save for the specifics of an array, and is not customizable via a policy.
See the reference for details
A variation on ref_list_of()
and cref_list_of()
, are ref_rebind_list_of()
and cref_rebind_list_of()
, respectively,
that have rebind, rather than copy semantics, when the collection is used as the left hand side of an assignement.
Their use is discouraged unless this specific feature is required. See the reference.
ref_csv()
, cref_csv()
and variantsref_list_of()
, cref_list_of()
,
their respective rebind analogs, and the custom policy overloads of these four, have counterparts that are identified by suffix 'csv' (comma separated values)
instead of 'list_of'. For example,
#include <boost/assign/auto_size/ref_csv.hpp> #include <boost/range/algorithm/max_element.hpp> using namespace boost::assign; { int a=1,b=5,c=3,d=4,e=2,f=9,g=0,h=7; int& max = *boost::max_element( ref_csv(a,b,c,d,e,f,g,h) ); BOOST_CHECK_EQUAL( max, f ); }
The result of a csv call has the same array and conversion capabilities as its non-csv counterpart. The main difference is that the the collection is not extensible. See the reference.
The maximum number of arguments to a csv function is BOOST_ASSIGN_CSV_SIZE
.
As a last example, let us assume that we need to keep track of the result of soccer matches. A team will get one point if it wins and zero otherwise. If there has been played three games in each group, the code might look like this:
In the first example, notice how the result of#include <boost/assign/list_of.hpp> #include <boost/assign/list_inserter.hpp> #include <boost/assert.hpp> #include <string> #include <vector> using namespace std; using namespace boost::assign; { typedef vector<int> score_type; typedef map<string,score_type> team_score_map; typedef pair<string,score_type> score_pair; team_score_map group1, group2; // // method 1: using 'insert()' // insert( group1 )( "Denmark", list_of(1)(1) ) ( "Germany", list_of(0)(0) ) ( "England", list_of(0)(1) ); BOOST_ASSERT( group1.size() == 3 ); BOOST_ASSERT( group1[ "Denmark" ][1] == 1 ); BOOST_ASSERT( group1[ "Germany" ][0] == 0 ); // // method 2: using 'list_of()' // group2 = list_of< score_pair > ( "Norway", list_of(1)(0) ) ( "USA", list_of(0)(0) ) ( "Andorra", list_of(1)(1) ); BOOST_ASSERT( group2.size() == 3 ); BOOST_ASSERT( group2[ "Norway" ][0] == 1 ); BOOST_ASSERT( group2[ "USA" ][0] == 0 ); }
list_of()
can be converted automatically to a vector<int>
because
insert()
knows it expects a vector<int>
.
In the second example we can see that list_of()
is somewhat
less intelligent since here it needs to be told explicitly what arguments to
expect. (In the future it might be possible to introduce a more intelligent
conversion layer in list_of()
.)
ptr_push_back(),
ptr_push_front()
, ptr_insert()
and ptr_map_insert()
new
manually:
Notice how you may provide a template argument to these functions. This argument determines the type to allocate with#include <boost/assign/ptr_list_inserter.hpp> // for 'ptr_push_back()', 'ptr_insert()' and 'ptr_push_front()' #include <boost/assign/ptr_map_inserter.hpp> // for 'ptr_map_insert()' #include <boost/ptr_container/ptr_deque.hpp> #include <boost/ptr_container/ptr_set.hpp> #include <boost/ptr_container/ptr_map.hpp> // // Example class // struct Foo { int i; Foo() : i(0) { } Foo( int i ) : i(i) { } Foo( int i, int ) : i(i) { } Foo( const char*, int i, int ) : i(i) { } virtual ~Foo() {} }; struct Bar : Foo { Bar() { } Bar( int i ) : Foo( 42 ) { } }; // // Required by ptr_set<Foo> // inline bool operator<( Foo l, Foo r ) { return l.i < r.i; } using namespace boost; using namespace boost::assign; int main() { ptr_deque<Foo> deq; ptr_push_back( deq )()(); BOOST_ASSERT( deq.size() == 2u ); ptr_push_back<Bar>( deq )()(); // insert 'Bar' objects BOOST_ASSERT( deq.size() == 4u ); ptr_push_front( deq )( 3 )( 42, 42 )( "foo", 42, 42 ); BOOST_ASSERT( deq.size() == 7u ); ptr_set<Foo> a_set; ptr_insert( a_set )()( 1 )( 2, 2 )( "foo", 3, 3 ); BOOST_ASSERT( a_set.size() == 4u ); ptr_insert( a_set )()()()(); BOOST_ASSERT( a_set.size() == 4u ); // duplicates not inserted ptr_insert<Bar>( a_set )( 42 ); // insert a 'Bar' object BOOST_ASSERT( a_set.size() == 5u ); ptr_map<int,Foo> a_map; ptr_map_insert( a_map )( 1 )( 2, 2 )( 3, 3, 3 )( 4, "foo", 4, 4 ); ptr_map_insert<Bar>( a_map )( 42, 42 ); // insert a 'Bar' object }
new
.
You have to specify this argument when the container is based on an abstract type (because one cannot create objects of such a type).
For ptr_map_insert()
the first argument arg1
in an argument tuple (arg1,arg2,...,argN)
is used to
construct a key; this means that the first argument need only be convertible to the key_type
of the container.
The rest of the arguments are used to construct the mapped object.
ptr_list_of()
list_of()
to initialize containers, you can
use ptr_list_of()
to initialize a pointer container.
Here is a small example:
Notice that a trailing#include <boost/assign/ptr_list_of.hpp> #include <boost/ptr_container/ptr_deque.hpp> using namespace boost; using namespace boost::assign; { ptr_deque<Foo> deq; deq = ptr_list_of<Foo>( 42 )()()( 3, 3 )( "foo", 2, 1 ); BOOST_CHECK( deq.size() == 5 ); }
.to_container(deq)
may be added to help many poor
compilers to figure out the conversion (a few get it right).
Notice also that pointer maps are
not supported.
That is all; now you are ready to use this library.
This section explains the way the library is implemented.
A free-standing function (eg. push_back()
or operator+=()
) returns a proxy
object which is responsible for the insertion or the assignment. The proxy
object does the insertion or assignment by overloading operator,()
and operator()()
and by calling the "insert" function from within
those operators. The "insert" function is typically stored in the proxy object
by using boost::function
.
Often overloading
of operator,()
is discouraged because it can lead to surprising
results, but the approach taken in this library is safe since the
user never deals with objects that have overloaded operator,()
directly. However, you should be aware of this:
The expressions in a comma-separated list no longer follow the rules of the built-in comma-operator. This means that the order of evaluation of expressions in a comma-separated list is undefined like when one specifies a list of function arguments.
Most of the code in this document use int
in the examples,
but of course it works for arbitrary types as long as they are
Copy Constructible. The inserted data need not be constant data,
but can be variables or data returned from functions; the only requirement
is that the type of the data is convertible to the type stored in the
container.
All forwarding is done by passing objects by const
reference.
Originally arguments were passed by value (and still is in
tuple_list_of()
). One thing to remember is that references
can be passed by using boost::ref
.
The above considerations motivate a reference in two parts, one for the functions and operators, whose usage is the primary interest of a client, and another for the implementation i.e. the proxy objects, which remain invisible to the client, but are important from a development standpoint.
The functions, operators and their proxy objects are by defaut in namespace boost::assign
.
list_of()
, map_list_of()
and ref_list_of<int>()
make_list_inserter()
ref_list_of()
, cref_list_of()
, and variantsref_csv()
, cref_csv()
, and variants+=
for standard containersrepeat()
, repeat_fun()
and
range()
&&
Please notice <boost/assign/list_inserter.hpp>
is included for each header that defines operator+=()
.
| Header | Includes |
|---|---|
| <boost/assign.hpp> | everything except support for pointer containers |
| <boost/assign/auto_size.hpp> | All functions return auto-size proxy objects. |
| <boost/assign/auto_size/range/chain_operator.hpp> | operator&&
|
| <boost/assign/auto_size/ref_csv.hpp> | ref_csv() and cref_csv()
|
| <boost/assign/auto_size/ref_rebind_csv.hpp> | ref_rebind_csv() and cref_rebind_csv()
|
| <boost/assign/auto_size/ref_list_of.hpp> | ref_list_of() and
cref_list_of() |
| <boost/assign/auto_size/ref_rebind_list_of.hpp> | ref_rebind_list_of() and
cref_rebind_list_of() |
| <boost/assign/list_of.hpp> |
list_of() , map_list_of(),
tuple_list_of(), ref_list_of<int>()
|
| <boost/assign/std.hpp> | operator+=() for all standard containers (see below) |
| <boost/assign/std/deque.hpp> | operator+=() for std::deque , <deque>
|
| <boost/assign/std/list.hpp> | operator+=() for
std::list , <list>
|
| <boost/assign/std/map.hpp> | operator+=() for
std::map and std::multimap ,
<map> |
| <boost/assign/std/queue.hpp> | operator+=() for
std::queue and std::priority_queue ,
<queue> |
| <boost/assign/std/set.hpp> | operator+=() for
std::set and std::multiset ,
<set> |
| <boost/assign/std/slist.hpp> | operator+=() for
std::slist if the class is available ,
<slist> |
| <boost/assign/std/stack.hpp> | operator+=() for
std::stack , <stack>
|
| <boost/assign/std/vector.hpp> | operator+=() for
std::vector , <vector>
|
| <boost/assign/assignment_exception.hpp> | Class assignment_exception which might
be thrown by the proxy returned by list_of()
|
| <boost/assign/list_inserter.hpp> | Functions make_list_inserter() , push_back() ,
push_front() ,insert() ,
push() and class list_inserter
which is the back-bone of this entire library.
|
| <boost/assign/ptr_list_inserter.hpp> | Functions ptr_push_back() ,
ptr_push_front() and ptr_insert()
|
| <boost/assign/ptr_map_inserter.hpp> | Functions ptr_map_insert()
|
| <boost/assign/ptr_list_of.hpp> | Function ptr_list_of()
|
This library uses the boost Preprocessor Library to implement overloaded
versions of operator()()
and list_of()
. By default you
can call these functions with five arguments, but you can also customize this
number by defining a macros before including a header from this library:
#define BOOST_ASSIGN_MAX_PARAMS 10 #include <boost/assign.hpp>
list_of()
T Element
Let U
be either of T
or const T
, and d
an instance thereof.
Expression Result list_of( d ) generic_list
<U>
namespace boost { namespace assign { template< class T > Implementation-defined list_of(); template< class T > Implementation-defined list_of( T t ); template< class T, class U, class U2 > Implementation-defined list_of( U u, U2 u2 ); template< class T, class U, class U2, class U3 > Implementation-defined list_of( U u, U2 u2, U3 u3 ); template< class T, class U, class U2, class U3, class U4 > Implementation-defined list_of( U u, U2 u2, U3 u3, U4 u4 ); template< class T, class U, class U2, class U3, class U4, class U5 > Implementation-defined list_of( U u, U2 u2, U3 u3, U4 u4, U5 u5 ); template< class Key, class T > Implementation-defined map_list_of( Key k, T t ) { return list_of< std::pair<Key,T> >()( k, t ); } } // namespace 'assign' } // namespace 'boost'
map_list_of()
Parameter Description K A key type T A data type
Let k
and d
denote instances of const K
and const T
, respectively.
Expression Result map_list_of( k, d ) generic_list
<std::pair<const K, const T > >
ref_list_of<int>()
This function has been superseded.
Usage
Parameter Description N An integer T Element
Let U
be either T
or const T
and d
an object of type U
.
Expression Result ref_list_of<int>(d) static_generic_list
<U,>
make_list_inserter()
A simple "constructor" function for list_inserter
. A typical
use of this function is to call it with the result of
boost::bind()
which in general returns some unreadable and weird class template.
namespace boost { namespace assign { template< class Function > list_inserter<Function> make_list_inserter( Function fun ) { return list_inserter<Function>( fun ); } } }
ref_list_of()
,
cref_list_of()
and variants
Parameter Description P A policy tag T Element
Let d1
and d2
denote objects of type T
and const T
, respectively.
Expression Result Description ref_list_of<P>( d1 ) expr<_,T,1,assign_reference_copy,P> cref_list_of<P>( d2 ) expr<_,const T,1,assign_reference_copy,P> ref_list_of( d1 ) expr<_,T,1,assign_reference_copy,use_default> cref_list_of( d2 ) expr<_,const T,1,assign_reference_copy,use_default>
Usage for the related functions ref_rebind_list_of()
and cref_rebind_list_of()
are identical to those
above, except the fourth argument to expr<> is assign_reference_copy.
ref_csv()
, cref_csv()
and variants
Parameter Description P A policy tag T Element N Size
Let ai
and bi
denote the i-th element of size-N sequences of objects of type T
and const T
,
respectively
Expression Result ref_csv<P>(a1,...,aN) A custom implementation cref_csv<P>(b1,...,bN) A custom implementation ref_csv(a1,...,aN) static_array<T,N,assign_reference_copy> cref_csv(b1,...,bN) static_array<const T,N,assign_reference_copy>
Usage for the related functions ref_rebind_list_of()
and cref_rebind_list_of()
are identical to those
above but with rebind rather than copy semantics.
The maximum number of arguments to a csv function is BOOST_ASSIGN_CSV_SIZE
.
+=
for standard containers In the following three dots (...) will mean
implementation defined.
operator+=()
returns a proxy that forwards calls to either
push_back()
,insert()
, or push()
depending on which operation the container supports.
Note that the extra template argumentnamespace boost { namespace assign { template< class V, class A, class V2 > list_inserter< ... > operator+=( std::deque<V,A>& c, V2 v ); template< class V, class A, class V2 > list_inserter< ... > operator+=( std::list<V,A>& c, V2 v ); template< class K, class V, class C, class A, class P > list_inserter< ... > operator+=( std::map<K,V,C,A>& m, const P& p ); template< class K, class V, class C, class A, class P > list_inserter< ... > operator+=( std::multimap<K,V,C,A>& m, const P& p ); template< class V, class C, class V2 > list_inserter< ... > operator+=( std::queue<V,C>& c, V2 v ); template< class V, class C, class V2 > list_inserter< ... > operator+=( std::priority_queue<V,C>& c, V2 v ); template< class K, class C, class A, class K2 > list_inserter< ... > operator+=( std::set<K,C,A>& c, K2 k ); template< class K, class C, class A, class K2 > list_inserter< ... > operator+=( std::multiset<K,C,A>& c, K2 k ); #ifdef BOOST_HAS_SLIST template< class V, class A, class V2 > list_inserter< ... > operator+=( std::slist<V,A>& c, V2 v ); #endif template< class V, class C, class V2 > list_inserter< ... > operator+=( std::stack<V,C>& c, V2 v ); template< class V, class A, class V2 > list_inserter< ... > operator+=( std::vector<V,A>& c, V2 v ); } // namespace 'assign' } // namespace 'boost'
V2
etc. is
necessary to allow for types convertible to V
.
repeat()
,
repeat_fun()
and range()
These first two function exist both as free-standing functions and as member functions of the object returned by
list_of()
and of list_inserter
.
The free-standing versions are used to create a
hook for operator,()
so we can call the functions in the middle of a comma-list. The member functions
are used when we need to call the functions in the middle of a parenthesis-list. In both cases we have that
repeat()
is (std::size_t,T)
, and
repeat_fun()
is (std::size_t,Nullary_function)
The function range()
only exists as a member function. The following two overloads are provided:
template< class SinglePassIterator > Implementation-defined range( SinglePassIterator first, SinglePassIterator last ); template< class SinglePassRange > Implementation-defined range( const SinglePassRange& rng );
&&
Parameter Description R1 Models Range R2 Models Range
In particular, elements modeling RefWrapper(T) are allowed.
Parameter Description boost::range_reference<R>::type Convertible to T
Let r1
, r2
, denote instances of R1
, and const R2
.
Let s1
and s2
of type R1
, and R2
, respectively,
such that at least one of them is const
.
Expression Result r1 && r2 result_of::chain_l
<R1,R2>::type
s1 && s2 result_of::chain_r
<R1,R2>::type
AnonymousList
AutoSize
Chainable
Converter
RangeComparable
RangeExtensible
RefWrapper
RefArray
Repeatable
For now AnonymousList is still a loose concept (once an acceptable formalization is found, this doc will be updated accordingly). Its distinguishing feature, however, is that it exposes public member functions to internally grow a list of a given type, T.
How the internal list is accessible publically is not part of the concept. It needs to be specified separately, such as AnonymousList+Range
For now Auto-Size list is still a loose concept (once an acceptable formalization is found, this doc will be updated accordingly). Its distinguishing feature, is that it is a compile time expression that is formed from references to passed argument, which may be faster than runtime alternatives, and frees the user from the need to specify the size of the resulting collection.
Expression Result c && r Models Range and is equivalent to c and r concatenated
<boost/assign/list_of.hpp>
<boost/assign/auto_size/reference_wrapper/copy.hpp>
<boost/assign/auto_size/reference_wrapper/rebind.hpp>
Expression Result r convertible to T&
Concept Expression Post-condition Model Copy r = x; T& y = r; x == y assign_reference_copy
Rebind r = x; T& y = r; &x == &y assign_reference
,assign_reference_rebind
<boost/assign/list_of.hpp>
<boost/assign/auto_size/range/converter.hpp>
Let V1
, V2
and V3
denote three classes, each of whose interface captures a valid conversion operand for Converter,
that we call container, adapter, and indexable. Let v1
, v2
and v3
, instances thereof. Let C denote
a class that models Converter, and c and instance thereof.
Let b
and e
denote the begin and end iterators of c, and n the distance between them. Assume that the elements of each
of these data-structures are of type X
, of which x
is and instance, and k
any index in the range
[0,n).
v1
, v2
and v3
must be copy constructible.
In addition,
Concept Expression Effect Container V1 v1(b,e); Constructs an object of type V Adapter v2.push(x) Adds element x to a Indexable v3[k] = x Assigns value x to the kth element of r
Expression v = c; v = c.convert_to_container(); v2 = c.to_adapter()
BOOST_ASSIGN_AS_CONVERTER
inside its definition.
RefArray
<boost/assign/auto_size/array/interface.hpp>
boost::array<>
,
each element of which models RefWrapper for value type T.
range_comparison_op::base_of<D>
.
<boost/assign/list_of.hpp>
Expression Result e.range( v ); reference to e
Expression Result e.repeat( n, t ); reference to e
generic_list<>
list_inserter<>
static_generic_list<>
expr<>
static_array<>
chain_impl::expr_l<>
chain_impl::expr_r<>
generic_list<>
<boost/assign/list_of.hpp>
Parameter Description T Element
AnanymousList(T) , Converter(T) , RangeComparable , RangeExtensible , Repeatable(T)
static_generic_list<>
<boost/assign/list_of.hpp>
Parameter Description T Element N Size
AnonymousList for value type assign_reference<T>, Converter(T) , RangeComparable , RangeExtensible
list_inserter<>
This class is responsible for inserting elements into containers and it is the key to extending the library to support your favourite class.
<boost/assign/list_inserter.hpp>
Parameter Description Function A functor to which insertion is delegated to Argument Argument to be inserted
namespace boost { namespace assign { template< Function, Argument = void > class list_inserter { Function fun; public: explicit list_inserter( Function fun ); // conversion constructor template< class Function2, class Arg > list_inserter( const list_inserter<Function2,Arg>& ); public: template< class U > list_inserter& operator,( U u ); template< class U > list_inserter& operator=( U u ); // calls 'fun()' with default-constructed object list_inserter& operator()(); template< class U > list_inserter& operator()( U u ); template< class U, class U2 > list_inserter& operator()( U u, U2 u2 ) { // // if 'Argument' is 'void' // fun( u, u2 ); // else // fun( Argument( u, u2 ) ); // return *this; } // // similarly up to 5 arguments // }; template< class C > list_inserter< ... > push_back( C& ); template< class C > list_inserter< ... > push_front( C& ); template< class C > list_inserter< ... > insert( C& ); template< class C > list_inserter< ... > push( C& ); } // namespace 'assign' } // namespace 'boost'
Notice how the arguments to operator,()
and
operator()()
are passed differently to
fun
depending of the type of Argument
.
So if we only pass one template argument to list_inserter,
we can forward "arbitrary" argument lists of functions. If we pass
two template arguments to list_inserter
we can
construct types with "arbitrary" constructors.
And because a reference to list_inserter
is returned, we can chain argument list together in a very space-efficient manner.
expr<>
<boost/assign/auto_size/detail/expr.hpp>
Parameter Description Requirements E Previous collection Unspecified T Element Unspecified N Size Unspecified R A class template R<T> models RefWrapper for value type T P Policy tag Unspecified
Expression Description expr<E,T,N,R,use_default> models RefArray<T>, Converter<T>, RangeComparable<T>
namespace boost { namespace assign { namespace detail { namespace auto_size { template<typename E,typename T,int N, template<typename> class R,typename P> class expr{ public: typedef Implementation-defined result_type; explicit expr(const E& p,T& t); template<typename E1,typename P1 > explicit expr(const expr<E1,T,N,R,P1>& that); result_type operator()(T& t)const; }; template<typename A,typename E,typename T,int N, template<typename> class R,typename P,bool F> void write_to_array(A& a,const expr& e); } // namespace 'auto_size' } // namespace 'detail' } // namespace 'assign' } // namespace 'boost'
A call to the unary operator returns an object that keeps a reference to the passed argument, and links to the
current object, thereby forming a collection whose final size is determined at compile time.
The function write_to_array()
is typically used to pass the elements of the collection to the policy,
that will be chosen to have the desired interface such as iterators and conversion operators.
static_array<>
<boost/assign/auto_size/array/static.hpp>
Parameter Description Requirements T Element Unspecified N Size Unspecified R A class template R<T> models RefWrapper(T)
boost::array<R<T>,N>
,
Expression Effect write_to_array(a,e) Assigns a's elements
chain_impl::expr_l<>
<boost/assign/auto_size/range/chain_l.hpp>
Parameter Description L Implementation-defined E Implementation-defined Rng1 Models Range is_first boolean constant V A value type R A reference type
chain_impl::expr_r<>
<boost/assign/auto_size/range/chain_r.hpp>
Parameter Description E Implementation-defined Rng1 Models Range is_first boolean constant V A value type R A reference type
The exception guarantees by the library is the same as guarantee as the guarantee of the function that is forwarded to. For standard containers this means that the strong guarantee is given for a single insertions and that the basic guarantee is given for many insertions (provided that the object being copied gives the basic guarantee).
The functions may throw standard exceptions
like std::bad_alloc
. Note however that, unfortunately, the standard does not guarantee allocation-failures
in standard containers to be reported by std::bad_alloc
or exceptions derived from std::exception
.
assignment_exception
The exception is thrown by the conversion operator in the proxy object
returned from list_of()
.
namespace boost { namespace assign { class assignment_exception : public std::exception { public: explicit assignment_exception( const char* what ); virtual const char* what() const throw(); }; } }
It is very simple to make the library work with new classes.
This code shows how to use operator+=()
with
a container:
wheretemplate< class V, class A, class V2 > inline list_inserter< assign_detail::call_push_back< std::vector<V,A> >, V > operator+=( std::vector<V,A>& c, V2 v ) { return make_list_inserter( assign_detail::call_push_back< std::vector<V,A> >( c ) )( v ); }
call_push_back
is defined as
Note that we pass a second template argument totemplate< class C > class call_push_back { C& c_; public: call_push_back( C& c ) : c_( c ) { } template< class T > void operator()( T r ) { c_.push_back( r ); } };
list_inserter
so argument
lists will be used to construct a V
object. Otherwise we
could end up trying to call push_back()
with n arguments
instead of one.
An alternative way would be to use boost::function
and
boost::bind()
in combination. However, in this case one must
remember that it is illegal to take the address of a function in
the standard library.
Calling a function with more that one argument can be very useful too. This small example shows how we take advantage of this functionality:
The full example can be seen in email_example.cpp// // A class representing emails // class email { public: enum address_option { check_addr_book, dont_check_addr_book }; private: typedef std::map< std::string,address_option > address_map; // // Store list of persons that must be cc'ed // mutable address_map cc_list; // // This extra function-object will take care of the // insertion for us. It stores a reference to a // map and 'operator()()' does the work. // struct add_to_map { address_map& m; add_to_map( address_map& m ) : m(m) {} void operator()( const std::string& name, address_option ao ) { m[ name ] = ao; } }; public: // // This function constructs the appropriate 'list_inserter'. // Again we could have use 'boost::function', but it is // trivial to use a function object. // // Notice that we do not specify an extra template // parameter to 'list_inserter'; this means we forward // all parameters directly to the function without // calling any constructor. // list_inserter< add_to_map > add_cc( std::string name, address_option ao ) { // // Notice how we pass the arguments 'name' and 'ao' to // the 'list_inserter'. // return make_list_inserter( add_to_map( cc_list ) )( name, ao ); } }; // // Now we can use the class like this: // email e; e.add_cc( "Mr. Foo", email::dont_check_addr_book ) ( "Mr. Bar", email::check_addr_book ) ( "Mrs. FooBar", email::check_addr_book );
Additional examples can be found in the test files:
boost::array
boost::multi_index_container
Boost.Pointer Container
Library has been successfully compiled and tested with MVC++ 7.1, GCC 3.2 (under Cygwin) Comeau 4.3.3
There are known limitation on platforms not supporting templated
conversion operators. The solution is to call certain member functions on
the object returned by list_of()
:
{ using namespace std; using namespace boost; using namespace boost::assign; vector<int> v = list_of(1)(2)(3)(4).to_container( v ); set<int> s = list_of(1)(2)(3)(4).to_container( s ); map<int,int> m = map_list_of(1,2)(2,3).to_container( m ); stack<int> st = list_of(1)(2)(3)(4).to_adapter( st ); queue<int> q = list_of(1)(2)(3)(4).to_adapter( q ); array<int,4> a = list_of(1)(2)(3)(4).to_array( a ); }
Notice how one must supply the functions with an argument so the right return type can be deduced.
Some standard libraries are also broken. One problem is that
insert()
might not work:
The solution is to usemap<int,int> next; insert( next )(1,2)(2,3); // compile-time error
map_list_of()
instead:
map<int,int> next = map_list_of(1,2)(2,3);
The idea for an assignment/initialization library is not new. The functionality of this library resembles Leor Zolman's STL Container Initialization Library a great deal, but it does not rely on string parsing to achieve its goals.
The
library is non-intrusive and puts only a minimum of requirements
on its supported classes.
Overloading operator comma is sometimes viewed as a bad practice [1]. However, it has been done
with success in eg. the Generative Matrix Computation Library and Blitz to initialize matrices
(see [2]) and [3]). The
Initialization Library overloads
the comma operator in a safe manner by letting free standing functions
return an object that is responsible for the initialization. Therefore it takes
explicit
action from the programmer to begin using the overloaded operator,()
.
There has recently been some discussion about enhancing the language to support better initialization (see [4]).
Special thanks goes to
chain_l
and chaining ranges.
The auto-size framework for building a collection of references whose size is deduced at compile time supersedes ref_list_of<int>()
.
The latter will continue to be supported to ensure backward compatibility.
(C) Copyright Thorsten Ottosen 2003-2006
(C) Copyright Erwann Rogard 2010-


My name is sandeep Mishra.I'm Persuing MCA degree from MANIT, Bhopal.I completed BCA degree from IIPS, DAVV. My schooling was done from indore,(M.P.).
About mine i'm a cool hearted person so usually see every difficulty in a positive way. I'm good in many programming languages like c, c++, java but my keen interest in desigining websites and managing databases. I've done various projects based on different languages like url-shortener, Home-Tutor Service, Crud Application, To-do app.My hobbies are Treking, travelling, listening music, shopping. I've a diferent bonds with pets.I love pet's.
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour
Some quick example text to build on the card title and make up the bulk of the card's content.
Some quick example text to build on the card title and make up the bulk of the card's content.
Some quick example text to build on the card title and make up the bulk of the card's content.
Some quick example text to build on the card title and make up the bulk of the card's content.
The Robin Hood Army is a volunteer-based Zero funds organization that works to get surplus food from restaurants to the less fortunate sections of society in cities across India and 14 other countries.
As the name suggests,Muskurahat Foundation believes in bringing a smile on faces that deserve it the most but do not have access to happiness in their lives.
The Robin Hood Army is a volunteer-based Zero funds organization that works to get surplus food from restaurants to the less fortunate sections of society in cities across India and 14 other countries.
As the name suggests,Muskurahat Foundation believes in bringing a smile on faces that deserve it the most but do not have access to happiness in their lives.


{% extends "base.html" %} {% block content %}
Booksonas is a work-in-progress for better library management. Right now, we create a library from books in your Dropbox, which you can organize, search, and send to your various devices via email.
Booksonas is alpha software, currently comes with no warranty. Currently, you use it at your own risk. We do not write to your Dropbox or make edits there.
{% endblock %}


GAME
OVER
Canvas not supported
Space Shooter
Start Game!
Options (coming soon)
Pause/Resume
Score:
Combo:


|
|
|
|
Hello Leona Rodriguez,
Congratulations! You have received a new booking.


Caution Hot is one of the restauranst in Maginhawa that never runs out of customers. We would always have to wait in line because that's how in demand their ramen is! But when you get there, I promise you it is worth the wait. They offer different Ramens, there is only one classic (if you are not the spicy type) then tehre are the spicy ramens and there are levels of spiciness. I also try their favorite milktea here that goes well with the Ramen.
Rib City has one of the tastiest ribs I've tasted. You can choose different side dishes for the Suburban steak. It can be the creamy pesto or the mash potato. They serve their ribs in huge portions and the price is very affordable.
Crazy Katsu is my favorite restaurant in Maginhawa. There was one time where we were here for a week straight. For only P 160, you can get their chicken katsu! It is served with rice and their yummy japanese cabbage. If you are also a fan of spicy sauce, this is the place to come here!
Whether it is breakfast or lunch, Artsy Cafe never fail to be the scenty relaxing place to dine in.  Because its a cafe, there's also a lot of yummy coffee shakes and drinks.
Fat Cousins' steaks is the best. It also comes with a refillable iced tea and mash potato. What I love here is how well cooked the steak is, it is very tender and juicy while their gravy is also semi-sweet and spicy.
Lost Bread is where I go to when I crave for desserts at Maginhawa. Their drinks are just out of this world. They are very creative with their different flavors of cotton candy drinks. Their drinks come with chocolates or fruits, etc. I have to admit it is a bit pricy, but the taste is really worth it.
Taste of heaven cause when you sip, you literally feel like you're in heaven. A taste of heaven offers different flavors of shake and my personal favorite is their red velvet cheescake.


For the final project, I have pushed all my files such as html and css to the git repository.
* Created a git repository called unix-server.
* Cloned the repository in my virtual machine.
* Practiced using git commands such as git commit, git pull, git push etc.
* Tried to merge
Deployment of Jekyll website
* Cloned repository into a regular user's home directory
* Installed required ruby and jekyll packages
* Jekyll site creation
Individual: Chris worked on getting the files on the server and tried attaching it to the main server.
Group: As Jordano and I were working on the files, Chris was in charge of helping where we had difficulties and fix the few bugs that appeared here and there.


We enhance mices!
- engage proactive bandwidth
- synergize bleeding-edge architectures
- leverage frictionless functionalities
- incubate granular mindshare
- enhance collaborative niches
- aggregate virtual e-tailers
- synthesize efficient infrastructures
- embrace 24/365 platforms
- deploy wireless e-business
- syndicate mission-critical interfaces
- unleash B2C markets
- benchmark back-end infrastructures
- embrace B2B applications


26 March 2002
Disease Outbreak Reported
As of 9 March, WHO has reported a total of 22 023 cases, including 609 deaths (case-fatality rate, 2.8%) in the country since the beginning of the outbreak on the 28th October 2001; The Southern Region is the worst affected region with 69% of the cases reported so far. Laboratory tests have confirmed Vibrio cholerae O1.
The Ministry of Health has reactivated the cholera control task forces at national and district levels to control the epidemic and WHO, along with UNICEF is assisting the Ministry to coordinate the response. Surveillance has been intensified at district level and temporary cholera control treatment centres have been established. Chlorination of water supplies is underway in the affected communities and hygiene education has been strengthened. Village committees have been mobilized, encouraging people to use latrines and safe drinking water.
The government of Malawi through the Office for the Coordination of Humanitarian Affairs (OCHA) has launched an appeal for US$ 21 million for the flood and food crisis in Malawi, including funds for controlling the cholera outbreak. WHO meets regularly with its main partners the European Union, United Nations Development Programme, The United States Agency for International Development and UNICEF through the Disaster Management UN Theme Group to discuss the course of outbreak and to coordinate the response.


Unzip the distribution archive to a directory of your choice for example:
C:\App\jasperstarter
Add the directory
C:\App\jasperstarter\bin
to your user or system path variable
or simply use the setup.exe
Extract the distribution archive to a directory of your choice for example:
/opt/jasperstarter
Add the directory
/opt/jasperstarter/bin
to your user or system path.
For ArchLinux an AUR Package is available here: https://aur.archlinux.org/packages/jasperstarter
If you put the bin dir on the seach path, just type
$ jasperstarter
to invoke the program.
If not, you can use an absolute path. On Linux:
/opt/jasperstarter/bin/jasperstarter
and on Windows:
C:\App\jasperstarter\bin\jasperstarter.exe
if you followed the example in the install section.
If you have any problem with the binary or shell script or you need to specify some extra options to your java vm, you can invoke the program directly:
$ java -jar /opt/jasperstarter/lib/jasperstarter.jar
or
$ java -cp /opt/jasperstarter/lib/jasperstarter.jar de.cenote.jasperstarter.App
JasperReports know three types of files:
This file is an xml file that defines the report, You can create it by hand but usually you will use one of the nice available GUI tools.
This file is the result of compiling an .jrxml file.
This file is the result of running a report. The data which is retrieved from the defined datasource is filled in the compiled report and can be stored in a .jrprint file.
JasperStarter has some global options and commands. Every command can have it's own options.
You can get an overview if you invoke jasperstarter with -h which shows you the global options and the available commands.
$ jasperstarter -h usage: jasperstarter [-h] [--locale <lang>] [-v] [-V] <cmd> ... optional arguments: -h, --help show this help message and exit --locale <lang> set locale with two-letter ISO-639 code or a combination of ISO-639 and ISO-3166 like de_DE -v, --verbose display additional messages -V, --version display version information and exit commands: <cmd> type <cmd> -h to get help on command compile (cp) compile reports process (pr) view, print or export an existing report list_printers (printers,lpr) lists available printers list_parameters (params,lpa) list parameters from a given report
Every command has it's own help which can be invoked with <command> -h.
The command compile is for compiling one report or all reports in a directory. cp is an alias for compile.
$ jasperstarter cp -h usage: jasperstarter compile [-h] [-o <output>] <input> optional arguments: -h, --help show this help message and exit options: <input> input file (.jrxml) or directory -o <output> directory or basename of outputfile(s)
The command process is for processing a report. Thant means viewing, printing or exporting. pr is an alias for process.
$ jasperstarter pr -h usage: jasperstarter process [-h] -f <fmt> [<fmt> ...] [-o <output>] [-w] [-a [<filter>]] [-P <param> [<param> ...]] [-r [<resource>]] [-t <dstype>] [-H <dbhost>] [-u <dbuser>] [-p <dbpasswd>] [-n <dbname>] [--db-sid <sid>] [--db-port <port>] [--db-driver <name>] [--db-url <jdbcUrl>] [--jdbc-dir <dir>] [--data-file <file>] [--csv-first-row] [--csv-columns <list>] [--csv-record-del <delimiter>] [--csv-field-del <delimiter>] [--csv-charset <charset>] [--xml-xpath <xpath>] [--json-query <jsonquery>] [-N <printername>] [-d] [-s <reportname>] [-c <copies>] [--out-field-del <delimiter>] [--out-charset <charset>] <input> optional arguments: -h, --help show this help message and exit options: -f <fmt> [<fmt> ...] view, print, pdf, rtf, xls, xlsMeta, xlsx, docx, odt, ods, pptx, csv, csvMeta, html, xhtml, xml, jrprint <input> input file (.jrxml|.jasper|.jrprint) -o <output> directory or basename of outputfile(s) compile options: -w, --write-jasper write .jasper file to imput dir if jrxml is processed fill options: -a [<filter>] ask for report parameters. Filter: a, ae, u, ue, p, pe (see usage) -P <param> [<param> ...] report parameter: name=value [...] -r [<resource>] path to report resource dir or jar file. If <resource> is not given the input directory is used. datasource options: -t <dstype> datasource type: none, csv, xml, json, mysql, postgres, oracle, generic (jdbc) -H <dbhost> database host -u <dbuser> database user -p <dbpasswd> database password -n <dbname> database name --db-sid <sid> oracle sid --db-port <port> database port --db-driver <name> jdbc driver class name for use with type: generic --db-url <jdbcUrl> jdbc url without user, passwd with type:generic --jdbc-dir <dir> directory where jdbc driver jars are located. Defaults to ./jdbc --data-file <file> input file for file based datasource --csv-first-row first row contains column headers --csv-columns <list> Comma separated list of column names --csv-record-del <delimiter> CSV Record Delimiter - defaults to line.separator --csv-field-del <delimiter> CSV Field Delimiter - defaults to "," --csv-charset <charset> CSV charset - defaults to "utf-8" --xml-xpath <xpath> XPath for XML Datasource --json-query <jsonquery> JSON query string for JSON Datasource output options: -N <printername> name of printer -d show print dialog when printing -s <reportname> set internal report/document name when printing -c <copies> number of copies. Defaults to 1 --out-field-del <delimiter> Export CSV (Metadata) Field Delimiter - defaults to "," --out-charset <charset> Export CSV (Metadata) Charset - defaults to "utf- 8"
The command list_printers has no options. It lists the available printers on your system which can be used with optin -N of the command process. printers, lpr are aliases for list_printers.
The command list_parameters lists all user defined parameters of a given report. params, lpa are aliases for list_parameters.
$ jasperstarter params -h usage: jasperstarter list_parameters [-h] <input> optional arguments: -h, --help show this help message and exit options: <input> input file (.jrxml) or (.jasper)
The columns have the following meaning:
Example output:
$ jasperstarter params myreport.jasper P background java.awt.Image Background image P MyName java.lang.String Title of some component P MyDate java.util.Date
Every command, option or argument JasperStarter accepts can be stored in a file that can be additionally provided with the @ sign.
The file should contain one command/option/argument per line.
Example file (db.conf):
-t mysql -H localhost -n mydb -u volker
Example invocation with command file:
$ jasperstarter pr myreport -f view @db.conf
Attention! The command file should not contain any empty lines and just one linebreak with no spaces at the end of the file!
To process a report you must provide the process command pr which needs the following options:
on the type of the datasource.
All other options are optional.
For output -o see section "File Handling".
<input> is now just an argument. The order of options and this argument does not matter but an argument cannot be placed behind an option that takes a vague number of arguments by itself. These options are:
So the following statement will not work:
$ jasperstarter pr -f view myreport.jasper
But these will:
$ jasperstarter pr -f print pdf -d myreport.jasper $ jasperstarter pr -f view -t mysql myreport.jasper -H localhost -u myuser -n mydb
The easiest way to circumvent any problems regarding arguments is to always place <input> at the first position right behind the command as shown in the following examples.
The minimum options needed, to process a report with an empty datasource:
$ jasperstarter pr myreport.jasper -f view
The minimum options required to process a report that needs a database connection:
$ jasperstarter pr myreport.jasper -f pdf -t mysql -H localhost -n mydb -u appuser
You can fill a report at one time and view, print or export it at a later time.
Just fill one report:
$ jasperstarter pr myreport.jasper -f jrprint -t mysql -H localhost -n mydb -u appuser
View a previously filled report:
$ jasperstarter pr myreport.jrprint -f view
The CSV file charset defaults to UTF-8. Other common used charsets are cp1252 (Windows), ISO-8859-1 or ISO-8859-15 (Linux). You can specify the csv file charset with the --csv-charset parameter.
Records are usually delimited by a newline but this is not a must. The record delimiter defaults to the system line separator which is different depending on your operating system. If you use CSV files from other systems you must provide the correct line ending with the --csv-record-del parameter:
Fields can be delimited by any char and optionally be enclosed by quotation marks. The field delimiter defaults to ,
A simple example:
$ jasperstarter pr csv.jrxml -f view -t csv --data-file data.csv --csv-first-row
A more complex example:
$ jasperstarter pr csv.jrxml -f view -t csv --data-file data.csv \ --csv-columns Name,Phone --csv-record-del="\n" --csv-field-del="|" \ --csv-charset=cp1252
Report parameters can consist of several types (classes). JasperStarter can generally handle all classes that have a constructor of type String. Additionally JasperStarter has special handlers for some classes that have no constructor of type String or otherwiese need special handling. These are:
Multiple parameters can be separated by spaces. A parameter has the following form:
Replace name with the parameter name in your report. Parameter names are case sensitive !
The parameter type date accepts a date in ISO format in the form: YYYY-MM-DD
The parameter type locale may consist just of the two-letter ISO-639 language code or a combination of the two-letter ISO-639 language code and the two-letter ISO-3166 country code connected by an underscore. For example de or de_DE.
$ jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P CustomerNo=10 StartFrom=2012-10-01
A simple way of customizing a report is to provide a logo or background image as parameter. In the following example we use background as parameter name for the image:
Now you can process your report with JasperStarter:
$ jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P background=/tmp/mybackgroundimage.jpg
Particularly windows users may need to work with spaces in file names. There are two ways you can do that. Just quote the value:
c:\jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P background="C:\Temp Files\My Image.jpg" otherValue=1
or quote the whole parameter:
c:\jasperstarter pr report.jasper -t mysql -u myuser -f pdf -H myhost -n mydb \ -o report -p secret -P "background=C:\Temp Files\My Image.jpg" otherValue=1
JasperStarter can ask for parameter input with option -a.
Every parameter defined in the report can be displayed but only those are supported for input, that have a type (class) with a constructor that takes one string as an argument or there is a special handler implemented for it.
It is possible to filter the displayed parameters with the following optional arguments:
In the following examples we assume a non database report which has two parameters:
The user will be prompted for the two parameters:
$ jasperstarter pr myreport.jasper -f view -a
The user will be prompted for the two parameters. The MyDate parameter is already filled but the user can change it:
$ jasperstarter pr myreport.jasper -f view -P MyDate=2013-01-30 -a
The user will be prompted only for the empty MyText parameter. The MyDate parameter is already filled and not displayed:
$ jasperstarter pr myreport.jasper -f view -P MyDate=2013-01-30 -a pe
Reports can use several resources like i18n resource bundles, icons, images or (compiled) subreports.
If a resource exists in the same directory as the report file just specify -r without any arguments:
$ jasperstarter pr myreport.jasper -f view -r
If the resource is located in another directory or in a jar file the path can be given as an argument:
$ jasperstarter pr myreport.jasper -f view -r myresources/
or
$ jasperstarter pr myreport.jasper -f view -r myresources.jar
The standard export to csv (xls, xlsx, ods) depends on layout and produces unexpected results most time. The solution to this is, at least for csv and xls, using metadata which clearly define which data is exported and how. This metadata must be added to the report definition jrxml.
See http://jasperreports.sourceforge.net/sample.reference/jasper/#csvmetadataexport and http://jasperreports.sourceforge.net/sample.reference/jasper/#xlsmetadataexport
Additionaly use the format -f csvMeta instead of -f csv or -f xlsMeta instead of -f xls with JasperStarter. Have a look at the example section at the end of this file.
Using subreports with JasperStarter can be a bit tricky and has some limitations. You have to use the datasource form the main report in the subreport which can be referenced with $P{REPORT_DATA_SOURCE}. It could be also a good idea to clone the datasource.
The subreport must be compiled before you can use it. It must be referenced with file ending .jasper. The path to the subreport must be provided as a resource with option -r.
<subreportExpression><![CDATA["mysubreport.jasper"]]></subreportExpression>
This is a complete example subreport element using clone and a relative path to the subreport. Keep in mind to replace the data source class with the one you are using.
<subreport isUsingCache="false"> <reportElement x="0" y="0" width="500" height="800"/> <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRBeanCollectionDataSource) $P{REPORT_DATA_SOURCE}).cloneDataSource()]]></dataSourceExpression> <subreportExpression><![CDATA["subdir/mysubreport.jasper"]]></subreportExpression> </subreport>
A user of JasperStarter has written a nice tutorial for a subreport with XML datasource here: http://nblock.org/2015/06/02/processing-jasper-subreports-with-jasperstarter/
The example report from this tutorial is included in the JasperStarter example directory. See main.jrxml_header.jrxml_details.jrxml
If the input file (option -i ) is not found, .jasper is added to the filename first, if the file is still not found .jrxml is added to the filename. So you can omit the file extension.
If the .jrxml file is used, it will be compiled in memory and used for further processing except you provide option -w which causes the compiled report to be written to the input directory.
A .jrprint file can be used as input but must specified with full filename.
If the output file or directory ( option -o ) is omitted, parent of the input file is used as output directory and the basename of the input file is used for as output filename:
(...) myreports/report1 -f pdf odt
or
(...) myreports/report1.jasper -f pdf odt
or
(...) myreports/report1.jrxml -f pdf odt
results in:
myreports/report1.odt myreports/report1.pdf
If output is an existing directory, basename of input is used as filename in that directory:
(...) myreports/report1.jasper -f pdf odt -o month01/
results in:
month01/report1.odt month01/report1.pdf
If output is NOT an existing directory, its name is used as basename for filenames:
(...) myreports/report1.jasper -f pdf odt -o month01/journal.xyz
results in:
month01/journal.xyz.odt month01/journal.xyz.pdf
There are several example reports provided whithin the JasperStarter distribution. They can be found in the examples folder.
For the following examples cd into the examples folder and execute the commands as described.
List of example files:
Blank_A4_1.jasper Blank_A4_1.jrxml CancelAck.jrxml CancelAck.xml charactersetTest.jasper charactersetTest.jrxml charactersetTestWithStudioBuiltinFunctions.jrxml contacts.json contacts.xml csv.jrxml csvExampleHeaders.csv csvMeta.jrxml details.jasper details.jrxml header.jasper header.jrxml i18n-bundle.properties i18n-bundle_de.properties i18n-bundle_ru.properties json.jrxml main.jrxml noDB-i18n.jrxml noDB-params.jrxml
A simple report whithout any datasource (just static text) showing different character sets. To view this report type:
$ jasperstarter pr charactersetTest.jrxml -f view
To get a pdf from this report type:
$ jasperstarter pr charactersetTest.jrxml -f pdf
Viewing the pdf you will miss the foreign characters as long as you did not provide the Arial font as a resouce. See Unicode PDF export
To view the report type:
$ jasperstarter pr csv.jrxml -f view -t csv --data-file csvExampleHeaders.csv --csv-first-row --csv-field-del "|"
To export the report to csv type:
$ jasperstarter pr csv.jrxml -f csv -t csv --data-file csvExampleHeaders.csv --csv-first-row --csv-field-del "|" --out-field-del "|"
To export the report to xls type:
$ jasperstarter pr csv.jrxml -f xsl -t csv --data-file csvExampleHeaders.csv --csv-first-row --csv-field-del "|"
The results are probably not what you expect. The csv data depends on the layout of the report and may be not row by row. See csv.csv. The xls export tries to mimic the print layout which is not useful if you want to post process the data in Excel.
This is an example report for exporting csv or xls with the help of metadata. Don't get confused by the fact that the report uses a csv file as datasource. The output of the export should result in a file named csvMeta.csv or csvMeta.xls depending on -f.
To just view the report type:
$ jasperstarter pr csvMeta.jrxml -f view -t csv --data-file csvExampleHeaders.csv --csv-first-row --csv-field-del "|"
To make the csv metadata export type:
$ jasperstarter pr csvMeta.jrxml -f csvMeta -t csv --data-file csvExampleHeaders.csv --csv-first-row --csv-field-del "|" --out-field-del "|"
The input and output files should only differ in line ending depending on your operating system.
$ diff -yW140 --ignore-all-space csvExampleHeaders.csv csvMeta.csv
To make the xls metadata export type:
$ jasperstarter pr csvMeta.jrxml -f xlsMeta -t csv --data-file csvExampleHeaders.csv --csv-first-row --csv-field-del "|"
To have an idea on how to add metadata to your report just take a look on csv.jrxml and csvMeta.jrxml. They mainly differ in the added metadata, the order of the fields and a fixed string.
This is a report with a xml datasource. To view it type:
$ jasperstarter pr CancelAck.jrxml -f view -t xml --xml-xpath /CancelResponse/CancelResult/ID --data-file CancelAck.xml
This is a report with a json datasource. To view it type:
$ jasperstarter pr json.jrxml -f view -t json --json-query contacts.person --data-file contacts.json
This is a localized report. To start with the defaults just type:
$ jasperstarter pr noDB-i18n.jrxml -f view
To start explicit with german localisation you have three options. The first and the second option change the locale of the user interface too:
Change the locale of the environment (Unix)
$ LANG=de_DE.UTF-8 jasperstarter pr noDB-i18n.jrxml -f view
Provide the locale parameter:
$ jasperstarter --locale de_DE pr noDB-i18n.jrxml -f view
Provide the build in report parameter REPORT_LOCALE. This changes only the locale inside the report but the UI remains in the default locale (your systems locale):
$ jasperstarter pr noDB-i18n.jrxml -f view -P REPORT_LOCALE=de_DE
Same with russian localisation:
$ jasperstarter pr noDB-i18n.jrxml -f view -P REPORT_LOCALE=ru
This report accepts parameters. If you don't provide a parameter the report can be shown but the values are empty:
$ jasperstarter pr noDB-params.jrxml -f view
To get a list of possible parameters type:
$ jasperstarter lpa noDB-params.jrxml
Let JasperStarter ask you for the Parameters:
$ jasperstarter pr noDB-params.jrxml -f view -a
Provide one or more parameters on command line (Parameter names are case sensitive):
$ jasperstarter pr noDB-params.jrxml -f view -P myString="My first Parameter" myInt=5
Provide a parameter on command line as a default but ask the user for all parameters:
$ jasperstarter pr noDB-params.jrxml -f view -P myString="My first Parameter" -a
Provide a parameter on the command line and ask the user only for the remaining empty ones:
$ jasperstarter pr noDB-params.jrxml -f view -P myString="My first Parameter" -a pe
The main report references two subreports. The subreports must be compiled, the main report not:
$ jasperstarter cp header.jrxml $ jasperstarter cp details.jrxml $ jasperstarter pr main.jrxml -f view -t xml --xml-xpath=/ --data-file contacts.xml -r .
See http://nblock.org/2015/06/02/processing-jasper-subreports-with-jasperstarter/


teaspoon package¶
teaspoon module¶
Initialize teaspoon module
-
teaspoon.
ts_to_labels
(_ts, _n, col=None)[source]¶ Convert a time series iterable into a set of features and labels ready for training.
- Parameters
_ts (array-like) – time series to be used for training.
_n (int) – number of step features for each label.
col (any) – column identifier for dataframe time series, in case only a subsection of it will be used for training.
-
teaspoon.
append_window
(_w, _x, _y, _n, col=None)[source]¶ Helper function to append the features and labels from a time series rolling window into a feature and label array.
- Parameters
_w (pd.DataFrame or pd.Series) – time series data window element of the .rolling(_n+1) method.
_x (list) – feature list to append features to.
_y (list) – feature list to append features to.
_n (int) – number of step features for each label.
col (any) – column identifier for dataframe time series, in case only a subsection of it will be used for training.
-
class
teaspoon.
UTSP
(model, n)[source]¶ Bases:
teaspoon.teaspoon._TSP
Univarate Time Series Prediction model.
This is used to predict the next step given a one-dimentional array.
- Variables
_n (int) – how many past steps considered for predicting the next.
-
class
teaspoon.
MTSP
(model, n, col, submodels=None, n_jobs=1)[source]¶ Bases:
teaspoon.teaspoon._TSP
Multivariate Time Series Prediction models.
These models are highly flexible ways of predicting future values based on a 2D aray of last steps over multiple features. While this feature is commonly used to look a single step ahead, users can specify more granularly how each step variable on a step ahead should be predicted.
- Variables
_n (int) – number of steps before used to predict a step ahead.
_col (str) – column this model tried to predict.
_submodels (dict) – dictionary of submodels used to predict a column’s value based on previous steps. These must be either USTP models for single columns or MTSP for multiple columns. This dictionary should have a tuple (multiple columns) or string (single column) as keys and _TSP instances as values.
_min_cols (list) – all columns specified by the initialization.
n_jobs (int) – number of jobs to run for fiting and predicting.
-
fit
(_ts, *args, **kwargs)[source]¶ Fit model from data.
- Parameters
_ts (array-like) – time series data used to fit the model.
-
property
n_jobs
¶ Get n_jobs attribute


I am experienced in solving a lot of tough problems and look forward to face a tough problem with a proper system and a cup full of hot coffee.
Working in a Finance Industry is tough where technology is on a downside using MVC, AngularJs, Angular 2 into the picture to reduce server side hits and increasing the security in an application. Writing Complex Back end logics to handle reports and stored procedures to deliver invoices, statements on time has shown me how important backend is for the finance inductry.
Handled projects for Banks,Shopping sites,Malls etc and innovated various modules to ease the pain. Brought in latest technologies keeping user experience on the throne. Complex issues, Intergrating in a Tough UI and meeting the expectations of every client thought me each and every minute.
Apart from being a web developer, I enjoy most of my time being outdoors eating spicy food, photographing random people, listening to classic rock, going on long drives, playing PC games for hours and hours.
Experimenting with new technologies just to satisfy my inner demon. Love to stay different and mastering new technologies bring a sense of satisfaction and a smile in my face(very difficult for an introvert with a serious smile). Love to put on my earphones and let lose my coding skils on a daily basis.


Open a Modal panel via AJAX.
Open a Modal panel with an extra class 'large' on it.
#### Use cases Frequent uses of modal windows include: - Drawing attention to vital pieces of information. This use has been criticised as ineffective because users are bombarded with too many dialog boxes, and habituate to simply clicking "Close", "Cancel", or "OK" without reading or understanding the message.[3][4][5] - Blocking the application flow until information required to continue is entered, as for example a password in a login process. Another example are file dialogs to open and save files in an application. - Collecting application configuration options in a centralized dialog. In such cases, typically the changes are applied upon closing the dialog, and access to the application is disabled while the edits are being made. - Warning that the effects of the current action are not reversible. This is a frequent interaction pattern for modal dialogs, but it is also criticised by usability experts as being ineffective for its intended use (protection against errors in destructive actions) due to habituation. Actually making the action reversible (providing an "undo" option) is recommended instead.[1] *Source: Wikipedia


This software distribution comes with a small collection of programs for converting non-TIFF format images to TIFF and for manipulating and interrogating the contents of TIFF images. Several of these tools are useful in their own right. Many of them however are more intended to serve as programming examples for using the TIFF library.
| tiffgt | Display the contents of one or more TIFF images using OpenGL. The software makes extensive use of the TIFFRGBAImage facilities described elsewhere. |
| tiffsv | A program to save all or part of a screen dump on a Silicon Graphics system. As for tiffgt this code, while written to use the IRIS GL, can be easily tailored to other devices. |
| bmp2tiff | Convert BMP images to TIFF |
| fax2ps | Convert a Group 3- or Group 4- compressed TIFF to PostScript that is significantly more compressed than is generated by tiff2ps (unless tiff2ps writes PS Level II) |
| fax2tiff | Convert raw Group 3 or Group 4 facsimile data to TIFF |
| gif2tiff | A quick hack that converts GIF 87a format images to TIFF |
| pal2rgb | Convert a Palette-style image to a full color RGB image by applying the colormap |
| ppm2tiff | A quick hack that converts PPM format images to TIFF |
| ras2tiff | A quick hack that converts Sun rasterfile format images to TIFF -- it's less than complete |
| raw2tiff | Create a TIFF file from raw data |
| rgb2ycbcr | Convert an RGB, grayscale, or bilevel TIFF image to a YCbCr TIFF image; it's mainly provided for testing |
| sgi2tiff | A program to convert SGI image files to TIFF. This program is only useful on SGI machines as it uses -limage. |
| thumbnail | Copy a bilevel TIFF to one that includes 8-bit greyscale "thumbnail images" for each page; it is provided as an example of how one might use the SubIFD tag (and the library support for it) |
| tiff2bw | A simple program to convert a color image to grayscale |
| tiff2pdf | Convert TIFF images to PDF |
| tiff2ps | Convert TIFF images to PostScript |
| tiff2rgba | Convert a TIFF image to RGBA color space |
| tiffcmp | Compare the contents of two TIFF files (it does not check all the directory information, but does check all the data) |
| tiffcp | Copy, concatenate, and convert TIFF images (e.g. switching from Compression=5 to Compression=1) |
| tiffdither | Dither a b&w image into a bilevel image (suitable for use in creating fax files) |
| tiffdump | Display the verbatim contents of the TIFF directory in a file (it's very useful for debugging bogus files that you may get from someone that claims they support TIFF) |
| tiffinfo | Display information about one or more TIFF files. |
| tiffmedian | A version of Paul Heckbert's median cut program that reads an RGB TIFF image, and creates a TIFF palette file as a result; it's useful for converting full-color RGB images to 8-bit color for your friends that have cheapo 8-bit framebuffers. |
| tiffset | Set a field in a TIFF header |
| tiffsplit | Create one or more single-image files from a (possibly) multi-image file |
Check out the manual pages for details about the above programs.


Reading
Wait, the storage effect is often evolutionarily unstable? Yikes. (Snyder & Adler, 2011). Will have to read this more closely.
- Vasseur & Fox nice AD paper in
PNASAm Nat (Vasseur & Fox, 2011), ((One day Am Nat will finish registering the doi for these papers?))
Contrary to previous verbal arguments that suggest that character convergence leads to neutral stability, coadaptation of competing consumers always leads to stable coexistence. Furthermore, we show that incorporating costs of consuming or excreting excess nonlimiting nutrients selects for nutritionally balanced diets and so promotes character convergence.
Curious: phlyogenetic rate shifts in feeding in Homo genus: (Organ et. al. 2011). An unfamiliar approach to me. Nice time-calibrated mophological-character tree of humans though. Now if only PNAS would consider requiring treebase archiving…
Best meta-population dataset ever (Hanski, 2011)? Looks like a nice paper, can’t help feeling it would have huge impact if the data were made available. Without that, it’s a bit hard to judge.
Great arxiv paper on parallel computation to improve MCMC. Not the way I thought – independent samples rather than independent chains. Which I had a better grasp or more time to go through this. Also, Robert’s ABC critique paper is out (Robert et. al. 2011).
Also need to read (Liebhold & Bascompte, 2003)
Writing
Working on Evolution revisions…
Arithmetic
Bill got me started on automatic reporting from the clusters using some bash scripting. Still tweaking.
Jacob, P., Robert, C. P., & Smith, M. H. (2010). Using parallel computation to improve Independent Metropolis–Hastings based estimation, 19. Retrieved from https://arxiv.org/abs/1010.1595
References
Snyder R and Adler P (2011). “Coexistence And Coevolution in Fluctuating Environments: Can The Storage Effect Evolve?” The American Naturalist, 178. ISSN 00030147, http://dx.doi.org/10.1086/661905.
Vasseur D and Fox J (2011). “Adaptive Dynamics of Competition For Nutritionally Complementary Resources: Character Convergence, Displacement, And Parallelism.” The American Naturalist, 178. ISSN 00030147, http://dx.doi.org/10.1086/661896.
Organ C, Nunn C, Machanda Z and Wrangham R (2011). “Phylogenetic Rate Shifts in Feeding Time During The Evolution of Homo.” Proceedings of The National Academy of Sciences, 108. ISSN 0027-8424, http://dx.doi.org/10.1073/pnas.1107806108.
Hanski I (2011). “Inaugural Article: Eco-Evolutionary Spatial Dynamics in The Glanville Fritillary Butterfly.” Proceedings of The National Academy of Sciences, 108. ISSN 0027-8424, http://dx.doi.org/10.1073/pnas.1110020108.
Robert C, Cornuet J, Marin J and Pillai N (2011). “Lack of Confidence in Approximate Bayesian Computation Model Choice.” Proceedings of The National Academy of Sciences, 108. ISSN 0027-8424, http://dx.doi.org/10.1073/pnas.1102900108.
Liebhold A and Bascompte J (2003). “The Allee Effect, Stochastic Dynamics And The Eradication of Alien Species.” Ecology Letters, 6. ISSN 1461-023X, http://dx.doi.org/10.1046/j.1461-0248.2003.00405.x.


 Follow along with this tutorial and you'll be on your way in no time.
The tutorial assumes at least an intermediate level of knowledge of JavaScript.
You can first play the game or jump directly to the article and view the source code for the game.
In order to draw things, we'll need to create a canvas. Because this is a No Tears guide we'll be using jQuery.
var CANVAS_WIDTH = 480; var CANVAS_HEIGHT = 320; var canvasElement = $("<canvas width='" + CANVAS_WIDTH + "' height='" + CANVAS_HEIGHT + "'></canvas>"); var canvas = canvasElement.get(0).getContext("2d"); canvasElement.appendTo('body');
In order to simulate the appearance of smooth and continuous gameplay, we want to update the game and redraw the screen just faster than the human mind and eye can perceive.
var FPS = 30; setInterval(function() { update(); draw(); }, 1000/FPS);
For now we can leave the update and draw methods blank. The important thing
to know is that setInterval()
takes care of calling them periodically.
function update() { ... } function draw() { ... }
Now that we have a game loop going, let's update our draw method to actually draw some text on the screen.
function draw() { canvas.fillStyle = "#000"; // Set color to black canvas.fillText("Sup Bro!", 50, 50); }
Pro Tip: Be sure to run your app after making changes. If something breaks it's a lot easier to track down when there's only a few lines of changes to look at.
That's pretty cool for stationary text, but because we have a game loop already set up, we should be able to make it move quite easily.
var textX = 50; var textY = 50; function update() { textX += 1; textY += 1; } function draw() { canvas.fillStyle = "#000"; canvas.fillText("Sup Bro!", textX, textY); }
Now give that a whirl. If you're following along, it should be moving, but also leaving the previous times it was drawn on the screen. Take a moment to guess why that may be the case. This is because we are not clearing the screen. So let's add some screen clearing code to the draw method.
function draw() { canvas.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); canvas.fillStyle = "#000"; canvas.fillText("Sup Bro!", textX, textY); }
Now that you've got some text moving around on the screen, you're halfway to having a real game. Just tighten up the controls, improve the gameplay, touch up the graphics.... Ok maybe 1/7th of the way to having a real game, but the good news is that there's much more to the tutorial.
Create an object to hold the player data and be responsible for things like drawing. Here we create a player object using a simple object literal to hold all the info.
var player = { color: "#00A", x: 220, y: 270, width: 32, height: 32, draw: function() { canvas.fillStyle = this.color; canvas.fillRect(this.x, this.y, this.width, this.height); } };
We're using a simple colored rectangle to represent the player for now. When we draw the game, we'll clear the canvas and draw the player.
function draw() { canvas.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT); player.draw(); }
The jQuery Hotkeys plugin makes key handling across browsers much much easier.
Rather than crying over indecipherable cross-browser keyCode
and
charCode
issues, we can bind events like so:
$(document).bind("keydown", "left", function() { ... });
Not having to worry about the details of which keys have which codes is a big win. We just want to be able to say things like "when the player presse the up button, do something." jQuery Hotkeys allows that nicely.
The way JavaScript handles keyboard events is completely event driven. That means that there is no built in query for checking whether a key is down, so we'll have to use our own.
You may be asking, "Why not just use an event-driven way of handling keys?" Well, it's because the keyboard repeat rate varies across systems and is not bound to the timing of the game loop, so gameplay could vary greatly from system to system. To create a consistent experience, it is important to have the keyboard event detection tightly integrated with the game loop.
The good news is that I've included a 16-line JS wrapper that will make event
querying available. It's called key_status.js and you can query the status of a
key at any time by checking keydown.left
, etc.
Now that we have the ability to query whether keys are down, we can use this simple update method to move the player around.
function update() { if (keydown.left) { player.x -= 2; } if (keydown.right) { player.x += 2; } }
Go ahead and give it a whirl.
You might notice that the player is able to be moved off of the screen. Let's clamp the player's position to keep them within the bounds. Additionally, the player seems kind of slow, so let's bump up the speed, too.
function update() { if (keydown.left) { player.x -= 5; } if (keydown.right) { player.x += 5; } player.x = player.x.clamp(0, CANVAS_WIDTH - player.width); }
Adding more inputs will be just as easy, so let's add some sort of projectiles.
function update() { if (keydown.space) { player.shoot(); } if (keydown.left) { player.x -= 5; } if (keydown.right) { player.x += 5; } player.x = player.x.clamp(0, CANVAS_WIDTH - player.width); } player.shoot = function() { console.log("Pew pew"); // :) Well at least adding the key binding was easy... };
Let's now add the projectiles for real. First, we need a collection to store them all in:
var playerBullets = [];
Next, we need a constructor to create bullet instances.
function Bullet(I) { I.active = true; I.xVelocity = 0; I.yVelocity = -I.speed; I.width = 3; I.height = 3; I.color = "#000"; I.inBounds = function() { return I.x >= 0 && I.x <= CANVAS_WIDTH && I.y >= 0 && I.y <= CANVAS_HEIGHT; }; I.draw = function() { canvas.fillStyle = this.color; canvas.fillRect(this.x, this.y, this.width, this.height); }; I.update = function() { I.x += I.xVelocity; I.y += I.yVelocity; I.active = I.active && I.inBounds(); }; return I; }
When the player shoots, we should create a bullet instance and add it to the collection of bullets.
player.shoot = function() { var bulletPosition = this.midpoint(); playerBullets.push(Bullet({ speed: 5, x: bulletPosition.x, y: bulletPosition.y })); }; player.midpoint = function() { return { x: this.x + this.width/2, y: this.y + this.height/2 }; };
We now need to add the updating of the bullets to the update step function. To prevent the collection of bullets from filling up indefinitely, we filter the list of bullets to only include the active bullets. This also allows us to remove bullets that have collided with an enemy.
function update() { ... playerBullets.forEach(function(bullet) { bullet.update(); }); playerBullets = playerBullets.filter(function(bullet) { return bullet.active; }); }
The final step is to draw the bullets:
function draw() { ... playerBullets.forEach(function(bullet) { bullet.draw(); }); }
Now it's time to add enemies in much the same way as we added the bullets.
enemies = []; function Enemy(I) { I = I || {}; I.active = true; I.age = Math.floor(Math.random() * 128); I.color = "#A2B"; I.x = CANVAS_WIDTH / 4 + Math.random() * CANVAS_WIDTH / 2; I.y = 0; I.xVelocity = 0 I.yVelocity = 2; I.width = 32; I.height = 32; I.inBounds = function() { return I.x >= 0 && I.x <= CANVAS_WIDTH && I.y >= 0 && I.y <= CANVAS_HEIGHT; }; I.draw = function() { canvas.fillStyle = this.color; canvas.fillRect(this.x, this.y, this.width, this.height); }; I.update = function() { I.x += I.xVelocity; I.y += I.yVelocity; I.xVelocity = 3 * Math.sin(I.age * Math.PI / 64); I.age++; I.active = I.active && I.inBounds(); }; return I; }; function update() { ... enemies.forEach(function(enemy) { enemy.update(); }); enemies = enemies.filter(function(enemy) { return enemy.active; }); if(Math.random() < 0.1) { enemies.push(Enemy()); } }; function draw() { ... enemies.forEach(function(enemy) { enemy.draw(); }); }
It's cool watching all those boxes flying around, but having images for them would be even cooler. Loading and drawing images on canvas is usually a tearful experience. To prevent that pain and misery, we can use a simple utility class.
player.sprite = Sprite("player"); player.draw = function() { this.sprite.draw(canvas, this.x, this.y); }; function Enemy(I) { ... I.sprite = Sprite("enemy"); I.draw = function() { this.sprite.draw(canvas, this.x, this.y); }; ... }
We've got all these dealies flying around on the screen, but they're not interacting with each other. In order to let everything know when to blow up, we'll need to add some sort of collision detection.
Let's use a simple rectangular collision detection algorithm:
function collides(a, b) { return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y; }
There are a couple collisions we want to check:
Let's make a method to handle the collisions which we can call from the update method.
function handleCollisions() { playerBullets.forEach(function(bullet) { enemies.forEach(function(enemy) { if (collides(bullet, enemy)) { enemy.explode(); bullet.active = false; } }); }); enemies.forEach(function(enemy) { if (collides(enemy, player)) { enemy.explode(); player.explode(); } }); } function update() { ... handleCollisions(); }
Now we need to add the explode methods to the player and the enemies. This will flag them for removal and add an explosion.
function Enemy(I) { ... I.explode = function() { this.active = false; // Extra Credit: Add an explosion graphic }; return I; }; player.explode = function() { this.active = false; // Extra Credit: Add an explosion graphic and then end the game };
To round out the experience, we're going to add some sweet sound effects. Sounds, like images, can be somewhat of a pain to use in HTML5, but thanks to our magic no-tears formula sound.js, sound can be made super-simple.
player.shoot = function() { Sound.play("shoot"); ... } function Enemy(I) { ... I.explode = function() { Sound.play("explode"); ... } }
Though the API is now tear-free, adding sounds is currently the quickest way to crash your application. It's not uncommon for sounds to cut-out or take down the entire browser tab, so get your tissues ready.
Again, here is the full working game demo. You can download the source code as a zip, too.
Well, I hope you enjoyed learning the basics of making a simple game in JavaScript and HTML5. By programming at the right level of abstraction, we can insulate ourselves from the more difficult parts of the APIs, as well as be resilient in the face of future changes.


--- layout: post title: Five Great Conferences for Teachers in 2012 date: 2012-03-18 05:48:39.000000000 -07:00 type: post parent_id: '0' published: true pd: '' status: publish categories: - Classroom Talk - Guest Posts tags: - 2012 teacher conferences - ideas for parents and teachers - learning and the brain - Teacher Conferences - technology and education author: login: k email: k@k display_name: mcary first_name: '' last_name: '' ---
Guest Post by Mary Ellen Ellis
Attending conferences is a vital part of professional development for educators. At conferences, you have the opportunity to learn new ways to become a better teacher and to confer with colleagues whom you normally never see from the seclusion of your classroom. There are so many meetings for professional educators, that the choice of which to attend can be overwhelming. Here are five that will surely not disappoint. They run the gamut from technology to neuroscience and neuroscience to online learning.
The Creativity Workshop – New York, June 8 – 11 and August 17 – 20
The Creativity Workshop is a unique type of conference targeted at educators. It is designed to help teachers develop creativity in themselves and in their students. The organization was founded in 1993 and takes its conference around the world to inspire thousands of educators. Through exercises, they stimulate creative thinking to help teachers bring this spark to their math, science, writing, literature, social studies, and art lessons. Attendees also have the chance to earn credits from the University of Iowa.
Learning and the Brain – New York, April 19 and Arlington, VA, May 4 – 6
Teachers can benefit greatly from understanding how the brain works with respect to learning. The group called Learning and the Brain provides connections between educators and neuroscience researchers. They hold conferences for teachers to get up to date on the research that can increase the understanding of the role the brain plays in learning and teaching. The April conference focuses on emotions and how to utilize them to improve student engagement. The conference in May is about the research into technology and how it affects the brain.
32nd International Conference on Critical Thinking – Berkeley, CA, July 23 – 26
Teaching students to think critically is an essential part of education. Unfortunately, it is often overlooked as educators struggle to teach all the concepts required for a standardized test. The Center for Critical Thinking holds an annual conference designed to help teachers bring this important skill back into the classroom.
18th Annual Sloan Consortium international Conference on Online Learning – Lake Buena Vista, FL, October 10 – 12
The Sloan Consortium is an organization for professional leadership that is dedicated to improving the quality of online education. Learning online is a relatively new concept, but more and more schools are using online programs to help students with varying needs succeed and learn.  This conference is a great way to delve into the world of online learning.
International Society for Technology in Education – San Diego, June 24 – 27
The ISTE annual conference is a great place for educators to convene and discuss the role and use of technology in learning. Using technology in the classroom is on the rise and changes every day. Teachers must keep up to date with these changes to provide the best learning environment for their students. ISTE brings together the leaders in technology education to provide the most current information and research.
Mary Ellen Ellis is a science teacher who writes for Teacher Certification Degrees, a teaching career site providing information on how to become a teacher in your state, education degree programs by state, and interviews with teachers.


This is a simple layout widget, which initially create four equal boxes which can the be resized
fourWayDragger({ dragContainer:"#four-way-drag-panel", dragPanelsWrapper:".four-way", dragBar:'#resize-handle-4', dragPanel1:'#pane-4-1', dragPanel2:'#pane-4-2', dragPanel3:'#pane-4-3', dragPanel4:{ selector:'#pane-4-4', innerContent:`
Panel 4

 def print_hi(name)  puts "Hi, #{name}" end  print_hi('Tom') #=> prints 'Hi, Tom' to STDOUT.

`, bgColor:randomColor() }, dragShield:"#drag-shield" });
What we're going to do is use JavaScript to calculatefixpoints of innerHTML parse and reparsing. We start with
an input value, encoded in a JavaScript string.
x.innerHTML = input
We then snapshot the DOM state of x, and then perform the iteration:
intermediate = x.innerHTML
x.innerHTML = intermediate
What inputs are we going to test? We will generate using the following alphabet:
a01~!@#$%^&*()_+`-=[]\{}|;':",./<>? (and


BattleShip
Shoot down all 4 ships within 20 shots
Ship`s Status
- Carrier [5 blocks] :{{carrierStatus}}
- Battleship [4 blocks] : {{battleshipStatus}}
- Submarine [3 blocks] : {{submarineStatus}}
- Destroyer [2 blocks] : {{destroyerStatus}}
Shots Left : {{shotsLeft}}


Audioscrobbler support in Synergy?
-
neilio
I can't remember if I've asked for this or not, but it would be smashing to have the ability to send recently played tracks from Synergy to the Audioscrobbler service.
It's based on HTTP and looks really straight-forward.
http://www.audioscrobbler.com/development/protocol.php
This would be very, very cool. For those of you who don't know what Audioscrobbler is, it is a system which tracks the music you play. You can then see a bunch of information about the tracks you've played (most played artists, songs, etc.) as well as share with others what you're listening to. It's open source and not affiliated with any labels or anything nefarious like that.
Audioscrobbler is like what del.icio.us is, except you share your musical tastes rather than bookmarks.
The best thing is that as you build a profile of the music you listen to, it gets synced up with the streaming radio site last.fm. This site allows you to listen to a personalized playlist with music that the system thinks you will like, based on what you've listened to in the past.
Please, could this be integrated into Synergy?
-
anonymous
I create a feature request for this.
[Edited to fix the hyperlink]
Reply
This topic is now closed.