Skip to content

Commit

Permalink
Move oak::c_array to oak/datatypes.h
Browse files Browse the repository at this point in the history
This simple wrapper is useful in a few places so we shouldn’t need to depend on the OakSystem framework in order to use it.
  • Loading branch information
sorbits committed Aug 11, 2012
1 parent dc37506 commit 485bdde
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Frameworks/OakSystem/src/application.cc
@@ -1,9 +1,9 @@
#include "application.h"
#include "process.h"
#include <io/io.h>
#include <cf/cf.h>
#include <text/format.h>
#include <oak/compat.h>
#include <oak/datatypes.h>
#include <oak/debug.h>

OAK_DEBUG_VAR(Application);
Expand Down
18 changes: 1 addition & 17 deletions Frameworks/OakSystem/src/process.cc
@@ -1,6 +1,7 @@
#include "process.h"
#include <io/io.h>
#include <oak/oak.h>
#include <oak/datatypes.h>
#include <oak/compat.h>
#include <oak/server.h>
#include <text/format.h>
Expand Down Expand Up @@ -98,23 +99,6 @@ namespace oak
new kill_process_group_in_background_t(groupId);
}

c_array::c_array (std::map<std::string, std::string> const& map)
{
char** p = new char* [map.size() + 1];
_array = p;
iterate(pair, map)
*p++ = strdup((pair->first + "=" + pair->second).c_str());
*p = NULL;
}

c_array::~c_array ()
{
char* const* p = _array;
while(p && *p)
free(*p++);
delete[] _array;
}

struct process_server_t
{
process_server_t ();
Expand Down
9 changes: 0 additions & 9 deletions Frameworks/OakSystem/src/process.h
Expand Up @@ -9,15 +9,6 @@ namespace oak
PUBLIC std::map<std::string, std::string> const& basic_environment ();
PUBLIC void kill_process_group_in_background (pid_t groupId);

struct PUBLIC c_array
{
c_array (std::map<std::string, std::string> const& map);
~c_array ();
operator char* const* () const { return _array; }
private:
char* const* _array;
};

struct PUBLIC process_t
{
WATCH_LEAKS(oak::process_t);
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/network/src/filter_tbz.h
Expand Up @@ -4,7 +4,7 @@
#include "download.h" // filter_t
#include <io/io.h>
#include <OakSystem/application.h>
#include <OakSystem/process.h>
#include <oak/datatypes.h>
#include <text/format.h>
#include <text/trim.h>

Expand Down
1 change: 1 addition & 0 deletions Frameworks/network/src/tbz.cc
@@ -1,6 +1,7 @@
#include "tbz.h"
#include <text/format.h>
#include <OakSystem/process.h>
#include <oak/datatypes.h>

namespace network
{
Expand Down
35 changes: 35 additions & 0 deletions Shared/include/oak/datatypes.h
@@ -0,0 +1,35 @@
#ifndef OAK_DATATYPES_H_665IJ16Q
#define OAK_DATATYPES_H_665IJ16Q

namespace oak
{
namespace
{
struct c_array
{
c_array (std::map<std::string, std::string> const& map)
{
char** p = new char* [map.size() + 1];
_array = p;
iterate(pair, map)
*p++ = strdup((pair->first + "=" + pair->second).c_str());
*p = NULL;
}

~c_array ()
{
char* const* p = _array;
while(p && *p)
free(*p++);
delete[] _array;
}

operator char* const* () const { return _array; }

private:
char* const* _array;
};
}
}

#endif /* end of include guard: OAK_DATATYPES_H_665IJ16Q */

0 comments on commit 485bdde

Please sign in to comment.