On Sun, 20 May 2012 19:12:32 +0200
"Sean M. Pappalardo - D.J. Pegasus" <[email protected]> wrote:
> Despite what the help text says, at least some of the options are
> case-insensitive. I think the best and easiest option is to make sure
> all options are made case-insensitive, perhaps to include song file
> names. This should take someone all of an hour to check and change.
Yes that would work but I don't think thats the best way to go. The way
we do option parsing now should be rewritten anyway since it is done in
several places. I'd prefer something that is in one place and
informs you about typos. I've attached a small proof of concept that
does this.
best Max
/******************************************************************************
*
* file: MyValuesConstraint.h
*
* Copyright (c) 2005, Michael E. Smoot
* All rights reverved.
*
* See the file COPYING in the top directory of this distribution for
* more information.
*
* THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#ifndef TCLAP_MYVALUESCONSTRAINT_H
#define TCLAP_MYVALUESCONSTRAINT_H
#include <string>
#include <iostream>
#include <vector>
#include <tclap/Constraint.h>
#ifdef HAVE_CONFIG_H
#include <config.h>
#else
#define HAVE_SSTREAM
#endif
#if defined(HAVE_SSTREAM)
#include <sstream>
#elif defined(HAVE_STRSTREAM)
#include <strstream>
#else
#error "Need a stringstream (sstream or strstream) to compile!"
#endif
namespace TCLAP {
/**
* A Constraint that constrains the Arg to only those values specified
* in the constraint.
*/
class MyValuesConstraint : public Constraint<std::string>
{
public:
/**
* Constructor.
* \param allowed - vector of allowed values.
*/
MyValuesConstraint(std::vector<std::string>& allowed);
/**
* Virtual destructor.
*/
virtual ~MyValuesConstraint() {}
/**
* Returns a description of the Constraint.
*/
virtual std::string description() const;
/**
* Returns the short ID for the Constraint.
*/
virtual std::string shortID() const;
/**
* The method used to verify that the value parsed from the command
* line meets the constraint.
* \param value - The value that will be checked.
*/
virtual bool check(const std::string &value) const;
protected:
/**
* The list of valid values.
*/
std::vector<std::string> _allowed;
/**
* The string used to describe the allowed values of this constraint.
*/
std::string _typeDesc;
};
MyValuesConstraint::MyValuesConstraint(std::vector<std::string>& allowed)
: _allowed(allowed),
_typeDesc("")
{
for ( unsigned int i = 0; i < _allowed.size(); i++ )
{
#if defined(HAVE_SSTREAM)
std::ostringstream os;
#elif defined(HAVE_STRSTREAM)
std::ostrstream os;
#else
#error "Need a stringstream (sstream or strstream) to compile!"
#endif
os << _allowed[i];
std::string temp( os.str() );
if ( i > 0 )
_typeDesc += "|";
_typeDesc += temp;
}
}
bool MyValuesConstraint::check( const std::string &value ) const
{
size_t found = value.find_last_of(".");
//find_last_of returns npos if "." is not found
if(found == std::string::npos){
return false;
}
std::string val = value.substr(found,value.size());
if ( std::find(_allowed.begin(),_allowed.end(),val) == _allowed.end() )
return false;
else
return true;
}
std::string MyValuesConstraint::shortID() const
{
return _typeDesc;
}
std::string MyValuesConstraint::description() const
{
return _typeDesc;
}
} //namespace TCLAP
#endif
// This illustrates how to change the flag and name start strings for
// Windows, otherwise the defaults are used.
//
// Note that these defines need to happen *before* tclap is included!
//
#ifdef WINDOWS
#define TCLAP_NAMESTARTSTRING "~~"
#define TCLAP_FLAGSTARTSTRING "/"
#endif
#include <iostream>
#include <tclap/CmdLine.h>
#include <string>
#include <vector>
#include "MyValuesConstraint.h"
using namespace std;
void loadSong(string filepath){
cout << "\t"<< filepath << endl;
}
int main(int argc,char** argv){
try {
TCLAP::CmdLine cmd("For more information, see http://mixxx.org/wiki/doku.php/command_line_options", ' ', "1.11.0-alpha");
//("shortname","longname","description",bool required,"default","expected filetype")
//shortname=="" --> no shortname
TCLAP::ValueArg<string> resourcePath("","resourcePath","Top-level directory where Mixxx should look for its resource files such as MIDI mappings, overriding the default installation location. ",false,"default","file path");
cmd.add( resourcePath );
TCLAP::ValueArg<string> pluginPath("","pluginPath","Top-level directory where Mixxx shoud look for sound source plugins in addition to default locations.",false,"default","file path");
cmd.add( pluginPath );
TCLAP::ValueArg<string> locale("","locale","Use a custom locale for loading translations",false,"default","LOCALE");
cmd.add( locale );
TCLAP::SwitchArg fullScreenSwitch("f","fullScreen","Starts Mixxx in full-screen mode", cmd, false);
TCLAP::SwitchArg midiDebugSwitch("","midiDebug","Starts Mixxx in full-screen mode", cmd, false);
//we constrain UnlabeledMultiArg to these file extensions
vector <string> fileExtensions;
fileExtensions.push_back(".flac");
fileExtensions.push_back(".ogg");
fileExtensions.push_back(".mp3");
fileExtensions.push_back(".wav");
fileExtensions.push_back(".aif");
fileExtensions.push_back(".aiff");
TCLAP::MyValuesConstraint fileExtensionsVals(fileExtensions);
// UnlabeledMultiArg must be the LAST argument added!
TCLAP::UnlabeledMultiArg<string> songsArg("fileName","Load the specified music file(s) at start-up. Each must be one of the following file types: *.mp3 *.ogg *.aiff *.aif *.wav *.flac", false,&fileExtensionsVals,cmd);
// Parse the argv array.
cmd.parse( argc, argv );
// Get the value parsed by each arg.
string resPath = resourcePath.getValue();
string plugPath = pluginPath.getValue();
string loc = locale.getValue();
bool fullScreen = fullScreenSwitch.getValue();
bool midiDebug = midiDebugSwitch.getValue();
vector<string> songs = songsArg.getValue();
//output all set information
cout << "resourcePath="<<resPath<<endl;
cout << "pluginPath="<<plugPath<<endl;
cout << "locale="<<loc<<endl;
cout << "fullscreen mode ? "<<fullScreen<<endl;
cout << "midiDebug ? "<<midiDebug<<endl;
cout << "songs to be loaded in a deck:"<<endl;
for_each (songs.begin(),songs.end(),loadSong);
} catch (TCLAP::ArgException &e) { // catch any exceptions
cerr << "error: " << e.error() << " for arg " << e.argId() << endl;
}
cout << "starting mixxx" << endl;
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Get Mixxx, the #1 Free MP3 DJ Mixing software Today
http://mixxx.org
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel