summaryrefslogtreecommitdiffstats
path: root/labb8/lib/StanfordCPPLib/private
diff options
context:
space:
mode:
Diffstat (limited to 'labb8/lib/StanfordCPPLib/private')
-rwxr-xr-xlabb8/lib/StanfordCPPLib/private/main.h58
-rwxr-xr-xlabb8/lib/StanfordCPPLib/private/randompatch.h63
-rwxr-xr-xlabb8/lib/StanfordCPPLib/private/tokenpatch.h11
-rwxr-xr-xlabb8/lib/StanfordCPPLib/private/tplatform.h25
4 files changed, 157 insertions, 0 deletions
diff --git a/labb8/lib/StanfordCPPLib/private/main.h b/labb8/lib/StanfordCPPLib/private/main.h
new file mode 100755
index 0000000..698a97c
--- /dev/null
+++ b/labb8/lib/StanfordCPPLib/private/main.h
@@ -0,0 +1,58 @@
+/*
+ * File: main.h
+ * ------------
+ * This file renames the <code>main</code> method in the client's
+ * program to <code>Main</code>, thereby allowing a custom
+ * <code>main</code> method in the libraries to take control
+ * before passing control back to the client program. The main macro
+ * also defines a function getMainFlags that returns an int whose bits
+ * indicate which of the various interfaces have been loaded by this
+ * definition of main.
+ *
+ * Note: This file can be loaded more than once and must therefore
+ * check to see what has already been defined.
+ */
+
+#ifdef main
+# undef main
+# undef CONSOLE_FLAG
+# undef GRAPHICS_FLAG
+#else
+# define MAIN_USES_CONSOLE (1<<0)
+# define MAIN_USES_GRAPHICS (1<<1)
+#endif
+
+#ifdef _console_h
+# define CONSOLE_FLAG MAIN_USES_CONSOLE
+#else
+# define CONSOLE_FLAG 0
+#endif
+
+#ifdef _gwindow_h
+# define GRAPHICS_FLAG MAIN_USES_GRAPHICS
+#else
+# define GRAPHICS_FLAG 0
+#endif
+
+#if CONSOLE_FLAG | GRAPHICS_FLAG
+
+#define main main(int argc, char **argv) { \
+ extern int _mainFlags; \
+ _mainFlags = GRAPHICS_FLAG + CONSOLE_FLAG; \
+ return startupMain(argc, argv); \
+ } \
+ int Main
+
+extern int startupMain(int argc, char **argv);
+
+#else
+
+#define main main(int argc, char **argv) { \
+ extern int _mainFlags; \
+ _mainFlags = GRAPHICS_FLAG + CONSOLE_FLAG; \
+ return mainWrapper(argc, argv); } \
+ int Main
+
+extern int mainWrapper(int argc, char **argv);
+
+#endif
diff --git a/labb8/lib/StanfordCPPLib/private/randompatch.h b/labb8/lib/StanfordCPPLib/private/randompatch.h
new file mode 100755
index 0000000..c7a4b86
--- /dev/null
+++ b/labb8/lib/StanfordCPPLib/private/randompatch.h
@@ -0,0 +1,63 @@
+/*
+ * File: private/randompatch.h
+ * ---------------------------
+ * This file patches the implementation of the random number library
+ * to avoid some serious bugs in standard implementations of rand,
+ * particularly on Mac OS X. It also includes a hack to set the
+ * seed from the RANDOM_SEED environment variable, which makes it
+ * possible to produce repeatable figures.
+ */
+
+/*
+ * Implementation notes: rand, srand
+ * ---------------------------------
+ * To ensure that this package works the same way on all platforms,
+ * this file completely reimplements the rand and srand methods. The
+ * algorithm is a conventional linear congruential generator with the
+ * parameters used in GNU's gclib. RAND_MAX for this implementation
+ * is 2147483647 (2^31 - 1).
+ */
+
+#define MULTIPLIER 1103515245
+#define OFFSET 12345
+
+static int _seed = 1;
+
+#undef rand
+#define rand() ((_seed = MULTIPLIER * _seed + OFFSET) & 0x7FFFFFFF)
+
+#undef srand
+#define srand(seed) (_seed = int(seed), _seed = (_seed <= 0) ? 1 : _seed)
+
+#undef RAND_MAX
+#define RAND_MAX 2147483647
+
+/*
+ * Implementation notes: Windows patch
+ * -----------------------------------
+ * On some versions of Windows, the time function is too coarse to use
+ * as a random seed. On those versions, this definition substitutes the
+ * GetTickCount function.
+ */
+
+#if defined (_MSC_VER) && (_MSC_VER >= 1200)
+# include <windows.h>
+# define time(dummy) (GetTickCount())
+#endif
+
+#ifdef __APPLE__
+
+# include <cstdlib>
+
+ static time_t patchedTime(time_t *) {
+ char *str = getenv("RANDOM_SEED");
+ if (str == NULL) {
+ return time(NULL);
+ } else {
+ return atoi(str);
+ }
+ }
+
+# define time(dummy) patchedTime(dummy)
+
+#endif
diff --git a/labb8/lib/StanfordCPPLib/private/tokenpatch.h b/labb8/lib/StanfordCPPLib/private/tokenpatch.h
new file mode 100755
index 0000000..d4930e5
--- /dev/null
+++ b/labb8/lib/StanfordCPPLib/private/tokenpatch.h
@@ -0,0 +1,11 @@
+/*
+ * File: tokenpatch.h
+ * ------------------
+ * This file renames TokenType and WORD to avoid conflict with the
+ * <windows.h> header.
+ */
+
+#ifdef _MSC_VER
+# define TokenType TokenTypeT
+# define WORD WORD_TC
+#endif
diff --git a/labb8/lib/StanfordCPPLib/private/tplatform.h b/labb8/lib/StanfordCPPLib/private/tplatform.h
new file mode 100755
index 0000000..6cf4bae
--- /dev/null
+++ b/labb8/lib/StanfordCPPLib/private/tplatform.h
@@ -0,0 +1,25 @@
+/*
+ * File: tplatform.h
+ * -----------------
+ * This interface defines the platform-specific methods on threads
+ * and locks.
+ */
+
+/* Methods for threads */
+
+int forkForPlatform(void (*fn)(void *), void *arg);
+void incThreadRefCountForPlatform(int id);
+void decThreadRefCountForPlatform(int id);
+void joinForPlatform(int id);
+int getCurrentThreadForPlatform();
+void yieldForPlatform();
+
+/* Methods for locks */
+
+int initLockForPlatform();
+void incLockRefCountForPlatform(int id);
+void decLockRefCountForPlatform(int id);
+void lockForPlatform(int id);
+void unlockForPlatform(int id);
+void waitForPlatform(int id);
+void signalForPlatform(int id);