add initial examples, replacing the 'Demos/Demos3'. Will make it work cross-platform, OpenGL3/OpenGL2 and add more examples to it.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#ifndef BOOST_REPLACEMENT_LEXICAL_CAST_H
|
||||
#define BOOST_REPLACEMENT_LEXICAL_CAST_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
template <typename T> T lexical_cast(const char* txt)
|
||||
{
|
||||
double result = atof(txt);
|
||||
return result;
|
||||
};
|
||||
|
||||
struct bad_lexical_cast
|
||||
{
|
||||
const char* what()
|
||||
{
|
||||
return ("bad lexical cast\n");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} //namespace boost
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "printf_console.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
void logError(const char* msg, const char* arg0, const char* arg1, const char* arg2)
|
||||
{
|
||||
printf("%s %s %s %s\n", msg,arg0,arg1,arg2);
|
||||
|
||||
}
|
||||
|
||||
void logDebug(const char* msg, float v0, float v1)
|
||||
{
|
||||
printf("%s %f %f\n", msg, v0, v1);
|
||||
};
|
||||
void logDebug(const char* msg, const char* msg1, const char* arg1)
|
||||
{
|
||||
printf("%s %s %s\n", msg, msg1, arg1);
|
||||
|
||||
}
|
||||
|
||||
void logInform(const char* msg, const char* arg0)
|
||||
{
|
||||
printf("%s %s\n", msg, arg0);
|
||||
}
|
||||
void logWarn(const char* msg,int id, const char* arg0)
|
||||
{
|
||||
printf("%s %d %s\n", msg,id,arg0);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef PRINTF_CONSOLE_H
|
||||
#define PRINTF_CONSOLE_H
|
||||
|
||||
|
||||
void logError(const char* msg="", const char* arg0="", const char* arg1="", const char* arg2="");
|
||||
void logDebug(const char* msg, float v0, float v1);
|
||||
void logDebug(const char* msg, const char* msg1="", const char* arg1="");
|
||||
void logInform(const char* msg, const char* arg0="");
|
||||
void logWarn(const char* msg,int id, const char* arg0="");
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
210
examples/ThirdPartyLibs/urdf/boost_replacement/shared_ptr.h
Normal file
210
examples/ThirdPartyLibs/urdf/boost_replacement/shared_ptr.h
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
Bullet Continuous Collision Detection and Physics Library Maya Plugin
|
||||
Copyright (c) 2008 Walt Disney Studios
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising
|
||||
from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must
|
||||
not claim that you wrote the original software. If you use this
|
||||
software in a product, an acknowledgment in the product documentation
|
||||
would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must
|
||||
not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Written by: Nicola Candussi <nicola@fluidinteractive.com>
|
||||
|
||||
Modified by Francisco Gochez
|
||||
Dec 2011 - Added deferencing operator
|
||||
*/
|
||||
|
||||
//my_shared_ptr
|
||||
|
||||
#ifndef DYN_SHARED_PTR_H
|
||||
#define DYN_SHARED_PTR_H
|
||||
|
||||
#define DYN_SHARED_PTR_THREAD_SAFE
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
class my_shared_count {
|
||||
public:
|
||||
my_shared_count(): m_count(1) { }
|
||||
~my_shared_count() { }
|
||||
|
||||
long increment()
|
||||
{
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
return InterlockedIncrement(&m_count);
|
||||
#else
|
||||
return ++m_count;
|
||||
#endif
|
||||
}
|
||||
|
||||
long decrement() {
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
return InterlockedDecrement(&m_count);
|
||||
#else
|
||||
return ++m_count;
|
||||
#endif
|
||||
}
|
||||
|
||||
long use_count() { return m_count; }
|
||||
|
||||
private:
|
||||
long m_count;
|
||||
};
|
||||
#else //ifdef WIN32
|
||||
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
class my_shared_count {
|
||||
public:
|
||||
my_shared_count(): m_count(1) {
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
pthread_mutex_init(&m_mutex, 0);
|
||||
#endif
|
||||
}
|
||||
~my_shared_count() {
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
long increment()
|
||||
{
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
#endif
|
||||
long c = ++m_count;
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
#endif
|
||||
return c;
|
||||
}
|
||||
|
||||
long decrement() {
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
pthread_mutex_lock(&m_mutex);
|
||||
#endif
|
||||
long c = --m_count;
|
||||
#ifdef DYN_SHARED_PTR_THREAD_SAFE
|
||||
pthread_mutex_unlock(&m_mutex);
|
||||
#endif
|
||||
return c;
|
||||
}
|
||||
|
||||
long use_count() { return m_count; }
|
||||
|
||||
private:
|
||||
long m_count;
|
||||
mutable pthread_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
template<typename T>
|
||||
class my_shared_ptr
|
||||
{
|
||||
public:
|
||||
my_shared_ptr(): m_ptr(NULL), m_count(NULL) { }
|
||||
my_shared_ptr(my_shared_ptr<T> const& other):
|
||||
m_ptr(other.m_ptr),
|
||||
m_count(other.m_count)
|
||||
{
|
||||
if(other.m_count != NULL) other.m_count->increment();
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
my_shared_ptr(my_shared_ptr<U> const& other):
|
||||
m_ptr(other.m_ptr),
|
||||
m_count(other.m_count)
|
||||
{
|
||||
if(other.m_count != NULL) other.m_count->increment();
|
||||
}
|
||||
|
||||
my_shared_ptr(T const* other): m_ptr(const_cast<T*>(other)), m_count(NULL)
|
||||
{
|
||||
if(other != NULL) m_count = new my_shared_count;
|
||||
}
|
||||
|
||||
~my_shared_ptr()
|
||||
{
|
||||
giveup_ownership();
|
||||
}
|
||||
|
||||
void reset(T const* other)
|
||||
{
|
||||
if(m_ptr == other) return;
|
||||
giveup_ownership();
|
||||
m_ptr = const_cast<T*>(other);
|
||||
if(other != NULL) m_count = new my_shared_count;
|
||||
else m_count = NULL;
|
||||
}
|
||||
|
||||
T* get() { return m_ptr; }
|
||||
T const* get() const { return m_ptr; }
|
||||
T* operator->() { return m_ptr; }
|
||||
T const* operator->() const { return m_ptr; }
|
||||
operator bool() const { return m_ptr != NULL; }
|
||||
T& operator*() const
|
||||
{
|
||||
assert(m_ptr != 0);
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
bool operator<(my_shared_ptr<T> const& rhs) const { return m_ptr < rhs.m_ptr; }
|
||||
|
||||
my_shared_ptr<T>& operator=(my_shared_ptr<T> const& other) {
|
||||
if(m_ptr == other.m_ptr) return *this;
|
||||
giveup_ownership();
|
||||
m_ptr = other.m_ptr;
|
||||
m_count = other.m_count;
|
||||
if(other.m_count != NULL) m_count->increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
my_shared_ptr<T>& operator=(my_shared_ptr<U>& other) {
|
||||
if(m_ptr == other.m_ptr) return *this;
|
||||
giveup_ownership();
|
||||
m_ptr = other.m_ptr;
|
||||
m_count = other.m_count;
|
||||
if(other.m_count != NULL) m_count->increment();
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
template<typename U> friend class my_shared_ptr;
|
||||
void giveup_ownership()
|
||||
{
|
||||
if(m_count != NULL) {
|
||||
if( m_count->decrement() == 0) {
|
||||
delete m_ptr;
|
||||
m_ptr = NULL;
|
||||
delete m_count;
|
||||
m_count = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
T *m_ptr;
|
||||
my_shared_count *m_count;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
253
examples/ThirdPartyLibs/urdf/boost_replacement/string_split.cpp
Normal file
253
examples/ThirdPartyLibs/urdf/boost_replacement/string_split.cpp
Normal file
@@ -0,0 +1,253 @@
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
//#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "string_split.h"
|
||||
|
||||
namespace boost
|
||||
{
|
||||
void split( std::vector<std::string>&pieces, const std::string& vector_str, std::vector<std::string> separators)
|
||||
{
|
||||
assert(separators.size()==1);
|
||||
if (separators.size()==1)
|
||||
{
|
||||
char** strArray = str_split(vector_str.c_str(),separators[0].c_str());
|
||||
int numSubStr = str_array_len(strArray);
|
||||
for (int i=0;i<numSubStr;i++)
|
||||
pieces.push_back(std::string(strArray[i]));
|
||||
str_array_free(strArray);
|
||||
}
|
||||
}
|
||||
std::vector<std::string> is_any_of(const char* seps)
|
||||
{
|
||||
std::vector<std::string> strArray;
|
||||
|
||||
int numSeps = strlen(seps);
|
||||
for (int i=0;i<numSeps;i++)
|
||||
{
|
||||
char sep2[2] = {0,0};
|
||||
|
||||
sep2[0] = seps[i];
|
||||
strArray.push_back(sep2);
|
||||
}
|
||||
return strArray;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Append an item to a dynamically allocated array of strings. On failure,
|
||||
return NULL, in which case the original array is intact. The item
|
||||
string is dynamically copied. If the array is NULL, allocate a new
|
||||
array. Otherwise, extend the array. Make sure the array is always
|
||||
NULL-terminated. Input string might not be '\0'-terminated. */
|
||||
char **str_array_append(char **array, size_t nitems, const char *item,
|
||||
size_t itemlen)
|
||||
{
|
||||
/* Make a dynamic copy of the item. */
|
||||
char *copy;
|
||||
if (item == NULL)
|
||||
copy = NULL;
|
||||
else {
|
||||
copy = (char*)malloc(itemlen + 1);
|
||||
if (copy == NULL)
|
||||
return NULL;
|
||||
memcpy(copy, item, itemlen);
|
||||
copy[itemlen] = '\0';
|
||||
}
|
||||
|
||||
/* Extend array with one element. Except extend it by two elements,
|
||||
in case it did not yet exist. This might mean it is a teeny bit
|
||||
too big, but we don't care. */
|
||||
array = (char**)realloc(array, (nitems + 2) * sizeof(array[0]));
|
||||
if (array == NULL) {
|
||||
free(copy);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Add copy of item to array, and return it. */
|
||||
array[nitems] = copy;
|
||||
array[nitems+1] = NULL;
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
/* Free a dynamic array of dynamic strings. */
|
||||
void str_array_free(char **array)
|
||||
{
|
||||
if (array == NULL)
|
||||
return;
|
||||
for (size_t i = 0; array[i] != NULL; ++i)
|
||||
free(array[i]);
|
||||
free(array);
|
||||
}
|
||||
|
||||
|
||||
/* Split a string into substrings. Return dynamic array of dynamically
|
||||
allocated substrings, or NULL if there was an error. Caller is
|
||||
expected to free the memory, for example with str_array_free. */
|
||||
char **str_split(const char *input, const char *sep)
|
||||
{
|
||||
size_t nitems = 0;
|
||||
char **array = NULL;
|
||||
const char *start = input;
|
||||
const char *next = strstr(start, sep);
|
||||
size_t seplen = strlen(sep);
|
||||
const char *item;
|
||||
size_t itemlen;
|
||||
|
||||
for (;;) {
|
||||
next = strstr(start, sep);
|
||||
if (next == NULL) {
|
||||
/* Add the remaining string (or empty string, if input ends with
|
||||
separator. */
|
||||
char **newstr = str_array_append(array, nitems, start, strlen(start));
|
||||
if (newstr == NULL) {
|
||||
str_array_free(array);
|
||||
return NULL;
|
||||
}
|
||||
array = newstr;
|
||||
++nitems;
|
||||
break;
|
||||
} else if (next == input) {
|
||||
/* Input starts with separator. */
|
||||
item = "";
|
||||
itemlen = 0;
|
||||
} else {
|
||||
item = start;
|
||||
itemlen = next - item;
|
||||
}
|
||||
char **newstr = str_array_append(array, nitems, item, itemlen);
|
||||
if (newstr == NULL) {
|
||||
str_array_free(array);
|
||||
return NULL;
|
||||
}
|
||||
array = newstr;
|
||||
++nitems;
|
||||
start = next + seplen;
|
||||
}
|
||||
|
||||
if (nitems == 0) {
|
||||
/* Input does not contain separator at all. */
|
||||
assert(array == NULL);
|
||||
array = str_array_append(array, nitems, input, strlen(input));
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
/* Return length of a NULL-delimited array of strings. */
|
||||
size_t str_array_len(char **array)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; array[len] != NULL; ++len)
|
||||
continue;
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifdef UNIT_TEST_STRING
|
||||
|
||||
#define MAX_OUTPUT 20
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
struct {
|
||||
const char *input;
|
||||
const char *sep;
|
||||
char *output[MAX_OUTPUT];
|
||||
} tab[] = {
|
||||
/* Input is empty string. Output should be a list with an empty
|
||||
string. */
|
||||
{
|
||||
"",
|
||||
"and",
|
||||
{
|
||||
"",
|
||||
NULL,
|
||||
},
|
||||
},
|
||||
/* Input is exactly the separator. Output should be two empty
|
||||
strings. */
|
||||
{
|
||||
"and",
|
||||
"and",
|
||||
{
|
||||
"",
|
||||
"",
|
||||
NULL,
|
||||
},
|
||||
},
|
||||
/* Input is non-empty, but does not have separator. Output should
|
||||
be the same string. */
|
||||
{
|
||||
"foo",
|
||||
"and",
|
||||
{
|
||||
"foo",
|
||||
NULL,
|
||||
},
|
||||
},
|
||||
/* Input is non-empty, and does have separator. */
|
||||
{
|
||||
"foo bar 1 and foo bar 2",
|
||||
" and ",
|
||||
{
|
||||
"foo bar 1",
|
||||
"foo bar 2",
|
||||
NULL,
|
||||
},
|
||||
},
|
||||
};
|
||||
const int tab_len = sizeof(tab) / sizeof(tab[0]);
|
||||
bool errors;
|
||||
|
||||
errors = false;
|
||||
|
||||
for (int i = 0; i < tab_len; ++i) {
|
||||
printf("test %d\n", i);
|
||||
|
||||
char **output = str_split(tab[i].input, tab[i].sep);
|
||||
if (output == NULL) {
|
||||
fprintf(stderr, "output is NULL\n");
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
size_t num_output = str_array_len(output);
|
||||
printf("num_output %lu\n", (unsigned long) num_output);
|
||||
|
||||
size_t num_correct = str_array_len(tab[i].output);
|
||||
if (num_output != num_correct) {
|
||||
fprintf(stderr, "wrong number of outputs (%lu, not %lu)\n",
|
||||
(unsigned long) num_output, (unsigned long) num_correct);
|
||||
errors = true;
|
||||
} else {
|
||||
for (size_t j = 0; j < num_output; ++j) {
|
||||
if (strcmp(tab[i].output[j], output[j]) != 0) {
|
||||
fprintf(stderr, "output[%lu] is '%s' not '%s'\n",
|
||||
(unsigned long) j, output[j], tab[i].output[j]);
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
str_array_free(output);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (errors)
|
||||
return EXIT_FAILURE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif//
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
#ifndef STRING_SPLIT_H
|
||||
#define STRING_SPLIT_H
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
void split( std::vector<std::string>&pieces, const std::string& vector_str, std::vector<std::string> separators);
|
||||
std::vector<std::string> is_any_of(const char* seps);
|
||||
};
|
||||
|
||||
///The string split C code is by Lars Wirzenius
|
||||
///See http://stackoverflow.com/questions/2531605/how-to-split-a-string-with-a-delimiter-larger-than-one-single-char
|
||||
|
||||
|
||||
/* Split a string into substrings. Return dynamic array of dynamically
|
||||
allocated substrings, or NULL if there was an error. Caller is
|
||||
expected to free the memory, for example with str_array_free. */
|
||||
char** str_split(const char* input, const char* sep);
|
||||
|
||||
/* Free a dynamic array of dynamic strings. */
|
||||
void str_array_free(char** array);
|
||||
|
||||
/* Return length of a NULL-delimited array of strings. */
|
||||
size_t str_array_len(char** array);
|
||||
|
||||
#endif //STRING_SPLIT_H
|
||||
|
||||
Reference in New Issue
Block a user