Xpace
ipv4.h
Go to the documentation of this file.
1 
2 /**********************************************************//**
3  **
4  ** @file base/IPv4.h
5  **
6  ** Copyright (C) 2012 Xpace, LLC. All rights reserved
7  **
8  ** www.xpace.net
9  **
10  **************************************************************/
11 
12 #ifndef XPACE_IPV4_H
13 #define XPACE_IPV4_H
14 
15 #include "util/matchstring.h"
16 
17 namespace Xpace
18 {
20  {
21  public:
22  IPv4
23  (const String& format) :
24  qformat(format)
25  {
26  for (int i(0), n(1); ((i = qformat.indexOf('a', i)) != -1) && (n <= 4); ++n)
27  qformat.replace(i, 1, QString("%%1").arg(n));
28  }
29 
30  IPv4& operator=
31  (uint32 v)
32  {
33  val = v;
34  return *this;
35  }
36 
37  /// @retval buf the buffer into which to store the IPv4
38  void toString
39  (String16* string)
40  const
41  {
42  QString q(toString());
43  if (q.length() < narrow_to<int>(string->length))
44  string->length = q.length();
45  memcpy(string->data, q.utf16(), string->length * sizeof(utf16_t));
46  }
47 
48  /// @param format the format of the IPv4 e.g. "a.a.a.a"
49  String toString
50  ()
51  const
52  {
53  return QString(qformat).arg(val >> 24)
54  .arg((val >> 16) & 0xFF)
55  .arg((val >> 8) & 0xFF)
56  .arg(val & 0xFF);
57  }
58 
59  private:
60  QString qformat;
61  uint32 val;
62  };
63 }
64 #endif
A low-level data holder.
Definition: types_c.h:82
Copyright (C) 2012 Xpace, LLC.
A string, Unicode UTF-16 and reference-counted.
Definition: types.h:269
unsigned short utf16_t
Definition: types.h:146
unsigned int uint32
Definition: types.h:85
Xpace project main namespace
Definition: datetime.h:18

current as of Wed Jun 10 2026 12:00:05