forked from textmate/textmate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move oak::c_array to oak/datatypes.h
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
Showing
6 changed files
with
39 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |