]> git.mxchange.org Git - simgear.git/blobdiff - simgear/misc/props.cxx
Moved up #include <algorithm>
[simgear.git] / simgear / misc / props.cxx
index 21a2aac47294f45350c9394ed2c54d1a73b0beef..8fbbbd585f7952ec14bcca81b45057203516b854 100644 (file)
@@ -8,10 +8,6 @@
 
 #include "props.hxx"
 
-#include <algorithm>
-#include <stdio.h>
-#include <string.h>
-
 #if PROPS_STANDALONE
 
 #include <iostream>
@@ -21,6 +17,7 @@ using std::sort;
 
 #else
 
+#include <algorithm>
 #include <simgear/compiler.h>
 #include <simgear/debug/logstream.hxx>
 
@@ -28,6 +25,8 @@ SG_USING_STD(sort);
 
 #endif
 
+#include <stdio.h>
+#include <string.h>
 
 
 \f
@@ -223,7 +222,6 @@ copy_string (const char * s)
                                // For some reason, strnlen and
                                // strncpy cause all kinds of crashes.
   string str = s;
-  size_t len = strlen(s);
   char * copy = new char[str.size() + 1];
   strcpy(copy, str.c_str());
   return copy;
@@ -420,7 +418,7 @@ SGPropertyNode::set_string (const char * val)
   if (_tied) {
     return _value.string_val->setValue(val);
   } else {
-    delete _local_val.string_val;
+    delete (char *)_local_val.string_val;
     _local_val.string_val = copy_string(val);
     return true;
   }
@@ -431,39 +429,53 @@ SGPropertyNode::clear_value ()
 {
   switch (_type) {
   case NONE:
+    break;
   case ALIAS:
     _value.alias = 0;
     break;
   case BOOL:
-    delete _value.bool_val;
-    _value.bool_val = 0;
+    if (_tied) {
+      delete _value.bool_val;
+      _value.bool_val = 0;
+    }
     _local_val.bool_val = SGRawValue<bool>::DefaultValue;
     break;
   case INT:
-    delete _value.int_val;
-    _value.int_val = 0;
+    if (_tied) {
+      delete _value.int_val;
+      _value.int_val = 0;
+    }
     _local_val.int_val = SGRawValue<int>::DefaultValue;
     break;
   case LONG:
-    delete _value.long_val;
-    _value.long_val = 0L;
+    if (_tied) {
+      delete _value.long_val;
+      _value.long_val = 0L;
+    }
     _local_val.long_val = SGRawValue<long>::DefaultValue;
     break;
   case FLOAT:
-    delete _value.float_val;
-    _value.float_val = 0;
+    if (_tied) {
+      delete _value.float_val;
+      _value.float_val = 0;
+    }
     _local_val.float_val = SGRawValue<float>::DefaultValue;
     break;
   case DOUBLE:
-    delete _value.double_val;
-    _value.double_val = 0;
+    if (_tied) {
+      delete _value.double_val;
+      _value.double_val = 0;
+    }
     _local_val.double_val = SGRawValue<double>::DefaultValue;
     break;
   case STRING:
   case UNSPECIFIED:
-    delete _value.string_val;
-    _value.string_val = 0;
-    delete _local_val.string_val;
+    if (_tied) {
+      delete _value.string_val;
+      _value.string_val = 0;
+    } else {
+      delete (char *)_local_val.string_val;
+    }
     _local_val.string_val = 0;
     break;
   }
@@ -664,7 +676,7 @@ SGPropertyNode::SGPropertyNode (const char * name,
  */
 SGPropertyNode::~SGPropertyNode ()
 {
-  delete _name;
+  delete (char *)_name;
   for (int i = 0; i < (int)_children.size(); i++) {
     delete _children[i];
   }