casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CompositeNumber.h
Go to the documentation of this file.
00001 //# CompositeNumber.h: generate a composite number
00002 //# Copyright (C) 2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: CompositeNumber.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_COMPOSITENUMBER_H
00029 #define CASA_COMPOSITENUMBER_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Containers/Block.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary> This class generates composite numbers </summary>
00038 // <use visibility=export>
00039 
00040 // <synopsis>
00041 // This class generates a list of composite numbers made up
00042 // of powers of 2, 3, and 5, which are less than
00043 // some max value and returns the smallest composite number greater
00044 // than some number given.
00045 // </synopsis>
00046 
00047 // <example>
00048 // <srcblock>
00049 // CompositeNumber cn(1000);
00050 // Int n = cn.nextLarger(319);
00051 // Int m = cn.nextSmaller(462);
00052 // Int l = cn.nearest(462);
00053 // </srcblock>
00054 // </example>
00055 
00056 
00057 class CompositeNumber
00058 {
00059 public:
00060   // constructor:
00061   // Note: if you later make a call with value > maxval, we
00062   // will recalculate the list of composite numbers
00063   CompositeNumber (const uInt maxval = 8192);
00064 
00065   // destructor
00066   ~CompositeNumber();
00067 
00068   // return the next larger composite number
00069   uInt nextLarger(const uInt value);
00070 
00071   // return the next smaller composite number
00072   uInt nextSmaller(const uInt value);
00073 
00074   // return the nearest composite number
00075   uInt nearest(const uInt value);
00076 
00077   // return the next larger even composite number
00078   uInt nextLargerEven(const uInt value);
00079 
00080   // return the next smaller even composite number
00081   uInt nextSmallerEven(const uInt value);
00082 
00083   // return the closest even composite number
00084   uInt nearestEven(const uInt value);
00085 
00086   // returns True is value is composite
00087   Bool isComposite(const uInt value);
00088 
00089  private:
00090 
00091   Block<uInt> itsNumbers;
00092   uInt         itsMaxComplete;
00093 
00094   void generate(const uInt maxval);
00095 
00096 };
00097 
00098 
00099 } //# NAMESPACE CASA - END
00100 
00101 #endif