activemq-cpp-3.6.0
Long.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _DECAF_LANG_LONG_H_
19 #define _DECAF_LANG_LONG_H_
20 
21 #include <decaf/lang/Number.h>
22 #include <decaf/lang/Comparable.h>
24 #include <string>
25 
26 namespace decaf{
27 namespace lang{
28 
29  class DECAF_API Long : public Number,
30  public Comparable<Long>,
31  public Comparable<long long> {
32  private:
33 
34  // The primitive long long value
35  long long value;
36 
37  public:
38 
40  static const int SIZE = 64;
41 
43  static const long long MAX_VALUE = (long long)0x7FFFFFFFFFFFFFFFLL;
44 
46  static const long long MIN_VALUE = (long long)0x8000000000000000LL;
47 
48  public:
49 
53  Long( long long value );
54 
65  Long( const std::string& value );
66 
67  virtual ~Long() {}
68 
77  virtual int compareTo( const Long& l ) const;
78 
83  bool equals( const Long& l ) const {
84  return this->value == l.value;
85  }
86 
92  virtual bool operator==( const Long& l ) const {
93  return this->value == l.value;
94  }
95 
102  virtual bool operator<( const Long& l ) const {
103  return this->value < l.value;
104  }
105 
114  virtual int compareTo( const long long& l ) const;
115 
120  bool equals( const long long& l ) const {
121  return this->value == l;
122  }
123 
129  virtual bool operator==( const long long& l ) const {
130  return this->value == l;
131  }
132 
139  virtual bool operator<( const long long& l ) const {
140  return this->value < l;
141  }
142 
146  std::string toString() const;
147 
152  virtual double doubleValue() const {
153  return (double)this->value;
154  }
155 
160  virtual float floatValue() const {
161  return (float)this->value;
162  }
163 
168  virtual unsigned char byteValue() const {
169  return (unsigned char)this->value;
170  }
171 
176  virtual short shortValue() const {
177  return (short)this->value;
178  }
179 
184  virtual int intValue() const {
185  return (int)this->value;
186  }
187 
192  virtual long long longValue() const {
193  return this->value;
194  }
195 
196  public:
197 
206  static int bitCount( long long value );
207 
223  static Long decode( const std::string& value );
224 
235  static long long highestOneBit( long long value );
236 
247  static long long lowestOneBit( long long value );
248 
266  static int numberOfLeadingZeros( long long value );
267 
278  static int numberOfTrailingZeros( long long value );
279 
293  static long long parseLong( const std::string& value );
294 
307  static long long parseLong( const std::string& value, int radix );
308 
315  static long long reverseBytes( long long value );
316 
323  static long long reverse( long long value );
324 
342  static long long rotateLeft( long long value, int distance );
343 
361  static long long rotateRight( long long value, int distance );
362 
370  static int signum( long long value );
371 
377  static std::string toString( long long value );
378 
379  /*
380  * Returns a string representation of the first argument in the radix
381  * specified by the second argument.
382  *
383  * If the radix is smaller than Character.MIN_RADIX or larger than
384  * Character.MAX_RADIX, then the radix 10 is used instead.
385  *
386  * If the first argument is negative, the first element of the result is
387  * the ASCII minus character '-'. If the first argument is not
388  * negative, no sign character appears in the result.
389  *
390  * The remaining characters of the result represent the magnitude of the
391  * first argument. If the magnitude is zero, it is represented by a single
392  * zero character '0'; otherwise, the first character of the
393  * representation of the magnitude will not be the zero character. The
394  * following ASCII characters are used as digits:
395  *
396  * 0123456789abcdefghijklmnopqrstuvwxyz
397  *
398  * @param value - the long long to convert to a string
399  * @param radix - the radix to format the string in
400  * @returns an long long formatted to the string value of the radix given.
401  */
402  static std::string toString( long long value, int radix );
403 
423  static std::string toHexString( long long value );
424 
443  static std::string toOctalString( long long value );
444 
460  static std::string toBinaryString( long long value );
461 
467  static Long valueOf( long long value ) {
468  return Long( value );
469  }
470 
481  static Long valueOf( const std::string& value );
482 
495  static Long valueOf( const std::string& value, int radix );
496 
497  private:
498 
499  static long long parse( const std::string& value, int offset,
500  int radix, bool negative );
501 
502  };
503 
504 }}
505 
506 #endif /*_DECAF_LANG_LONG_H_*/