Skip to content

Commit

Permalink
ch9/proj
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang.gao committed Sep 12, 2016
1 parent a1d5cfe commit b88ed28
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 1 deletion.
49 changes: 49 additions & 0 deletions project/0.1/include/myslam/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2016 <copyright holder> <email>
*
* 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 Foundation, either version 3 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 details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*
*/

#ifndef CONFIG_H
#define CONFIG_H

#include "myslam/common_include.h"

namespace myslam
{
class Config
{
private:
static std::shared_ptr<Config> config_;
cv::FileStorage file_;

Config () {} // private constructor makes a singleton
public:
~Config(); // close the file when deconstructing

// set a new config file
static void setParameterFile( const std::string& filename );

// access the parameter values
template< typename T >
static T get( const std::string& key )
{
return T( Config::config_->file_[key] );
}
};
}

#endif // CONFIG_H
Binary file modified project/0.1/lib/libmyslam.so
Binary file not shown.
3 changes: 2 additions & 1 deletion project/0.1/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ add_library( myslam SHARED
mappoint.cpp
map.cpp
camera.cpp
config.cpp
)

target_link_libraries( myslam
${THIRD_PARTY_LIBS}
)
)
46 changes: 46 additions & 0 deletions project/0.1/src/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* <one line to give the program's name and a brief idea of what it does.>
* Copyright (C) 2016 <copyright holder> <email>
*
* 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 Foundation, either version 3 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 details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http:https://www.gnu.org/licenses/>.
*
*/

#include "myslam/config.h"

namespace myslam
{

void Config::setParameterFile( const std::string& filename )
{
if ( config_ == nullptr )
config_ = shared_ptr<Config>(new Config);
config_->file_ = cv::FileStorage( filename.c_str(), cv::FileStorage::READ );
if ( config_->file_.isOpened() == false )
{
std::cerr<<"parameter file "<<filename<<" does not exist."<<std::endl;
config_->file_.release();
return;
}
}

Config::~Config()
{
if ( file_.isOpened() )
file_.release();
}

shared_ptr<Config> Config::config_ = nullptr;

}

0 comments on commit b88ed28

Please sign in to comment.