dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / lib / spu / proc_wrapper.cpp
diff --git a/dol/src/dol/visitor/cell/lib/spu/proc_wrapper.cpp b/dol/src/dol/visitor/cell/lib/spu/proc_wrapper.cpp
new file mode 100644 (file)
index 0000000..41e2705
--- /dev/null
@@ -0,0 +1,92 @@
+/**
+ * proc_wrapper.cpp
+ *
+ *  Created on: Feb 24, 2009
+ *      Author: lschor
+ */
+
+#include "proc_wrapper.h"
+
+proc_wrapper::proc_wrapper() {
+  _isDetached = false;
+  readPos = 0;
+  writePos = 0;
+}
+
+proc_wrapper::~proc_wrapper() {
+}
+
+/**
+ *
+ */
+void proc_wrapper::init() {
+  _process.init(&_process);
+}
+
+/**
+ *
+ */
+int proc_wrapper::fire() {
+  return _process.fire(&_process);
+}
+
+/**
+ *
+ */
+void proc_wrapper::detach() {
+  _isDetached = true;
+}
+
+/**
+ * Gets an index of a string, where the index must be separated by
+ * a character specified in tokens.
+ * Returns -1, when an error occurs.
+ *
+ * Example:
+ * getIndex("name_1_2", "_", 0) will return 1.
+ * getIndex("name_1_2", "_", 1) will return 2.
+ *
+ * @param string string to parse
+ * @param tokens delimiter of indices
+ * @param indexNumber position of index (starting at 0)
+ */
+int proc_wrapper::getIndex(const char* string, char* tokens,
+    int indexNumber) {
+  char* string_copy;
+  char* token_pointer;
+  int index = 0;
+
+  string_copy = (char*) malloc(sizeof(char) * (strlen(string) + 1));
+  if (!string_copy) {
+    fprintf(stderr, "getIndex(): could not allocate memory.\n");
+    return -1;
+  }
+
+  strcpy(string_copy, string);
+
+  token_pointer = strtok(string_copy, tokens);
+  do {
+    token_pointer = strtok(NULL, tokens);
+    index++;
+  } while (index <= indexNumber && token_pointer != 0);
+
+  if (token_pointer) {
+    index = atoi(token_pointer);
+    free(string_copy);
+    return index;
+  }
+
+  free(string_copy);
+  return -1;
+}
+
+/**
+ * Get the index of this process.
+ * @param indexNumber position of index (starting at 0)
+ */
+int proc_wrapper::getIndex(unsigned indexNumber) const {
+    if (indexNumber < 4) {
+        return _iteratorIndex[indexNumber];
+    }
+    return -1;
+}