Skip to content

Commit

Permalink
'-P' property ops executed in chain as expected, rather than at end
Browse files Browse the repository at this point in the history
  • Loading branch information
whatdoineed2do/Ray committed Jun 24, 2023
1 parent 63834a7 commit 32c2bec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/Ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ namespace AudioTag
}
}

OpNested::~OpNested()
{
for (auto i : _ops) {
delete i;
}
}

void OpNested::_execute(File& f_, bool verbose_) const
{
for (const auto i : _ops) {
i->execute(f_, _verbose);
}
}

void OpListTags::_execute(File& f_, bool verbose_) const
{
std::cout << f_;
Expand Down
13 changes: 11 additions & 2 deletions src/Ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ struct _OpWR : public Op
_OpWR(_OpWR&& rhs_) = default;
};

using _Ops = std::list<const Op*>;

class Ops
{
public:
using _Ops = std::list<const Op*>;

Ops() : _readonly(true) { }
~Ops();

Expand Down Expand Up @@ -92,6 +91,16 @@ class Ops
_Ops _ops;
};

struct OpNested : public _OpWR
{
OpNested() : _OpWR("nested tags") { }
~OpNested();

_Ops _ops;
void _execute(File& f_, bool verbose_) const override;
};



////////////////////////////////////////////////////////////////////////////////

Expand Down
16 changes: 13 additions & 3 deletions src/audiotag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ int main(int argc, char *argv[])
TagLib::String::Type enc = TagLib::String::UTF8;

AudioTag::Ops ops;
// ownership will be xfr'd to 'ops' if non-null
AudioTag::OpNested* propops = nullptr;

// we do this as we dont want to do anything wihtin taglib that deals with mbs
std::list<char*> propargs;
Expand Down Expand Up @@ -364,7 +366,15 @@ int main(int argc, char *argv[])
case 'g': AudioTag::_addupdop(opts.iop, opts.toi, opts.iflds, ops); opts.iflds.genre = optarg; break;
case 's': AudioTag::_addupdop(opts.iop, opts.toi, opts.iflds, ops); opts.iflds.rating = optarg; break;

case 'P': propargs.push_back(optarg); break;
case 'P':
{
if (propops == nullptr) {
propops = new AudioTag::OpNested();
ops.add(propops);
}
propargs.push_back(optarg);
} break;

case 255: opts.propertiesTok = optarg; break;

case 'w':
Expand Down Expand Up @@ -493,7 +503,7 @@ int main(int argc, char *argv[])
}
AUDIOTAG_NOTICE_VERBOSE("using locale=" << l);

std::for_each(propargs.cbegin(), propargs.cend(), [&ops, &opts](char* optarg) {
std::for_each(propargs.cbegin(), propargs.cend(), [&ops, &opts, &propops](char* optarg) {
AudioTag::OpPropertyTags::Map m;

char* pc = NULL;
Expand All @@ -517,7 +527,7 @@ int main(int argc, char *argv[])

m.insert(std::make_pair(prop, value));
}
ops.add(new AudioTag::OpPropertyTags(opts.toi, opts.iflds, m) );
propops->_ops.push_back(new AudioTag::OpPropertyTags(opts.toi, opts.iflds, m) );
});


Expand Down

0 comments on commit 32c2bec

Please sign in to comment.