OKlibrary  0.2.1.6
Traits_Variables.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 18.8.2003 (Swansea)
00002 /* Copyright 2003 - 2007 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00008 #ifndef TRAITSVARIABLESWAECHTER_jakjdkfjt52190
00009 
00010 #define TRAITSVARIABLESWAECHTER_jakjdkfjt52190
00011 
00012 #include <exception>
00013 #include <stdexcept>
00014 #include <string>
00015 
00016 
00017 namespace Error_Variables {
00018 
00019   struct Basis_Variables_Error {};
00020  
00021   struct CapacityOverflow : std::runtime_error, virtual Basis_Variables_Error {
00022     explicit CapacityOverflow(const std::string& what) : runtime_error(what) {}
00023   };
00024 
00025   struct InvalidName : std::runtime_error, virtual Basis_Variables_Error {
00026     explicit InvalidName(const std::string& what) : runtime_error(what) {}
00027   };
00028 
00029 }
00030 
00031 
00032 namespace Traits_Variables {
00033 
00034   struct ThrowsTotalCapacityOverflow {};
00035   struct DoesntThrowTotalCapacityOverflow {};
00036 
00037   struct ThrowsInvalidName {};
00038   struct NoInvalidNames {};
00039 
00040   struct GeneralNames {};
00041   // for GeneralNames the name type should neither be integral nor string
00042   struct SpecialNames : virtual GeneralNames {};
00043   struct NaturalNumberConvertibleName : virtual SpecialNames {};
00044   struct StringConvertibleName : virtual SpecialNames, virtual NoInvalidNames {};
00045 
00046   struct ComparisonDifferentDomainsUndefinedBehaviour {};
00047   struct ComparisonDifferentDomainsImplementationDefined : virtual ComparisonDifferentDomainsUndefinedBehaviour {};
00048   // this is the common base type of the two following types (comparison of variables from different domains results in implementation defined behaviour):
00049   struct LocalDomainsIdentified : virtual ComparisonDifferentDomainsImplementationDefined {};
00050   // only for LocalDomainsIdentified comparison of variables created from different domains has the expected behaviour
00051   struct OneGlobalDomain : virtual ComparisonDifferentDomainsUndefinedBehaviour {};
00052   // here variables created by different domains, but with the same name are equal.
00053 
00054   struct AllocationBehaviour {};
00055   struct AllocationCausesInvalidation : virtual AllocationBehaviour {};
00056   struct SafeAllocation : virtual AllocationBehaviour {};
00057 
00058   struct OrderImplementationDefined {};
00059   struct OrderNameInherited : virtual OrderImplementationDefined {};
00060   struct OrderByCreation : virtual OrderImplementationDefined {};
00061 
00062   struct SizeBehaviour {};
00063   struct NaturalSize : virtual SizeBehaviour {};
00064   struct SizeNameRelated : virtual SizeBehaviour {};
00065   struct SizeIndexRelated : virtual SizeNameRelated {};
00066   
00067 
00068   // Consider a variable domain type VarD and objects D, D1, D2 of type VarD:
00069 
00070   // If MetaData<VarD>::comparison_property is just ComparisonDifferentDomainsUndefinedBehaviour, then comparing variables (via == or <) from D1 and D2 results in undefined behaviour; if it is ComparisonDifferentDomainsImplementationDefined then comparing variables from different domains results in implementation defined behaviour. If comparison_property is one of the two derived types, then the behaviour is defined as follows://
00071   // If comparison_property is LocalDomainsIdentified, then in case of name1 != NameType() we always have
00072   // D1(name1) != D2(name2),
00073   // while if comparison_property is OneGlobalDomain, then we have
00074   // D1(name1) == D2(name2) iff name1 == name2.
00075   // W.r.t. comparing via < comparing variables from different domains results in implementation-defined behaviour, except of the case where MetaData<VarD>::order_property is OrderNameInherited.
00076 
00077   // If MetaData<VarD>::allocation_property is AllocationCausesInvalidation, then a call of D(name) with name != NameType() may cause reallocation, and thus invalidates all existing variables (and iterators), if there has not been a sufficient call to D.reserve() before:
00078   // Calling D.reserve(s) for an empty domain guarantees, that s-1 calls of D(name) can be done without reallocation.
00079   // If capacity() is available, then "reallocation" can be seen as equivalent to capacity() increasing its value.
00080 
00081   // If MetaData<VarD>::name_property is NaturalNumberConvertibleName, then VarD(int x) for x >= 0 is possible.
00082   // If MetaData<VarD>::name_property is StringConvertibleName, then VarD(std::string) is possible, and MetaData<VarD>::name_throw_property is NoInvalidNames.
00083 
00084   // If MetaData<VarD>::order_property is OrderNameInherited, then for variables v, w we have v < w iff D.name(v) < D.name(w) (provided v, w have been created by D).
00085   // If MetaData<VarD>::order_property is OrderByCreation, then for variables v, w we have v < w iff v has been created before w.
00086 
00087   // If VarD has size():
00088   // If MetaData<VarD>::size_property is NaturalSize, then creation of a new variable increases the size of the domain exactly by one; if it is SizeNameRelated, it may be larger (but never less), depending on the name (regarded as index); if it is SizeIndexRelated, then name_property must be NaturalNumberConvertibleName, and after creating a variable v with index i we have size() >= i+1.
00089 
00090   
00091 }
00092 
00093 #endif