]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/input_output/FGPropertyManager.cpp
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / FDM / JSBSim / input_output / FGPropertyManager.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 63bc589..c0218ec
@@ -8,20 +8,20 @@
  ------------- Copyright (C) 2002 -------------
 
  This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
+ the terms of the GNU Lesser General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.
 
  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
  details.
 
- You should have received a copy of the GNU General Public License along with
+ You should have received a copy of the GNU Lesser General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place - Suite 330, Boston, MA  02111-1307, USA.
 
- Further information about the GNU General Public License can also be found on
+ Further information about the GNU Lesser General Public License can also be found on
  the world wide web at http://www.gnu.org.
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -48,6 +48,21 @@ COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
 
 namespace JSBSim {
 
+bool FGPropertyManager::suppress_warning = true;
+std::vector<std::string> FGPropertyManager::tied_properties;
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGPropertyManager::Unbind(void)
+{
+    vector<string>::iterator it;
+    for (it = tied_properties.begin();it < tied_properties.end();it++)
+    {
+        Untie(*it);
+    }
+    tied_properties.clear();
+}
+
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
@@ -61,12 +76,7 @@ string FGPropertyManager::mkPropertyName(string name, bool lowercase) {
     else if( isspace(name[i]) )
       name[i]='-';
   }
-  /*
-  for(i=0;i<name.length();i++) {
-    if( name[i] == '/' )
-      name.erase(i,1);
-  }
-  */
+  
   return name;
 }
 
@@ -76,9 +86,9 @@ FGPropertyManager*
 FGPropertyManager::GetNode (const string &path, bool create)
 {
   SGPropertyNode* node=this->getNode(path.c_str(), create);
-  if (node == 0 && !suppress_warning)
-    cout << "FGPropertyManager::GetNode() No node found for "
-         << path << endl;
+  if (node == 0 && !suppress_warning) {
+    cerr << "FGPropertyManager::GetNode() No node found for " << path << endl;
+  }
   return (FGPropertyManager*)node;
 }
 
@@ -104,12 +114,34 @@ bool FGPropertyManager::HasNode (const string &path)
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGPropertyManager::GetName( void ) {
+string FGPropertyManager::GetName( void )
+{
   return string( getName() );
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+string FGPropertyManager::GetPrintableName( void )
+{
+  string temp_string(getName());
+  size_t initial_location=0;
+  size_t found_location;
+
+  found_location = temp_string.rfind("/");
+  if (found_location != string::npos)
+  temp_string = temp_string.substr(found_location);
+
+  found_location = temp_string.find('_',initial_location);
+  while (found_location != string::npos) {
+    temp_string.replace(found_location,1," ");
+    initial_location = found_location+1;
+    found_location = temp_string.find('_',initial_location);
+  }
+  return temp_string;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 string FGPropertyManager::GetFullyQualifiedName(void) {
     vector<string> stack;
     stack.push_back( getDisplayName(true) );
@@ -133,6 +165,19 @@ string FGPropertyManager::GetFullyQualifiedName(void) {
 
 }
 
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+string FGPropertyManager::GetRelativeName( const string &path )
+{
+  string temp_string = GetFullyQualifiedName();
+  size_t len = path.length();
+  if ( (len > 0) && (temp_string.substr(0,len) == path) ) {
+    temp_string = temp_string.erase(0,len);
+  }
+  return temp_string;
+}
+
+
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
@@ -224,8 +269,8 @@ void FGPropertyManager::SetArchivable (const string &name, bool state )
 {
   SGPropertyNode * node = getNode(name.c_str());
   if (node == 0)
-    cout <<
-           "Attempt to set archive flag for non-existant property "
+    cerr <<
+           "Attempt to set archive flag for non-existent property "
            << name << endl;
   else
     node->setAttribute(SGPropertyNode::ARCHIVE, state);
@@ -237,7 +282,7 @@ void FGPropertyManager::SetReadable (const string &name, bool state )
 {
   SGPropertyNode * node = getNode(name.c_str());
   if (node == 0)
-    cout <<
+    cerr <<
            "Attempt to set read flag for non-existant property "
            << name << endl;
   else
@@ -250,7 +295,7 @@ void FGPropertyManager::SetWritable (const string &name, bool state )
 {
   SGPropertyNode * node = getNode(name.c_str());
   if (node == 0)
-    cout <<
+    cerr <<
            "Attempt to set write flag for non-existant property "
            << name << endl;
   else
@@ -262,7 +307,7 @@ void FGPropertyManager::SetWritable (const string &name, bool state )
 void FGPropertyManager::Untie (const string &name)
 {
   if (!untie(name.c_str()))
-    cout << "Failed to untie property " << name << endl;
+    cerr << "Failed to untie property " << name << endl;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -270,9 +315,11 @@ void FGPropertyManager::Untie (const string &name)
 void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
 {
   if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
-  else if (debug_lvl & 0x20)
-    cout << name << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
+  else {
+    tied_properties.push_back(name);
+    if (debug_lvl & 0x20) std::cout << name << std::endl;
+  }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -281,9 +328,11 @@ void FGPropertyManager::Tie (const string &name, int *pointer,
                                           bool useDefault )
 {
   if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
-  else if (debug_lvl & 0x20)
-    cout << name << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
+  else {
+    tied_properties.push_back(name);
+    if (debug_lvl & 0x20) std::cout << name << std::endl;
+  }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -292,9 +341,11 @@ void FGPropertyManager::Tie (const string &name, long *pointer,
                                           bool useDefault )
 {
   if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
-  else if (debug_lvl & 0x20)
-    cout << name << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
+  else {
+    tied_properties.push_back(name);
+    if (debug_lvl & 0x20) std::cout << name << std::endl;
+  }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -303,9 +354,11 @@ void FGPropertyManager::Tie (const string &name, float *pointer,
                                           bool useDefault )
 {
   if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
-  else if (debug_lvl & 0x20)
-    cout << name << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
+  else {
+    tied_properties.push_back(name);
+    if (debug_lvl & 0x20) std::cout << name << std::endl;
+  }
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -313,9 +366,11 @@ void FGPropertyManager::Tie (const string &name, float *pointer,
 void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
 {
   if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault))
-    cout << "Failed to tie property " << name << " to a pointer" << endl;
-  else if (debug_lvl & 0x20)
-    cout << name << endl;
+    cerr << "Failed to tie property " << name << " to a pointer" << endl;
+  else {
+    tied_properties.push_back(name);
+    if (debug_lvl & 0x20) std::cout << name << std::endl;
+  }
 }
 
 } // namespace JSBSim