* Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
75 lines
2.6 KiB
C++
75 lines
2.6 KiB
C++
/*
|
||
NULL-VALUE.hpp - maintain per-type NIL values in static memory
|
||
|
||
Copyright (C)
|
||
2010, Hermann Vosseler <Ichthyostega@web.de>
|
||
|
||
**Lumiera** is free software; you can redistribute it and/or modify it
|
||
under the terms of the GNU General Public License as published by the
|
||
Free Software Foundation; either version 2 of the License, or (at your
|
||
option) any later version. See the file COPYING for further details.
|
||
|
||
*/
|
||
|
||
|
||
/** @file null-value.hpp
|
||
** Singleton-style holder for \em NIL or \em default values.
|
||
** This template allows to maintain a "Null Object" value, with type-based access.
|
||
** It is implemented as a cluster of Meyer's Singletons, thus the creation happens
|
||
** on demand, and the destruction happens "sometime" during application shutdown.
|
||
** Contrary to the generic lumiera Singleton holder, this implementation is
|
||
** lightweight and without any further prerequisites and validity checks.
|
||
** @warning we can't make any assumptions regarding the exact time when the dtor
|
||
** is called, and it is even impossible to detect if this happened already.
|
||
** Any access after that point will use a defunct object, thus the user
|
||
** needs to assure this facility is *never used during application shutdown*
|
||
**
|
||
** # purpose of NIL objects
|
||
** Employing the NIL object pattern instead of NULL pointers typically leads to
|
||
** greatly simplified and more robust code. Usually the only problem is these NIL
|
||
** marker objects need to exist somewhere. In case no factory is used for object
|
||
** creation, this NullValue holder might satisfy this need.
|
||
**
|
||
** NIL objects are assumed to be default constructible for now. Initialisation
|
||
** may introduce a race, which is considered acceptable here, as these objects
|
||
** are assumed to be simple, constant and value-like.
|
||
**
|
||
** @note deliberately this template is an extension point for explicit specialisation
|
||
** @todo initialisation could be extended to use a free function to fabricate
|
||
** the NIL value object, so to support the special case of an NIL object
|
||
** not being default constructible
|
||
**
|
||
** @see null-value-test.cpp
|
||
** @see lib::advice::Request usage example
|
||
**
|
||
*/
|
||
|
||
|
||
|
||
#ifndef LIB_NULL_VALUE_H
|
||
#define LIB_NULL_VALUE_H
|
||
|
||
|
||
|
||
namespace lib {
|
||
|
||
/**
|
||
* Singleton holder for NIL or default value objects.
|
||
* Implemented as a cluster of Meyer's singletons, maintaining
|
||
* a single value per type. Specialisation is intended.
|
||
*/
|
||
template<class TY>
|
||
struct NullValue
|
||
{
|
||
static TY const&
|
||
get()
|
||
{
|
||
static TY nilValue;
|
||
return nilValue;
|
||
}
|
||
};
|
||
|
||
|
||
|
||
} // namespace lib
|
||
#endif
|