activemq-cpp-3.8.2
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;
41 
43  static const long long MAX_VALUE;
44 
46  static const long long MIN_VALUE;
47 
48  public:
49 
53  Long(long long value);
54 
65  Long(const std::string& value);
66 
67  virtual ~Long() {
68  }
69 
78  virtual int compareTo(const Long& l) const;
79 
84  bool equals(const Long& l) const {
85  return this->value == l.value;
86  }
87 
93  virtual bool operator==(const Long& l) const {
94  return this->value == l.value;
95  }
96 
103  virtual bool operator<(const Long& l) const {
104  return this->value < l.value;
105  }
106 
115  virtual int compareTo(const long long& l) const;
116 
121  bool equals(const long long& l) const {
122  return this->value == l;
123  }
124 
130  virtual bool operator==(const long long& l) const {
131  return this->value == l;
132  }
133 
140  virtual bool operator<(const long long& l) const {
141  return this->value < l;
142  }
143 
147  std::string toString() const;
148 
153  virtual double doubleValue() const {
154  return (double) this->value;
155  }
156 
161  virtual float floatValue() const {
162  return (float) this->value;
163  }
164 
169  virtual unsigned char byteValue() const {
170  return (unsigned char) this->value;
171  }
172 
177  virtual short shortValue() const {
178  return (short) this->value;
179  }
180 
185  virtual int intValue() const {
186  return (int) this->value;
187  }
188 
193  virtual long long longValue() const {
194  return this->value;
195  }
196 
197  public:
198 
207  static int bitCount(long long value);
208 
224  static Long decode(const std::string& value);
225 
236  static long long highestOneBit(long long value);
237 
248  static long long lowestOneBit(long long value);
249 
267  static int numberOfLeadingZeros(long long value);
268 
279  static int numberOfTrailingZeros(long long value);
280 
294  static long long parseLong(const std::string& value);
295 
308  static long long parseLong(const std::string& value, int radix);
309 
316  static long long reverseBytes(long long value);
317 
324  static long long reverse(long long value);
325 
343  static long long rotateLeft(long long value, int distance);
344 
362  static long long rotateRight(long long value, int distance);
363 
371  static int signum(long long value);
372 
378  static std::string toString(long long value);
379 
380  /*
381  * Returns a string representation of the first argument in the radix
382  * specified by the second argument.
383  *
384  * If the radix is smaller than Character.MIN_RADIX or larger than
385  * Character.MAX_RADIX, then the radix 10 is used instead.
386  *
387  * If the first argument is negative, the first element of the result is
388  * the ASCII minus character '-'. If the first argument is not
389  * negative, no sign character appears in the result.
390  *
391  * The remaining characters of the result represent the magnitude of the
392  * first argument. If the magnitude is zero, it is represented by a single
393  * zero character '0'; otherwise, the first character of the
394  * representation of the magnitude will not be the zero character. The
395  * following ASCII characters are used as digits:
396  *
397  * 0123456789abcdefghijklmnopqrstuvwxyz
398  *
399  * @param value - the long long to convert to a string
400  * @param radix - the radix to format the string in
401  * @returns an long long formatted to the string value of the radix given.
402  */
403  static std::string toString(long long value, int radix);
404 
424  static std::string toHexString(long long value);
425 
444  static std::string toOctalString(long long value);
445 
461  static std::string toBinaryString(long long value);
462 
468  static Long valueOf(long long value) {
469  return Long(value);
470  }
471 
482  static Long valueOf(const std::string& value);
483 
496  static Long valueOf(const std::string& value, int radix);
497 
498  private:
499 
500  static long long parse(const std::string& value, int offset, int radix, bool negative);
501 
502  };
503 
504 }}
505 
506 #endif /*_DECAF_LANG_LONG_H_*/
virtual float floatValue() const
Answers the float value which the receiver represents.
Definition: Long.h:161
static const long long MAX_VALUE
The maximum value that the primitive type can hold.
Definition: Long.h:43
bool equals(const Long &l) const
Definition: Long.h:84
virtual int intValue() const
Answers the int value which the receiver represents.
Definition: Long.h:185
bool equals(const long long &l) const
Definition: Long.h:121
virtual double doubleValue() const
Answers the double value which the receiver represents.
Definition: Long.h:153
virtual bool operator<(const long long &l) const
Compares this object to another and returns true if this object is considered to be less than the one...
Definition: Long.h:140
Definition: Long.h:29
virtual long long longValue() const
Answers the long value which the receiver represents.
Definition: Long.h:193
virtual bool operator==(const long long &l) const
Compares equality between this object and the one passed.
Definition: Long.h:130
The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short.
Definition: Number.h:35
static const int SIZE
The size in bits of the primitive long long type.
Definition: Long.h:40
static Long valueOf(long long value)
Returns a Long instance representing the specified int value.
Definition: Long.h:468
#define DECAF_API
Definition: Config.h:29
virtual short shortValue() const
Answers the short value which the receiver represents.
Definition: Long.h:177
virtual bool operator==(const Long &l) const
Compares equality between this object and the one passed.
Definition: Long.h:93
virtual bool operator<(const Long &l) const
Compares this object to another and returns true if this object is considered to be less than the one...
Definition: Long.h:103
virtual unsigned char byteValue() const
Answers the byte value which the receiver represents.
Definition: Long.h:169
This interface imposes a total ordering on the objects of each class that implements it...
Definition: Comparable.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: AprPool.h:25
static const long long MIN_VALUE
The minimum value that the primitive type can hold.
Definition: Long.h:46
virtual ~Long()
Definition: Long.h:67