Skip to content
Snippets Groups Projects
Commit c8990d05 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

pair set access

parent 270d012b
No related branches found
No related tags found
No related merge requests found
/*
* PairSetAccess.cpp
*
* Created on: 20. 9. 2014
* Author: Jan Travnicek
*/
#include "PairSetAccess.h"
#include <factory/XmlDataFactory.hpp>
#include <container/ObjectsSet.h>
#include <container/ObjectsMap.h>
#include <container/ObjectsTuple.h>
#include <container/ObjectsVector.h>
#include <container/ObjectsVariant.h>
#include <container/ObjectsPair.h>
void PairSetAccess::access ( const std::set < std::pair < alib::Object, alib::Object > > & pairSet, const std::set < PairSetSettings::Settings > & settings ) {
if ( settings.count ( PairSetSettings::Settings::FIRST ) ) {
std::set < alib::Object > res;
for ( const std::pair < alib::Object, alib::Object > & pair : pairSet )
res.insert ( pair.first );
alib::XmlDataFactory::toStdout ( res );
}
if ( settings.count ( PairSetSettings::Settings::SECOND ) ) {
std::set < alib::Object > res;
for ( const std::pair < alib::Object, alib::Object > & pair : pairSet )
res.insert ( pair.second );
alib::XmlDataFactory::toStdout ( res );
}
}
/*
* PairSetAccess.h
*
* Created on: 20. 9. 2014
* Author: Jan Travnicek
*/
#ifndef PAIR_SET_ACCESS_H_
#define PAIR_SET_ACCESS_H_
#include <core/multipleDispatch.hpp>
#include <object/Object.h>
#include "settings/PairSetSettings.h"
#include <set>
#include <pair>
class PairSetAccess {
public:
static void access ( const std::set < std::pair < alib::Object, alib::Object > > & pairSet, const std::set < PairSetSettings::Settings > & settings );
};
#endif /* PAIR_SET_ACCESS_H_ */
......@@ -20,6 +20,13 @@
#include "StringAccess.h"
#include "ExceptionAccess.h"
#include "TreeAccess.h"
#include "PairSetAccess.h"
#include <container/ObjectsSet.h>
#include <container/ObjectsPair.h>
#include <label/LabelSetLabel.h>
#include <label/LabelPairLabel.h>
 
int main ( int argc, char * argv[] ) {
try {
......@@ -89,6 +96,16 @@ int main ( int argc, char * argv[] ) {
 
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
std::vector < std::string > pairSetSettings {
PairSetSettings::stringsVector ( )
};
TCLAP::ValuesConstraint < std::string > pairSetPrintingOptionsVals ( pairSetSettings );
TCLAP::MultiArg < std::string > pairSet ( "", "pairSet", "Access components of set of pairs", false, & pairSetPrintingOptionsVals );
// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
std::vector < TCLAP::Arg * > xorlist;
xorlist.push_back ( & automaton );
xorlist.push_back ( & grammar );
......@@ -96,6 +113,7 @@ int main ( int argc, char * argv[] ) {
xorlist.push_back ( & exception );
xorlist.push_back ( & string );
xorlist.push_back ( & tree );
xorlist.push_back ( & pairSet );
cmd.xorAdd ( xorlist );
 
TCLAP::ValueArg < std::string > file ( "i", "input", "Read from file", false, "-", "file" );
......@@ -192,6 +210,35 @@ int main ( int argc, char * argv[] ) {
measurements::start ( "Accesss print", measurements::Type::MAIN );
 
TreeAccess::access ( tree, settings );
} else if ( alib::XmlDataFactory::first < std::set < std::pair < alib::Object, alib::Object > > > ( tokens ) && pairSet.isSet ( ) ) {
std::set < PairSetSettings::Settings > settings;
for ( const std::string & param : pairSet.getValue ( ) )
settings.insert ( PairSetSettings::fromString ( param ) );
std::set < std::pair < alib::Object, alib::Object > > pairSet = alib::XmlDataFactory::fromTokens < std::set < std::pair < alib::Object, alib::Object > > > ( std::move ( tokens ) );
measurements::end ( );
measurements::start ( "Accesss print", measurements::Type::MAIN );
PairSetAccess::access ( pairSet, settings );
} else if ( alib::XmlDataFactory::first < label::LabelSetLabel > ( tokens ) && pairSet.isSet ( ) ) {
std::set < PairSetSettings::Settings > settings;
for ( const std::string & param : pairSet.getValue ( ) )
settings.insert ( PairSetSettings::fromString ( param ) );
std::set < label::Label > labelSet = alib::XmlDataFactory::fromTokens < label::LabelSetLabel > ( std::move ( tokens ) ).getData ( );
std::set < std::pair < alib::Object, alib::Object > > pairSet;
for ( const label::Label & label : labelSet ) {
const label::LabelPairLabel & labelPair = dynamic_cast < const label::LabelPairLabel & > ( label.getData ( ) );
pairSet.insert ( std::make_pair ( alib::Object ( labelPair.getData ( ).first.getData ( ) ), alib::Object ( labelPair.getData ( ).second.getData ( ) ) ) );
}
measurements::end ( );
measurements::start ( "Accesss print", measurements::Type::MAIN );
PairSetAccess::access ( pairSet, settings );
} else {
throw exception::CommonException ( "Input not recognized." );
}
......
/*
* PairSetSettings.h
*
* Created on: 26. 3. 2014
* Author: Jan Travnicek
*/
#ifndef __PAIR_SET_SETTINGS_H__
#define __PAIR_SET_SETTINGS_H__
#include "SettingsHelper.h"
class PairSetEnum {
public:
enum class Settings {
FIRST, SECOND, __MAX__
};
static std::string toString ( PairSetEnum::Settings settings ) {
switch ( settings ) {
case PairSetEnum::Settings::FIRST:
return "first";
case PairSetEnum::Settings::SECOND:
return "second";
case PairSetEnum::Settings::__MAX__:
throw exception::CommonException ( "Invalid enumeration" );
}
throw exception::CommonException ( "Invalid enumeration" );
}
};
class PairSetSettings : public PairSetEnum, public EnumClassHelper < PairSetEnum > {
};
#endif /* __PAIR_SET_SETTINGS_H__ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment