summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Savoye2010-11-26 11:23:37 -0700
committerRob Savoye2010-11-26 11:23:37 -0700
commit712e2a1b1235b9f1272b56ae90afbc776c884f7b (patch)
tree1687dff9315a2415d7e4626b50ac552e6b5acb47
parent9039bed758fc3e3513ca96a33e6fe130b5d976a2 (diff)
downloadgnuradio-712e2a1b1235b9f1272b56ae90afbc776c884f7b.tar.gz
gnuradio-712e2a1b1235b9f1272b56ae90afbc776c884f7b.tar.bz2
gnuradio-712e2a1b1235b9f1272b56ae90afbc776c884f7b.zip
create C++ class with C linkage bindings for guile. Add string conversion static method.
-rw-r--r--gr-run-waveform/xyzzy.cc70
-rw-r--r--gr-run-waveform/xyzzy.h57
2 files changed, 103 insertions, 24 deletions
diff --git a/gr-run-waveform/xyzzy.cc b/gr-run-waveform/xyzzy.cc
index a54947c51..ecb692643 100644
--- a/gr-run-waveform/xyzzy.cc
+++ b/gr-run-waveform/xyzzy.cc
@@ -26,6 +26,7 @@
#include <iostream>
#include <fstream>
#include <libguile.h>
+#include <boost/cstdint.hpp>
// Include our definitions
#include "xyzzy.h"
@@ -34,19 +35,28 @@ using namespace std;
typedef void* handle_t;
-handle_t datafile;
+XYZZY::XYZZY()
+{
+ // nothing to initialize
+}
+XYZZY::~XYZZY()
+{
+ // nothing to destruct
+}
// Initialize with the data file produced by gen-xyzzy.
-bool init()
+bool
+XYZZY::init()
{
- string filespec = PKGLIBDIR;
- filespec += '/';
- filespec += "filesystem.dat";
- return init(filespec);
+ _filespec = PKGLIBDIR;
+ _filespec += '/';
+ _filespec += "filesystem.dat";
+ return init(_filespec);
};
-bool init(const std::string &file)
+bool
+XYZZY::init(const std::string &file)
{
return false;
};
@@ -54,15 +64,53 @@ bool init(const std::string &file)
// Does a file with name 'filename' exist in magic filesystem?
// bool file_exists(handle, const std::string &filespec);
bool
-file_exists(const std::string &filespec)
+XYZZY::file_exists(const std::string &filespec)
{
-// datafile
+
}
// Return a C port that will read the file contents
// SCM make_read_only_port(handle, const std::string &filespec)
SCM
-make_read_only_port(const std::string &filespec)
+XYZZY::make_read_only_port(const std::string &filespec)
+{
+
+}
+
+string
+XYZZY::read_string(boost::uint8_t *entry, size_t length)
+{
+ string str(reinterpret_cast<const char *>(entry), length);
+
+ return str;
+}
+
+string
+XYZZY::read_string(struct string_entry & entry)
{
-// datafile
+ return read_string(entry.base, entry.length);
}
+
+extern "C" {
+
+static XYZZY datafile;
+
+// Initialize with the data file produced by gen-xyzzy.
+bool xyzzy_init(const std::string &filespec)
+{
+ datafile.init(filespec);
+}
+
+// Does a file with name 'filename' exist in magic filesystem?
+bool xyzzy_file_exists(const std::string &filespec)
+{
+ datafile.file_exists(filespec);
+}
+
+// Return a C port that will read the file contents
+SCM xyzzy_make_read_only_port(const std::string &filespec)
+{
+ datafile.make_read_only_port(filespec);
+}
+
+} // end of extern C
diff --git a/gr-run-waveform/xyzzy.h b/gr-run-waveform/xyzzy.h
index 024c9f963..effb348d2 100644
--- a/gr-run-waveform/xyzzy.h
+++ b/gr-run-waveform/xyzzy.h
@@ -26,8 +26,10 @@
#include <cstdio>
#include <cstdlib>
#include <string>
+#include <map>
#include <iostream>
#include <fstream>
+#include <boost/cstdint.hpp>
#include <libguile.h>
@@ -49,34 +51,63 @@ using namespace std;
struct header {
char magic[8];
- uint32_t offset_to_directory; // byte offset from start of file
- uint32_t size_of_directory; // bytes
- uint32_t number_of_dir_entries;
+ boost::uint32_t offset_to_directory; // byte offset from start of file
+ boost::uint32_t size_of_directory; // bytes
+ boost::uint32_t number_of_dir_entries;
- uint32_t offset_to_strings; // byte offset from start of file
- uint32_t size_of_strings; // bytes
+ boost::uint32_t offset_to_strings; // byte offset from start of file
+ boost::uint32_t size_of_strings; // bytes
};
struct directory_entry {
- uint32_t offset_to_name; // from start of strings
- uint32_t offset_to_contents; // from start of strings
+ boost::uint32_t offset_to_name; // from start of strings
+ boost::uint32_t offset_to_contents; // from start of strings
};
// Each string starts with a uint32_t length, followed by length bytes.
// There is no trailing \0 in the string.
struct string_entry {
- uint32_t length;
- unsigned char c[1]; // 0 is nicer, but not portable.
+ boost::uint32_t length;
+ boost::uint8_t *base;
};
+class XYZZY {
+public:
+ XYZZY();
+ ~XYZZY();
+
+ // Initialize with the data file produced by gen-xyzzy.
+ bool init();
+ bool init(const std::string &filespec);
+
+ // Does a file with name 'filename' exist in magic filesystem?
+ bool file_exists(const std::string &filespec);
+
+ // Return a C port that will read the file contents
+ SCM make_read_only_port(const std::string &filespec);
+
+ /// Parse a string data structure
+ static std::string read_string(boost::uint8_t *entry, size_t length);
+ static std::string read_string(struct string_entry &entry);
+
+private:
+ std::string _filespec;
+ struct header _header;
+ std::map<std::string, directory_entry> _directories;
+};
+
+// C linkage bindings for Guile
+extern "C" {
+
// Initialize with the data file produced by gen-xyzzy.
-bool init(const std::string &filespec);
-bool init();
+bool xyzzy_init(const std::string &filespec);
// Does a file with name 'filename' exist in magic filesystem?
-bool file_exists(const std::string &filespec);
+bool xyzzy_file_exists(const std::string &filespec);
// Return a C port that will read the file contents
-SCM make_read_only_port(const std::string &filespec);
+SCM xyzzy_make_read_only_port(const std::string &filespec);
+
+} // end of extern C
#endif // _XYZZY_H_ 1