Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wsfulton/1cb931f1ee5c7cdc34258554c35597ac to your computer and use it in GitHub Desktop.
Save wsfulton/1cb931f1ee5c7cdc34258554c35597ac to your computer and use it in GitHub Desktop.
From ca76734ed688fc20396997c11dd9de804e40bd57 Mon Sep 17 00:00:00 2001
From: William S Fulton <wsf@fultondesigns.co.uk>
Date: Thu, 25 May 2017 21:40:05 +0100
Subject: [PATCH 1/2] Whitespace corrections in C# std_list.i
---
Lib/csharp/std_list.i | 422 +++++++++++++++++++++++++-------------------------
1 file changed, 211 insertions(+), 211 deletions(-)
diff --git a/Lib/csharp/std_list.i b/Lib/csharp/std_list.i
index 78336ad..fd98c4d 100644
--- a/Lib/csharp/std_list.i
+++ b/Lib/csharp/std_list.i
@@ -6,7 +6,7 @@
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.LinkedList<> collection.
*
* ----------------------------------------------------------------------------- */
-
+
%include <std_common.i>
%define SWIG_STD_LIST_MINIMUM_INTERNAL(CONST_REFERENCE, CTYPE...)
%typemap(csinterfaces) std::list< CTYPE > "global::System.Collections.Generic.ICollection<$typemap(cstype, CTYPE)>, global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>, global::System.Collections.IEnumerable, global::System.IDisposable"
@@ -24,96 +24,96 @@
return false;
}
}
-
+
public int Count {
get {
return (int)size();
}
}
-
+
public $csclassnameNode First {
- get {
- if (Count == 0)
- return null;
- return new $csclassnameNode(getFirstIter(), this);
+ get {
+ if (Count == 0)
+ return null;
+ return new $csclassnameNode(getFirstIter(), this);
}
}
public $csclassnameNode Last {
get {
- if (Count == 0)
- return null;
+ if (Count == 0)
+ return null;
return new $csclassnameNode(getLastIter(), this);
}
}
-
- public $csclassnameNode AddFirst($typemap(cstype, CTYPE) value) {
- push_front(value);
- return new $csclassnameNode(getFirstIter(), this);
+
+ public $csclassnameNode AddFirst($typemap(cstype, CTYPE) value) {
+ push_front(value);
+ return new $csclassnameNode(getFirstIter(), this);
}
public void AddFirst($csclassnameNode newNode) {
ValidateNewNode(newNode);
- if (!newNode.inlist) {
- push_front(newNode.csharpvalue);
- newNode.iter = getFirstIter();
- newNode.inlist = true;
- } else {
- throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
- }
+ if (!newNode.inlist) {
+ push_front(newNode.csharpvalue);
+ newNode.iter = getFirstIter();
+ newNode.inlist = true;
+ } else {
+ throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
+ }
}
public $csclassnameNode AddLast($typemap(cstype, CTYPE) value) {
push_back(value);
- return new $csclassnameNode(getLastIter(), this);
+ return new $csclassnameNode(getLastIter(), this);
}
public void AddLast($csclassnameNode newNode) {
ValidateNewNode(newNode);
- if (!newNode.inlist) {
- push_back(newNode.csharpvalue);
- newNode.iter = getLastIter();
- newNode.inlist = true;
- } else {
- throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
- }
+ if (!newNode.inlist) {
+ push_back(newNode.csharpvalue);
+ newNode.iter = getLastIter();
+ newNode.inlist = true;
+ } else {
+ throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
+ }
}
-
+
public $csclassnameNode AddBefore($csclassnameNode node, $typemap(cstype, CTYPE) value) {
- return new $csclassnameNode(insertNode(node.iter, value), this);
+ return new $csclassnameNode(insertNode(node.iter, value), this);
}
public void AddBefore($csclassnameNode node, $csclassnameNode newNode) {
ValidateNode(node);
- ValidateNewNode(newNode);
- if (!newNode.inlist) {
- newNode.iter = insertNode(node.iter, newNode.csharpvalue);
- newNode.inlist = true;
- } else {
- throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
- }
+ ValidateNewNode(newNode);
+ if (!newNode.inlist) {
+ newNode.iter = insertNode(node.iter, newNode.csharpvalue);
+ newNode.inlist = true;
+ } else {
+ throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
+ }
}
public $csclassnameNode AddAfter($csclassnameNode node, $typemap(cstype, CTYPE) value) {
- node = node.Next;
- return new $csclassnameNode(insertNode(node.iter, value), this);
+ node = node.Next;
+ return new $csclassnameNode(insertNode(node.iter, value), this);
}
public void AddAfter($csclassnameNode node, $csclassnameNode newNode) {
ValidateNode(node);
- ValidateNewNode(newNode);
- if (!newNode.inlist) {
- if (node == this.Last)
- AddLast(newNode);
- else
- {
- node = node.Next;
- newNode.iter = insertNode(node.iter, newNode.csharpvalue);
- newNode.inlist = true;
- }
- } else {
- throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
- }
+ ValidateNewNode(newNode);
+ if (!newNode.inlist) {
+ if (node == this.Last)
+ AddLast(newNode);
+ else
+ {
+ node = node.Next;
+ newNode.iter = insertNode(node.iter, newNode.csharpvalue);
+ newNode.inlist = true;
+ }
+ } else {
+ throw new global::System.InvalidOperationException("The " + newNode.GetType().Name + " node already belongs to a " + this.GetType().Name);
+ }
}
public void Add($typemap(cstype, CTYPE) value) {
@@ -123,24 +123,24 @@
public bool Remove($typemap(cstype, CTYPE) value) {
var node = Find(value);
if (node == null)
- return false;
- Remove(node);
- return true;
+ return false;
+ Remove(node);
+ return true;
}
public void Remove($csclassnameNode node) {
ValidateNode(node);
- eraseIter(node.iter);
+ eraseIter(node.iter);
}
public $csclassnameNode Find($typemap(cstype, CTYPE) value) {
System.IntPtr tmp = find(value);
if (tmp != System.IntPtr.Zero) {
- return new $csclassnameNode(tmp, this);
- }
- return null;
+ return new $csclassnameNode(tmp, this);
+ }
+ return null;
}
-
+
public void CopyTo($typemap(cstype, CTYPE)[] array, int index) {
if (array == null)
throw new global::System.ArgumentNullException("array");
@@ -159,17 +159,17 @@
internal void ValidateNode($csclassnameNode node) {
if (node == null) {
- throw new System.ArgumentNullException("node");
- }
- if (!node.inlist || node.list != this) {
+ throw new System.ArgumentNullException("node");
+ }
+ if (!node.inlist || node.list != this) {
throw new System.InvalidOperationException("node");
}
}
internal void ValidateNewNode($csclassnameNode node) {
if (node == null) {
- throw new System.ArgumentNullException("node");
- }
+ throw new System.ArgumentNullException("node");
+ }
}
global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() {
@@ -183,7 +183,7 @@
public $csclassnameEnumerator GetEnumerator() {
return new $csclassnameEnumerator(this);
}
-
+
public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator,
global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)>
{
@@ -192,7 +192,7 @@
private int currentIndex;
private object currentObject;
private int currentSize;
-
+
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
currentNode = collection.First;
@@ -200,7 +200,7 @@
currentObject = null;
currentSize = collectionRef.Count;
}
-
+
// Type-safe iterator Current
public $typemap(cstype, CTYPE) Current {
get {
@@ -213,14 +213,14 @@
return ($typemap(cstype, CTYPE))currentObject;
}
}
-
+
// Type-unsafe IEnumerator.Current
object global::System.Collections.IEnumerator.Current {
get {
return Current;
}
}
-
+
public bool MoveNext() {
if (currentNode == null) {
currentIndex = collectionRef.Count + 1;
@@ -231,7 +231,7 @@
currentNode = currentNode.Next;
return true;
}
-
+
public void Reset() {
currentIndex = -1;
currentObject = null;
@@ -239,105 +239,105 @@
throw new global::System.InvalidOperationException("Collection modified.");
}
}
-
+
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
}
-
+
public sealed class $csclassnameNode {
internal $csclassname list;
internal System.IntPtr iter;
- internal $typemap(cstype, CTYPE) csharpvalue;
- internal bool inlist;
-
+ internal $typemap(cstype, CTYPE) csharpvalue;
+ internal bool inlist;
+
public $csclassnameNode($typemap(cstype, CTYPE) value) {
- csharpvalue = value;
- inlist = false;
+ csharpvalue = value;
+ inlist = false;
}
internal $csclassnameNode(System.IntPtr _iter, $csclassname _list) {
list = _list;
iter = _iter;
- inlist = true;
+ inlist = true;
}
-
+
public $csclassname List {
- get {
- return this.list;
+ get {
+ return this.list;
}
}
public $csclassnameNode Next {
- get {
- if (list.getNextIter(iter) == System.IntPtr.Zero)
- return null;
+ get {
+ if (list.getNextIter(iter) == System.IntPtr.Zero)
+ return null;
return new $csclassnameNode(list.getNextIter(iter), list);
}
}
-
+
public $csclassnameNode Previous {
get {
- if (list.getPrevIter(iter) == System.IntPtr.Zero)
- return null;
+ if (list.getPrevIter(iter) == System.IntPtr.Zero)
+ return null;
return new $csclassnameNode(list.getPrevIter(iter), list);
}
}
-
- public $typemap(cstype, CTYPE) Value {
- get {
- return list.getItem(this.iter);
+
+ public $typemap(cstype, CTYPE) Value {
+ get {
+ return list.getItem(this.iter);
}
- set {
- list.setItem(this.iter, value);
+ set {
+ list.setItem(this.iter, value);
}
}
- public static bool operator== ($csclassnameNode node1, $csclassnameNode node2) {
- if (object.ReferenceEquals(node1, null) && object.ReferenceEquals(node2, null))
- return true;
- if (object.ReferenceEquals(node1, null) || object.ReferenceEquals(node2, null))
- return false;
- return node1.Equals(node2);
- }
+ public static bool operator== ($csclassnameNode node1, $csclassnameNode node2) {
+ if (object.ReferenceEquals(node1, null) && object.ReferenceEquals(node2, null))
+ return true;
+ if (object.ReferenceEquals(node1, null) || object.ReferenceEquals(node2, null))
+ return false;
+ return node1.Equals(node2);
+ }
public static bool operator!= ($csclassnameNode node1, $csclassnameNode node2) {
- if (node1 == null && node2 == null)
- return false;
- if (node1 == null || node2 == null)
- return true;
- return !node1.Equals(node2);
- }
-
- public bool Equals($csclassnameNode node) {
- if (node == null)
- return false;
- if (!node.inlist || !this.inlist)
- return object.ReferenceEquals(this, node);
- return list.equals(this.iter, node.iter);
- }
-
- public override bool Equals(object node) {
- return Equals(($csclassnameNode)node);
- }
-
- public override int GetHashCode() {
- int hash = 13;
- if (inlist) {
- hash = (hash * 7) + this.list.GetHashCode();
- hash = (hash * 7) + this.Value.GetHashCode();
- hash = (hash * 7) + this.list.getNextIter(this.iter).GetHashCode();
- hash = (hash * 7) + this.list.getPrevIter(this.iter).GetHashCode();
- } else {
- hash = (hash * 7) + this.csharpvalue.GetHashCode();
- }
- return hash;
- }
-
- public void Dispose() {
- list.deleteIter(this.iter);
- }
+ if (node1 == null && node2 == null)
+ return false;
+ if (node1 == null || node2 == null)
+ return true;
+ return !node1.Equals(node2);
+ }
+
+ public bool Equals($csclassnameNode node) {
+ if (node == null)
+ return false;
+ if (!node.inlist || !this.inlist)
+ return object.ReferenceEquals(this, node);
+ return list.equals(this.iter, node.iter);
+ }
+
+ public override bool Equals(object node) {
+ return Equals(($csclassnameNode)node);
+ }
+
+ public override int GetHashCode() {
+ int hash = 13;
+ if (inlist) {
+ hash = (hash * 7) + this.list.GetHashCode();
+ hash = (hash * 7) + this.Value.GetHashCode();
+ hash = (hash * 7) + this.list.getNextIter(this.iter).GetHashCode();
+ hash = (hash * 7) + this.list.getPrevIter(this.iter).GetHashCode();
+ } else {
+ hash = (hash * 7) + this.csharpvalue.GetHashCode();
+ }
+ return hash;
+ }
+
+ public void Dispose() {
+ list.deleteIter(this.iter);
+ }
}
%}
@@ -355,86 +355,86 @@ public:
%rename(Clear) clear;
void clear();
%extend {
- CONST_REFERENCE getItem(void *iter) {
+ CONST_REFERENCE getItem(void *iter) {
std::list< CTYPE >::iterator it = *reinterpret_cast<std::list< CTYPE >::iterator*>(iter);
- return *it;
+ return *it;
}
- void setItem(void *iter, CTYPE const& val) {
- std::list< CTYPE >::iterator* it = reinterpret_cast<std::list< CTYPE >::iterator*>(iter);
- *(*it) = val;
- }
-
- void *getFirstIter() {
- if ($self->size() == 0)
- return NULL;
- auto iterator = new std::list< CTYPE >::iterator($self->begin());
- return reinterpret_cast<void *>(iterator);
- }
-
- void *getLastIter() {
- if ($self->size() == 0)
- return NULL;
- auto iterator = new std::list< CTYPE >::iterator(--$self->end());
- return reinterpret_cast<void *>(iterator);
- }
-
- void *getNextIter(void *iter) {
- auto it = *(reinterpret_cast<std::list< CTYPE >::iterator *>(iter));
- if (std::distance(it, --$self->end()) != 0) {
- auto itnext = new std::list< CTYPE >::iterator(++it);
- return itnext;
- }
- return NULL;
- }
-
- void *getPrevIter(void *iter) {
+ void setItem(void *iter, CTYPE const& val) {
+ std::list< CTYPE >::iterator* it = reinterpret_cast<std::list< CTYPE >::iterator*>(iter);
+ *(*it) = val;
+ }
+
+ void *getFirstIter() {
+ if ($self->size() == 0)
+ return NULL;
+ auto iterator = new std::list< CTYPE >::iterator($self->begin());
+ return reinterpret_cast<void *>(iterator);
+ }
+
+ void *getLastIter() {
+ if ($self->size() == 0)
+ return NULL;
+ auto iterator = new std::list< CTYPE >::iterator(--$self->end());
+ return reinterpret_cast<void *>(iterator);
+ }
+
+ void *getNextIter(void *iter) {
+ auto it = *(reinterpret_cast<std::list< CTYPE >::iterator *>(iter));
+ if (std::distance(it, --$self->end()) != 0) {
+ auto itnext = new std::list< CTYPE >::iterator(++it);
+ return itnext;
+ }
+ return NULL;
+ }
+
+ void *getPrevIter(void *iter) {
auto it = *(reinterpret_cast<std::list< CTYPE >::iterator *>(iter));
- if (std::distance($self->begin(), it) != 0) {
- auto itprev = new std::list< CTYPE >::iterator(--it);
- return itprev;
- }
- return NULL;
- }
-
- void *insertNode(void *iter, CTYPE const& value) {
- auto it = $self->insert(*(reinterpret_cast<std::list< CTYPE >::iterator *>(iter)), value);
- auto newit = reinterpret_cast<void *>(new std::list< CTYPE >::iterator(it));
- return newit;
- }
-
- void *find(CTYPE const& value) {
- if (std::find($self->begin(), $self->end(), value) != $self->end()) {
- auto it = reinterpret_cast<void *>(new std::list< CTYPE >::iterator(std::find($self->begin(), $self->end(), value)));
- return it;
- }
- return NULL;
- }
-
- void eraseIter(void *iter) {
- auto it = *reinterpret_cast<std::list< CTYPE >::iterator*>(iter);
- $self->erase(it);
- }
-
- void deleteIter(void *iter) {
- std::list< CTYPE >::iterator* it = reinterpret_cast<std::list< CTYPE >::iterator*>(iter);
- delete it;
- }
-
- bool equals(void *iter1, void *iter2) {
- if (iter1 == NULL && iter2 == NULL)
- return true;
- std::list< CTYPE >::iterator it1 = *reinterpret_cast<std::list< CTYPE >::iterator*>(iter1);
- std::list< CTYPE >::iterator it2 = *reinterpret_cast<std::list< CTYPE >::iterator*>(iter2);
- return it1 == it2;
- }
-
+ if (std::distance($self->begin(), it) != 0) {
+ auto itprev = new std::list< CTYPE >::iterator(--it);
+ return itprev;
+ }
+ return NULL;
+ }
+
+ void *insertNode(void *iter, CTYPE const& value) {
+ auto it = $self->insert(*(reinterpret_cast<std::list< CTYPE >::iterator *>(iter)), value);
+ auto newit = reinterpret_cast<void *>(new std::list< CTYPE >::iterator(it));
+ return newit;
+ }
+
+ void *find(CTYPE const& value) {
+ if (std::find($self->begin(), $self->end(), value) != $self->end()) {
+ auto it = reinterpret_cast<void *>(new std::list< CTYPE >::iterator(std::find($self->begin(), $self->end(), value)));
+ return it;
+ }
+ return NULL;
+ }
+
+ void eraseIter(void *iter) {
+ auto it = *reinterpret_cast<std::list< CTYPE >::iterator*>(iter);
+ $self->erase(it);
+ }
+
+ void deleteIter(void *iter) {
+ std::list< CTYPE >::iterator* it = reinterpret_cast<std::list< CTYPE >::iterator*>(iter);
+ delete it;
+ }
+
+ bool equals(void *iter1, void *iter2) {
+ if (iter1 == NULL && iter2 == NULL)
+ return true;
+ std::list< CTYPE >::iterator it1 = *reinterpret_cast<std::list< CTYPE >::iterator*>(iter1);
+ std::list< CTYPE >::iterator it2 = *reinterpret_cast<std::list< CTYPE >::iterator*>(iter2);
+ return it1 == it2;
+ }
+
bool Contains(CTYPE const& value) {
return std::find($self->begin(), $self->end(), value) != $self->end();
}
}
%enddef
-
+
%apply void *VOID_INT_PTR { void *iter1, void *iter2, void *iter, void *find, void *insertNode, void *getPrevIter, void *getNextIter, void *getFirstIter, void *getLastIter }
%define SWIG_STD_LIST_ENHANCED(CTYPE...)
@@ -467,16 +467,16 @@ namespace std {
%csmethodmodifiers std::list::deleteIter "private"
namespace std {
- template<class T>
+ template<class T>
class list {
SWIG_STD_LIST_MINIMUM_INTERNAL(T const&, T)
};
- template<class T>
- class list<T *>
+ template<class T>
+ class list<T *>
{
SWIG_STD_LIST_MINIMUM_INTERNAL(T *const&, T *)
};
- template<>
+ template<>
class list<bool> {
SWIG_STD_LIST_MINIMUM_INTERNAL(bool, bool)
};
--
2.7.4
From 5eefaf8655f1a3af219141d9863e36e55fbdc353 Mon Sep 17 00:00:00 2001
From: William S Fulton <wsf@fultondesigns.co.uk>
Date: Thu, 25 May 2017 21:59:16 +0100
Subject: [PATCH 2/2] Add li_std_list C# testing
---
Examples/test-suite/csharp/Makefile.in | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Examples/test-suite/csharp/Makefile.in b/Examples/test-suite/csharp/Makefile.in
index 0c799c7..afa3214 100644
--- a/Examples/test-suite/csharp/Makefile.in
+++ b/Examples/test-suite/csharp/Makefile.in
@@ -25,7 +25,8 @@ CPP_TEST_CASES = \
enum_thorough_typesafe \
exception_partial_info \
intermediary_classname \
- li_boost_intrusive_ptr
+ li_boost_intrusive_ptr \
+ li_std_list \
CPP11_TEST_CASES = \
cpp11_strongly_typed_enumerations_simple \
--
2.7.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment