GteUIntegerAP32.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
11 #include <fstream>
12 #include <vector>
13 
14 // Class UIntegerAP32 is designed to support arbitrary precision arithmetic
15 // using BSNumber and BSRational. It is not a general-purpose class for
16 // arithmetic of unsigned integers.
17 
18 // Uncomment this to collect statistics on how large the UIntegerAP32 storage
19 // becomes when using it for the UIntegerType of BSNumber. After a sequence
20 // of BSNumber operations, look at UIntegerAP32::msMaxSize in the debugger
21 // watch window. If the number is not too large, you might be safe in
22 // replacing UIntegerAP32 by UIntegerFP32<N>, where N is the value of
23 // UIntegerAP32::msMaxSize. This leads to much faster code because you no
24 // you no longer have dynamic memory allocations and deallocations that occur
25 // regularly with std::vector<uint32_t> during BSNumber operations. A safer
26 // choice is to argue mathematically that the maximum size is bounded by N.
27 // This requires an analysis of how many bits of precision you need for the
28 // types of computation you perform. See class BSPrecision for code that
29 // allows you to compute maximum N.
30 //
31 //#define GTE_COLLECT_UINTEGERAP32_STATISTICS
32 
33 #if defined(GTE_COLLECT_UINTEGERAP32_STATISTICS)
35 #endif
36 
37 namespace gte
38 {
39 
40 class UIntegerAP32 : public UIntegerALU32<UIntegerAP32>
41 {
42 public:
43  // Construction.
44  UIntegerAP32();
45  UIntegerAP32(UIntegerAP32 const& number);
46  UIntegerAP32(uint32_t number);
47  UIntegerAP32(uint64_t number);
48  UIntegerAP32(int numBits);
49 
50  // Assignment.
51  UIntegerAP32& operator=(UIntegerAP32 const& number);
52 
53  // Support for std::move.
54  UIntegerAP32(UIntegerAP32&& number);
56 
57  // Member access.
58  void SetNumBits(uint32_t numBits);
59  inline int32_t GetNumBits() const;
60  inline std::vector<uint32_t> const& GetBits() const;
61  inline std::vector<uint32_t>& GetBits();
62  inline void SetBack(uint32_t value);
63  inline uint32_t GetBack() const;
64  inline int32_t GetSize() const;
65 
66  // Disk input/output. The fstream objects should be created using
67  // std::ios::binary. The return value is 'true' iff the operation
68  // was successful.
69  bool Write(std::ofstream& output) const;
70  bool Read(std::ifstream& input);
71 
72 private:
73  int32_t mNumBits;
74  std::vector<uint32_t> mBits;
75 
76  friend class UnitTestBSNumber;
77 
78 #if defined(GTE_COLLECT_UINTEGERAP32_STATISTICS)
79  static std::atomic<size_t> msMaxSize;
80 public:
81  static void SetMaxSizeToZero() { msMaxSize = 0; }
82  static size_t GetMaxSize() { return msMaxSize; }
83 #endif
84 };
85 
86 
87 inline int32_t UIntegerAP32::GetNumBits() const
88 {
89  return mNumBits;
90 }
91 
92 inline std::vector<uint32_t> const& UIntegerAP32::GetBits() const
93 {
94  return mBits;
95 }
96 
97 inline std::vector<uint32_t>& UIntegerAP32::GetBits()
98 {
99  return mBits;
100 }
101 
102 inline void UIntegerAP32::SetBack(uint32_t value)
103 {
104  mBits.back() = value;
105 }
106 
107 inline uint32_t UIntegerAP32::GetBack() const
108 {
109  return mBits.back();
110 }
111 
112 inline int32_t UIntegerAP32::GetSize() const
113 {
114  return static_cast<int32_t>(mBits.size());
115 }
116 
117 
118 }
std::vector< uint32_t > const & GetBits() const
void SetBack(uint32_t value)
std::vector< uint32_t > mBits
UIntegerAP32 & operator=(UIntegerAP32 const &number)
int32_t GetNumBits() const
void SetNumBits(uint32_t numBits)
GLsizei const GLfloat * value
Definition: glcorearb.h:819
bool Read(std::ifstream &input)
friend class UnitTestBSNumber
uint32_t GetBack() const
GLenum GLenum GLenum input
Definition: glext.h:9913
int32_t GetSize() const
bool Write(std::ofstream &output) const


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01