File: NodeIDNET.i

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (109 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//NodeID
namespace RobotRaconteur
{

%typemap("cscode") NodeID
%{

public static bool operator == (NodeID a, NodeID b)
{
    if (Object.Equals(a,  null)  && Object.Equals(b,  null) ) return true;
    if (Object.Equals(a,  null)  || Object.Equals(b,  null) ) return false;
    return a.eq(b);
}

public override bool Equals(Object o)
{
    if (!(o is NodeID)) return false;
    return this == ((NodeID)o);
}

public override int GetHashCode()
{
	int o=0;
	byte[] b=ToByteArray();
	for (int i=0; i<b.Length; i++) o+=b[i];
    return o;
}

public static bool operator != (NodeID a, NodeID b)
{
    return !(a==b);
}

public byte[] ToByteArray()
{
	byte[] o=new byte[16];
	this.ToByteArrayC(o);
	return o;

}

public NodeID(byte[] bytes) : this(bytes,bytes.Length) {}

%}

class NodeID
{
public:
	NodeID();
	%csmethodmodifiers ToString "public override";
	virtual std::string ToString() const;
	%csmethodmodifiers ToString "public";
	virtual std::string ToString(const std::string& format) const;
	static NodeID NewUniqueID();

    %csmethodmodifiers operator== "public virtual";
    %rename(eq) operator==;
	bool operator== (const NodeID &id2) const;

    %rename(ne) operator!=;
	bool operator != (const NodeID &id2) const;
	%rename(lt) operator<;
	bool operator <(const NodeID& id2) const;

	bool IsAnyNode();
	static NodeID GetAny();


	//NodeID(std::boost<uint8_t,16> id);
	NodeID(const std::string& id);
	NodeID(const NodeID& id);



	%rename(ToByteArrayC) ToByteArray;
	%csmethodmodifiers ToByteArray "private";
	//std::vector<uint8_t> ToByteArray();





};

%extend NodeID {
	%csmethodmodifiers NodeID (const uint8_t bytes[16], int32_t bytes_len) "private";
	%apply unsigned char INPUT[] {const uint8_t bytes[16]}
	NodeID (const uint8_t bytes[16], int32_t bytes_len)
	{
		if (bytes_len!=16) throw InvalidArgumentException("Invalid NodeID bytes length");

		boost::array<uint8_t,16> b = {};
		memcpy(&b[0],bytes,16);

		NodeID* n=new NodeID(b);
		return n;
	}

	%apply unsigned char OUTPUT[] {uint8_t bytes[16]}
	void ToByteArray(uint8_t bytes[16])
	{
		boost::array<uint8_t,16> b=$self->ToByteArray();
		memcpy(bytes,&b[0],16);
	}


}

}