1
0
Fork 0

YASim: move common helper functions to new yasim-common.cpp

This commit is contained in:
Henning Stahlke 2017-12-01 22:59:07 +01:00
parent c63ded1c44
commit 78f7950fa6
8 changed files with 58 additions and 70 deletions

View file

@ -26,6 +26,7 @@ set(COMMON
Turbulence.cpp Turbulence.cpp
Wing.cpp Wing.cpp
Version.cpp Version.cpp
yasim-common.cpp
) )
set(SOURCES set(SOURCES

View file

@ -2,6 +2,7 @@
# include "config.h" # include "config.h"
#endif #endif
#include "yasim-common.hpp"
#include "Jet.hpp" #include "Jet.hpp"
#include "Thruster.hpp" #include "Thruster.hpp"
#include "PropEngine.hpp" #include "PropEngine.hpp"
@ -281,26 +282,6 @@ float ControlMap::rangeMax(Control control)
} }
} }
/// duplicate null-terminated string
char* ControlMap::dup(const char* s)
{
int len=0;
while(s[len++]);
char* s2 = new char[len+1];
char* p = s2;
while((*p++ = *s++));
s2[len] = 0;
return s2;
}
/// compare null-terminated strings
bool ControlMap::eq(const char* a, const char* b)
{
while(*a && *b && *a == *b) { a++; b++; }
// equal if both a and b points to null chars
return !(*a || *b);
}
/// register property name, return ID (int) /// register property name, return ID (int)
int ControlMap::propertyHandle(const char* name) int ControlMap::propertyHandle(const char* name)
{ {

View file

@ -142,10 +142,6 @@ private:
Vector _outputs; Vector _outputs;
// control properties // control properties
Vector _properties; Vector _properties;
// helper
char* dup(const char* s);
bool eq(const char* a, const char* b);
}; };
}; // namespace yasim }; // namespace yasim

View file

@ -1114,24 +1114,6 @@ void FGFDM::parseWeight(XMLAttributes* a)
_weights.add(wr); _weights.add(wr);
} }
bool FGFDM::eq(const char* a, const char* b)
{
// Figure it out for yourself. :)
while(*a && *b && *a == *b) { a++; b++; }
return !(*a || *b);
}
char* FGFDM::dup(const char* s)
{
int len=0;
while(s[len++]);
char* s2 = new char[len+1];
char* p = s2;
while((*p++ = *s++));
s2[len] = 0;
return s2;
}
int FGFDM::attri(XMLAttributes* atts, const char* attr) int FGFDM::attri(XMLAttributes* atts, const char* attr)
{ {
if(!atts->hasAttribute(attr)) { if(!atts->hasAttribute(attr)) {

View file

@ -59,9 +59,6 @@ private:
void parseTurbineEngine(XMLAttributes* a); void parseTurbineEngine(XMLAttributes* a);
void parsePistonEngine(XMLAttributes* a); void parsePistonEngine(XMLAttributes* a);
void parsePropeller(XMLAttributes* a); void parsePropeller(XMLAttributes* a);
bool eq(const char* a, const char* b);
bool caseeq(const char* a, const char* b);
char* dup(const char* s);
int attri(XMLAttributes* atts, const char* attr); int attri(XMLAttributes* atts, const char* attr);
int attri(XMLAttributes* atts, const char* attr, int def); int attri(XMLAttributes* atts, const char* attr, int def);
float attrf(XMLAttributes* atts, const char* attr); float attrf(XMLAttributes* atts, const char* attr);

View file

@ -3,6 +3,8 @@
#include <stdio.h> #include <stdio.h>
#include <cassert> #include <cassert>
namespace yasim {
// //
// Excruciatingly simple vector-of-pointers class. Easy & useful. // Excruciatingly simple vector-of-pointers class. Easy & useful.
// No support for addition of elements anywhere but at the end of the // No support for addition of elements anywhere but at the end of the
@ -78,5 +80,5 @@ inline void Vector::realloc()
delete[] _array; delete[] _array;
_array = array; _array = array;
} }
}; //namespace yasim
#endif // _VECTOR_HPP #endif // _VECTOR_HPP

View file

@ -0,0 +1,23 @@
#include "yasim-common.hpp"
namespace yasim {
/// duplicate null-terminated string
char* dup(const char* s)
{
int len=0;
while(s[len++]);
char* s2 = new char[len+1];
char* p = s2;
while((*p++ = *s++));
s2[len] = 0;
return s2;
}
/// compare null-terminated strings
bool eq(const char* a, const char* b)
{
while(*a && *b && *a == *b) { a++; b++; }
// equal if both a and b points to null chars
return !(*a || *b);
}
}; //namespace yasim

View file

@ -1,6 +1,9 @@
#ifndef _YASIM_COMMON_HPP #ifndef _YASIM_COMMON_HPP
#define _YASIM_COMMON_HPP #define _YASIM_COMMON_HPP
/*
common file for YASim wide constants and static helper functions
*/
namespace yasim { namespace yasim {
static const float YASIM_PI = 3.14159265358979323846f; static const float YASIM_PI = 3.14159265358979323846f;
static const float PI2 = YASIM_PI*2; static const float PI2 = YASIM_PI*2;
@ -29,6 +32,9 @@ namespace yasim {
static const float NM2FTLB = (1/(LBS2N*FT2M)); static const float NM2FTLB = (1/(LBS2N*FT2M));
static const float SLUG2KG = 14.59390f; static const float SLUG2KG = 14.59390f;
}; char* dup(const char* s);
bool eq(const char* a, const char* b);
}; //namespace yasim
#endif // ifndef _YASIM_COMMON_HPP #endif // ifndef _YASIM_COMMON_HPP