diff --git a/AUTHORS.txt b/AUTHORS.txt new file mode 100644 index 0000000..1978f9b --- /dev/null +++ b/AUTHORS.txt @@ -0,0 +1,121 @@ +Credits +======= + +The following people have contributed to libmusicbrainz5 + Andy Hawkins + - Update from libmusicbrainz4 + +The following people have contributed to libmusicbrainz4 + Andy Hawkins + - Created the C++ implementation (based on libmusicbrainz3) and the + C bindings. + - Updated examples + + Lukáš Lalinský + - Advised on documentation and examples required. + +The following people have contributed to libmusicbrainz3: + + Lukáš Lalinský + - Created the C++ implementation (based on python-musicbrainz2) and the + C bindings. + - CppUnit test suite. + + Matthias Friedrich + - Design and documentation for the original Python implementation. + - Autotools/libtool build system. + + +The following people have contributed to the original libmusicbrainz2: + + Adam Wozniak + - original CD-ROM TOC code + + Ben Wong + - support for SGI Irix + + Bert Vermeulen + - improved endian support + + Johnny Tevessen + - brought in autoconf support + + Jukka Poikolainen + - brought in Win32 TOC code + + Marc E E van Woerkom + - support for FreeBSD, NetBSD, OpenBSD, Solaris and Win32/Cygwin + + Mark A Mankins + - improved Netscape support + + Rick Bradey + - support Linux 2 dot 2 kernel and -l command line option + + Robert Kaye + - hacked it together in the first place + - support for Win32/MS VC++ + - coordination of the CD Index/MusicBrainz project + - move the CD Index over to MusicBrainz + - All the RDF/XML work in the client library + + Stephen van Egmond + - support for BeOS + + Winston Chang + - support for Solaris + + David W. Gray + - cmd.dsp and added support for exporting the C++ interface in Win32 + + Alexey Zakhlestine + - Supplied a patch compile this lib under BeOS + + Brian Reichert + - Supplied a patch compile this lib under FreeBSD-4.3 + + Erik Gavert + - A small browser launch patch. + + Patrick Mauritz + - A patch to allow building mb_client from a different directory. + + Chris Gray + - A patch to keep the trm stuff from crashing. + + Myers Carpenter + - Added track duration queries to queries.h + - Added all the python and debian support + + Matthias Friedrich + - Provided a patch for fixing NetBSD cdrom TOC code + + Sander van Zoest + - Wrote the perl bindings + + Philippe Normand + - Supplied a couple of minor patches to the new build system + + Andreas Rottmann + - Improve build system and debian support + + Tim Van Holder + - Supplied a patch to fix some compile issues under cygwin + + Clayton O'Neill + - Improved the mp3 sanity checking code in the lib/bitzi/mp3.c + + Juergen Kreileder + - Supplied minimal patch for making sure that mb_client still works + when CDO_CHECK_TYPE is defined. + + Martin Michlmayr + - Supplied a number of patches that fixed minor issues with the reintegrated + python bindings + + Ryan McCabe + - Supplied a patch to fix pointer issues in comhttpsocket.cpp and + comsocket.cpp on 64-bit architectures. + +-- + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..384cb65 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,52 @@ +cmake_minimum_required(VERSION 2.6) + +PROJECT(libmusicbrainz5) +SET(PROJECT_VERSION 5.1.0) + +# 1. If the library source code has changed at all since the last update, then increment revision. +# 2. If any interfaces have been added, removed, or changed since the last update, increment current, and set revision to 0. +# 3. If any interfaces have been added since the last public release, then increment age. +# 4. If any interfaces have been removed since the last public release, then set age to 0. +SET(musicbrainz5_SOVERSION_CURRENT 1) +SET(musicbrainz5_SOVERSION_REVISION 0) +SET(musicbrainz5_SOVERSION_AGE 0) + +MATH(EXPR musicbrainz5_SOVERSION_MAJOR "${musicbrainz5_SOVERSION_CURRENT} - ${musicbrainz5_SOVERSION_AGE}") +MATH(EXPR musicbrainz5_SOVERSION_MINOR "${musicbrainz5_SOVERSION_AGE}") +MATH(EXPR musicbrainz5_SOVERSION_PATCH "${musicbrainz5_SOVERSION_REVISION}") + +SET(musicbrainz5_VERSION ${musicbrainz5_SOVERSION_MAJOR}.${musicbrainz5_SOVERSION_MINOR}.${musicbrainz5_SOVERSION_PATCH}) +SET(musicbrainz5_SOVERSION ${musicbrainz5_SOVERSION_MAJOR}) + +SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) +FIND_PACKAGE(Neon REQUIRED) +FIND_PACKAGE(LibXml2 REQUIRED) + +SET(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)") +SET(EXEC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Installation prefix for executables and object code libraries" FORCE) +SET(BIN_INSTALL_DIR ${EXEC_INSTALL_PREFIX}/bin CACHE PATH "Installation prefix for user executables" FORCE) +SET(LIB_INSTALL_DIR ${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX} CACHE PATH "Installation prefix for object code libraries" FORCE) +SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Installation prefix for C header files" FORCE) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libmusicbrainz5.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libmusicbrainz5.pc) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) + +FILE(GLOB headers ${CMAKE_CURRENT_SOURCE_DIR}/include/musicbrainz5/*.h) +INSTALL(FILES ${headers} ${CMAKE_CURRENT_BINARY_DIR}/include/musicbrainz5/mb5_c.h DESTINATION ${INCLUDE_INSTALL_DIR}/musicbrainz5) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmusicbrainz5.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) + +ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(tests) +ADD_SUBDIRECTORY(examples) + +ADD_CUSTOM_TARGET(docs + doxygen +) + +ADD_DEPENDENCIES(docs src_gen) + +ADD_CUSTOM_TARGET(dist + rm -rf "libmusicbrainz-${PROJECT_VERSION}" + COMMAND git archive --prefix="libmusicbrainz-${PROJECT_VERSION}/" master | gzip -9 > libmusicbrainz-${PROJECT_VERSION}.tar.gz +) diff --git a/COPYING.txt b/COPYING.txt new file mode 100644 index 0000000..5ab7695 --- /dev/null +++ b/COPYING.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/Doxyfile.cmake b/Doxyfile.cmake new file mode 100644 index 0000000..f1b69c7 --- /dev/null +++ b/Doxyfile.cmake @@ -0,0 +1,20 @@ +PROJECT_NAME = "${PROJECT_NAME}" +PROJECT_NUMBER = ${PROJECT_VERSION} +HTML_OUTPUT = docs +GENERATE_LATEX = NO +GENERATE_MAN = NO +GENERATE_RTF = NO +CASE_SENSE_NAMES = NO +INPUT = include/musicbrainz5 +EXCLUDE = include/musicbrainz5/xmlParser.h +JAVADOC_AUTOBRIEF = YES +EXTRACT_ALL = YES +EXTRACT_STATIC = YES +SHOW_USED_FILES = NO +GENERATE_TREEVIEW = YES +SHOW_INCLUDE_FILES = NO +FULL_PATH_NAMES = NO +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = YES +PREDEFINED = LIBMB5_DEPRECATED(f)= +REPEAT_BRIEF = NO diff --git a/INSTALL.txt b/INSTALL.txt new file mode 100644 index 0000000..a190ce0 --- /dev/null +++ b/INSTALL.txt @@ -0,0 +1,72 @@ +================================================ + Installation of the MusicBrainz Client Library +================================================ + +The instructions in this file should help you to build and install the +MusicBrainz client library from source on your system. + +Dependencies +============ + +Before you start, make sure you have installed following libraries: + + * Neon -- HTTP client library + http://www.webdav.org/neon/ + +Building +======== + +Once you have installed all dependencies, you can compile the +library: + + cmake . + make + +And to install the built library run (as root): + + make install + +Cross Compiling +=============== + +Cross compiling is a little more involved due to the automatic generation +of the C interface source files. Your cross compilation environment will +need appropriate headers and libraries for any dependencies. + +First set up a toolchain file as specified here: + + http://www.cmake.org/Wiki/CMake_Cross_Compiling#The_toolchain_file + +Then build natively to generate the appropriate make-c-interface file + +mkdir build-native +cd build-native +cmake .. +make + +Finally, cross compile, telling cmake where to find your toolchain and the +make-c-interface binary: + +mkdir build-cross +cd build-cross +cmake -DCMAKE_TOOLCHAIN_FILE=~/powerpc-cross \ + -DIMPORT_EXECUTABLES=../build-native/ImportExecutables.cmake .. +make + +CMake Options +============= + +By default, the library will be installed to /usr/local. You can change this +using the CMAKE_INSTALL_PREFIX option, for example: + + cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr . + +To disable debug messages, change the build type: + + cmake -DCMAKE_BUILD_TYPE=Release . + +For overview of all available options use: + + cmake -L . + +or use a GUI. See http://www.cmake.org/HTML/RunningCMake.html for more details. diff --git a/NEWS.txt b/NEWS.txt new file mode 100644 index 0000000..36724e6 --- /dev/null +++ b/NEWS.txt @@ -0,0 +1,257 @@ +Changes for libmusicbrainz 5.1.0 +-------------------------------- + + - Fix LMB-33 - Handle 'ended' element in 'relation' + - Fix LMB-34 - Remove non-free XML parser and replace with libxml2 + - Add support for cross-compilation and building out of tree + +Changes for libmusicbrainz 5.0.1 +-------------------------------- + + - Fix LMB-32 - Correctly ignore unrecognised nodes + - Don't compile using -Werror when building from tarball + +Changes for libmusicbrainz 5.0.0 +-------------------------------- + + - Deprecated functions removed + +Changes for libmusicbrainz 4.0.3 +-------------------------------- + + - Fix LMB-32 - Correctly ignore unrecognised nodes + - Don't compile using -Werror when building from tarball + +Changes for libmusicbrainz 4.0.2 +-------------------------------- + + - Add extra attributes to Alias + - Add IPI lists to Artist and Label + - Add 'Ended' to Lifespan + - Add PrimaryType and SecondaryTypeList to ReleaseGroup + - Add text based track number to Track + - Add ISWC list to Work + - Debug builds show queries and responses on stderr + - Documentation updates + +Changes for libmusicbrainz 4.0.1 +-------------------------------- + + - Fixed bug LMB-30 - Unable to access all relation lists on objects with + multiple relation lists + - Fixed bug LMB-31 - mb_relationlist_get_targettype always returns + "target-type" + +Changes for libmusicbrainz 4.0.0 +-------------------------------- + + - Added support for collection list being returned as part of a release + +Changes for libmusicbrainz 4.0.0 beta 2 +--------------------------------------- + + - Restructured for easier maintenance + - List class interface rewritten + - Added handling of extension elements and attributes + - Add handling of all list attributes and elements + - C interface is now automatically generated from an XML file template + +N.B. The API has changed with regard to lists since beta 1. Any +applications are likely to need rewriting to take account of this +and will certainly need to be recompiled due to the ABI change. + +Changes for libmusicbrainz 4.0.0 beta 1 +--------------------------------------- + + - Rewritten from scratch for NGS + +Changes for libmusicbrainz 3.0.4 +-------------------------------- + + - Fixed parsing of release-group lists. (#5891) + - Fixed compilation on the Sun Studio compiler (#5801) + - Added mb_disc_free() to the C bindings. (#5885) + +Changes for libmusicbrainz 3.0.3 +-------------------------------- + + - Use Requires.private instead of Requires for dependencies in + libmusicbrainz3.pc + - Support for reading and submitting ISRCs + - Support for reading ratings for all entity type + - Full release group and label support + - C wrappers for extractFragment and extractUuid + - Support for filtering by any Lucene query + +Changes for libmusicbrainz 3.0.2 +-------------------------------- + + - Added mb_track_get_artist to the C API. (#3817) + - Fix incorrect string comparision in the XML parser code. (#3614) + - Fix compilation on GCC 4.3 (#3490 and #3613, patch by Ross Burton + and "dirtyepic") + +Changes for libmusicbrainz 3.0.1 +-------------------------------- + + - Fixed mb_query_get_tracks function name in mb_c.h. + - Detect correctly installed libdiscid in src/disc.cpp. + - Support for releaseEvents in ArtistIncludes. (#2974) + - Support for catalog numbers and barcodes. + - Added Release::TYPE_PSEUDO_RELEASE. + - Added mb_release_get_artist to the C API, patch by Ross Burton. + +Changes for libmusicbrainz 3.0.0 (2007-05-12) +--------------------------------------------- + + - Use CMake as the only build system. + +Changes for libmusicbrainz 3.0.0beta3 +------------------------------------- + + - C bindings for artist/release/track collections. + - New cdlookup_c.c example. + +Changes for libmusicbrainz 3.0.0beta2 +------------------------------------- + + - Fixed MusicBrainz::extractUuid for non-artist IDs. + - Implementation of release types. + - Implementation of release lists on track level. + - New cdlookup.cpp example. + +Changes for libmusicbrainz 3.0.0beta1 +------------------------------------- + + - Rewritten from scratch, libmusicbrainz now uses the new XML web service. + - New object oriented API in C++ based on python-musicbrainz2, with + GLib-style C bindings. + + +****************************************************************************** +****************************************************************************** +****************************************************************************** + +Changes for libmusicbrainz 2.1.2 +------------------------------------- + + - Since expat is now installed on most systems we removed our internal copy + and now rely on the system installed version. + - Juergen Kreileder Supplied minimal patch for making sure that mb_client still works + when CDO_CHECK_TYPE is defined + - Fixed a C++ style variable declaration inside the album.c C module + - On linux the cdrom drive is now opened in non-blocking mode + - Fixed bug #834541: Tagger setting track no. is 0 - possibly due to trm mixup? + - Added support for parsing AdvancedRelationship date. Also added new + getrels.c example program. + - Re-added the python bindings and changed the binding's version number to + match the version of this lib. + - Fixed bug # 1224562: libmusicbrainz fails to post large RDF. This fixes + problems looking up CDs with large numbers of tracks. (This was also + bug # 725701 ignores blank tracks) + + The included perl bindings had the following changes: + - Updated bindings to match up to 2.1.1 + - Fixed int size cast warning + - Fixed #6431: unmatched bootstrap parameter + - Updated req for MusicBrainz::Queries to 0.07 + + The included python bindings had the following changes: + - Fixed #957393: Python Bindings type bug + - Fixed #1206514: Python bindings to select release not up-to-date + +Changes for libmusicbrainz 2.1.1 +------------------------------------- + + - Return special TRMs for special conditions for TRM generation: + c457a4a8-b342-4ec9-8f13-b6bd26c0e400 -- Sigserver busy and overloaded + f9809ab1-2b0f-4d78-8862-fb425ade8ab9 -- Source file is too short to calculate TRM + 7d154f52-b536-4fae-b58b-0666826c2bac -- File is slience + + - If the TRM signature server becomes overloaded, it will now start + returning HTTP 503 error codes and the TRM generator will catch that + and return the Sigserver busy TRM shown above. + + +Changes for libmusicbrainz 2.1.0 +------------------------------------- + + - moved the python bindings into a new seperate project + - rewrote the mp3 duration detection code to be more robust + by making it vastly easier. In the process the bitzi + related code has been tossed. This should make the libary + smaller and the mp3 duration checking faster. + - Due to the bitzi code being removed, the SHA1 and Bitprint + related functions have been removed. + - Added query items for Release Dates/Countries, Amazon Asins and Amazon cover art URLs + - Move include files into include/musicbrainz so that the example + files will compile outside of the libmusicbrainz client + source tree. + +Changes for libmusicbrainz 2.0.2 +------------------------------------- + + - Added support for Mac OS X + - Improved build system + - Added build files for Visual Studio .NET (VC7) + +Changes for libmusicbrainz 2.0.1 +------------------------------------- + - Added patch for pkgconfig + - Threading handled correctly in python wrapper + - New perl bindings + - Had client use HTTP 1.0 rather than HTTP 1.1 + + +Changes for libmusicbrainz 2.0.0 +------------------------------------- + + - Removed some spurious C++ comments from mb_c.h + - Fixes and improvements to the python language bindings and tools + - Updated NetBSD cdrom reading code + +Changes for libmusicbrainz 2.0.0-pre4 +------------------------------------- + + - Two new functions have been added: + mb_GetFragmentFromURL - Retrieve a fragment from a URI + mb_GetOrdinalFromList - Retrieve a list ordinal from a given list -- + this is sometimes needed to determine the + location of an item in a list. (e.g. a track in + an album in order to find the track number) + - The TRM code has been updated for TRM B#er. + - New queries have been added to queries.h in order to support the improved + FileLookupInterface. + - The client library now uses the mm-2.1 and mq-1.1 namespaces. + - The client library will now be referred to as libmusicbrainz + +Changes from version 1.1.0 to version 2.0.0-pre1 +------------------------------------------------ + + - Added authentication support + - Added new queries + - Added support for submitting client version to the server + during TRM submits + - Updated client code for TRM B#er + +Changes from version 1.0.1 to version 1.1.0 +------------------------------------------- + + - Fixed an OpenBSD 3.0 compile problem + - Updated libtool version to 1.4.2 in hopes to get it to build on OSX. + - Added MBQ_Quick queries to support the MB Tagger + - Fixed a bug in the TRM generation that caused different TRMs to be + generated for subsequent runs on the same file. + +Changes from version 1.0.0 to version 1.0.1 +------------------------------------------- + + - Fixed the multi drive support under windows. + - Added support for setting the depth of a query via GET methods. + - Added SetDebug() function that allows the caller to set the + debug mode. In debug mode the library will print the server + URL, query and responses to stdout. + - Fixed a few crash bugs in the bitzi id3/mp3 metadata code + - Changed the bitzi plugin manager to not load plugins, in order + to avoid the unecessary dependency on dlopen/dlsym/dlclose. + - Removed a bunch of generates files from the CVS archive. diff --git a/README.md b/README.md new file mode 100644 index 0000000..53da30b --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +============================ + MusicBrainz Client Library +============================ + +Documentation +------------- + +To get started quickly have a look at the examples directory which +contains various sample programs. API documentation can be generated +using [Doxygen] (http://www.stack.nl/~dimitri/doxygen/). The online version of +the API documentation can be found at: + + http://metabrainz.github.com/libmusicbrainz/ + +Compiling and Linking +--------------------- + +This package provides a pkg-config script that returns the necessary compiler +and linker flags, as well as the version number. To build a small sample +program one would use: + + g++ -o test_app test_app.cpp `pkg-config libmusicbrainz5 --cflags --libs` + +If you don't want/can't use pkg-config and you are using the C API, make sure +you link in the C++ standard library: + + gcc -o test_app test_app.c -lmusicbrainz5 -lm -lstdc++ + +Contact +------- + +If you have any questions about this library, feel free to ask on the +MusicBrainz development mailing list: + + http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel + +Please submit bug reports to the MusicBrainz bug tracking system: + + http://tickets.musicbrainz.org/browse/LMB + +You can find out more about the MusicBrainz project by visiting its +site: + + http://musicbrainz.org/ diff --git a/cmake/modules/FindLibXml2.cmake b/cmake/modules/FindLibXml2.cmake new file mode 100644 index 0000000..00ee0e2 --- /dev/null +++ b/cmake/modules/FindLibXml2.cmake @@ -0,0 +1,18 @@ +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PKG_LIBXML2 libxml-2.0) + +FIND_PATH(LIBXML2_INCLUDE_DIR libxml/tree.h + PATHS + ${PKG_LIBXML2_INCLUDE_DIRS} + /usr/include + /usr/local/include +) + +FIND_LIBRARY(LIBXML2_LIBRARIES xml2 + ${PKG_LIBXML2_LIBRARY_DIRS} + /usr/lib + /usr/local/lib +) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR) diff --git a/cmake/modules/FindNeon.cmake b/cmake/modules/FindNeon.cmake new file mode 100644 index 0000000..e550af1 --- /dev/null +++ b/cmake/modules/FindNeon.cmake @@ -0,0 +1,19 @@ +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE(PkgConfig) +PKG_CHECK_MODULES(PKG_NEON neon) + +FIND_PATH(NEON_INCLUDE_DIR ne_request.h + PATHS + ${PKG_NEON_INCLUDE_DIRS} + /usr/include + /usr/local/include + PATH_SUFFIXES neon +) + +FIND_LIBRARY(NEON_LIBRARIES neon + ${PKG_NEON_LIBRARY_DIRS} + /usr/lib + /usr/local/lib +) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Neon DEFAULT_MSG NEON_LIBRARIES NEON_INCLUDE_DIR) diff --git a/config.h.cmake b/config.h.cmake new file mode 100644 index 0000000..5a87e3f --- /dev/null +++ b/config.h.cmake @@ -0,0 +1,7 @@ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#define PACKAGE "${PROJECT_NAME}" +#define VERSION "${PROJECT_VERSION}" + +#endif diff --git a/developer/make-release.sh b/developer/make-release.sh new file mode 100644 index 0000000..a16517d --- /dev/null +++ b/developer/make-release.sh @@ -0,0 +1,136 @@ +#!/bin/bash + +DoIt() +{ + SRCREPO="git://github.com/metabrainz/libmusicbrainz.git" + PUSHURL="git@github.com:metabrainz/libmusicbrainz.git" + + #Enable these 4 lines for local access only + #rm -rf $SRCDIR/../flactag.git-local + #git init --bare $SRCDIR/../libmusicbrainz.git-local + #SRCREPO="/home/andy/software/libmusicbrainz.git" + #PUSHURL="$SRCDIR/../libmusicbrainz.git-local" + + echo "Entering work directory" + cd $WORKDIR || return 1 + + echo "Cloning repository" + git clone --quiet $SRCREPO . || return 1 + + echo "Setting remote push URL" + git remote set-url origin --push $PUSHURL || return 1 + + echo "Running cmake" + cmake . >/dev/null || return 1 + + echo "Making tarball" + make dist >/dev/null || return 1 + + echo "Checking for tarball $TARBALL" + [ -f $TARBALL ] || return 1 + + echo "Copying tarball to $EXTRACTDIR" + cp $TARBALL $EXTRACTDIR || return 1 + + echo "Entering extract directory" + cd $EXTRACTDIR || return 1 + + echo "Extracting tarball" + tar xzf $TARBALL || return 1 + + echo "Building" + cd libmusicbrainz-$VERSION || return 1 + cmake . > /dev/null || return 1 + make $MAKEARGS > /dev/null || return 1 + + echo "Install test" + mkdir "$EXTRACTDIR/install-test" | return 1 + make DESTDIR="$EXTRACTDIR/install-test" install > /dev/null || return 1 + + echo "Installed binary test" + ldd "$EXTRACTDIR/install-test/usr/local/lib/libmusicbrainz5.so" > /dev/null || return 1 + + MD5=`md5sum $WORKDIR/$TARBALL | cut -d' ' -f1` + SHA224=`sha224sum $WORKDIR/$TARBALL | cut -d' ' -f1` + + MAILTEXT="New release of libmusicbrainz $VERSION is attached:\n\nMD5: $MD5\nSHA224: $SHA224" + + if [ "$TAGANDPUSH" -eq "1" ] + then + echo "Tagging work repository" + + cd $WORKDIR + git tag -s -u $KEYID -m "Tag release $VERSION" -m "MD5 checksum: $MD5" -m "SHA224 checksum: $SHA224" $TAGNAME || return 1 + + COMMIT=`git show $TAGNAME | grep commit | cut -d ' ' -f 2` + + echo "Pushing new tag to origin" + git push origin master --tags || return 1 + + MAILTEXT="$MAILTEXT\nCOMMIT: $COMMIT\n" + + if ! echo -e "$MAILTEXT" | mutt -s "libmusicbrainz release" -a $TARBALL -- $KEYID + then + (echo -e "$MAILTEXT"; uuencode $TARBALL $TARBALL) | Mail -s "libmusicbrainz release" $KEYID + fi + + git --no-pager show --raw $TAGNAME + + echo + fi + + echo -e "$MAILTEXT" + return 0 +} + +VALIDARGS=0 +TAGANDPUSH=0 + +if [ "$#" -eq "2" -o "$#" -eq "3" ] +then + VALIDARGS=1 + + #rm -rf /tmp/tmp.* + + if [ "$#" -eq "3" ] + then + if [ "x$3" = "x--tag-and-push" ] + then + TAGANDPUSH=1 + else + VALIDARGS="0" + fi + fi +fi + +if [ "$VALIDARGS" -eq "1" ] +then + VERSION="$1" + KEYID="$2" + + SRCDIR=`pwd` + TARBALL="libmusicbrainz-$VERSION.tar.gz" + TAGNAME="test-$VERSION" + + #Comment this line out to do test pushes + TAGNAME="release-$VERSION" + + WORKDIR=`mktemp -d` + EXTRACTDIR=`mktemp -d` + + echo "Using directories $WORKDIR and $EXTRACTDIR" + + DoIt + RET=$? + + if [ "$RET" -eq "1" -o "$TAGANDPUSH" -eq "1" ] + then + rm -rf $WORKDIR + else + echo "Files remain in $WORKDIR" + fi + + rm -rf $EXTRACTDIR +else + echo "Usage: $0 version keyid [ --tag-and-push ]" +fi diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..bdcc991 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,27 @@ +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_BINARY_DIR}/../include + ${LIBXML2_INCLUDE_DIR} +) +LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES} ${LIBXML2_LIBRARIES}) + +ADD_EXECUTABLE(cdlookup cdlookup.cc) +ADD_EXECUTABLE(cdlookup_c cdlookup_c.c) +ADD_EXECUTABLE(search search.cc) +ADD_EXECUTABLE(search_c search_c.c) +ADD_EXECUTABLE(collections collections.cc) + +IF(CMAKE_COMPILER_IS_GNUCXX) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors") + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) +ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +IF(CMAKE_COMPILER_IS_GNUCC) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic-errors") + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) +ENDIF(CMAKE_COMPILER_IS_GNUCC) + diff --git a/examples/cdlookup.cc b/examples/cdlookup.cc new file mode 100644 index 0000000..c8b2cc0 --- /dev/null +++ b/examples/cdlookup.cc @@ -0,0 +1,171 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include + +#include "musicbrainz5/Query.h" +#include "musicbrainz5/Medium.h" +#include "musicbrainz5/MediumList.h" +#include "musicbrainz5/ReleaseGroup.h" +#include "musicbrainz5/Track.h" +#include "musicbrainz5/TrackList.h" +#include "musicbrainz5/Recording.h" +#include "musicbrainz5/Disc.h" +#include "musicbrainz5/HTTPFetch.h" +#include "musicbrainz5/Release.h" + +int main(int argc, const char *argv[]) +{ + if (argc==2) + { + std::string DiscID=argv[1]; + + MusicBrainz5::CQuery Query("cdlookupexample-1.0"); + + std::cout << "Library version: '" << Query.Version() << "'" << std::endl; + + try + { + MusicBrainz5::CMetadata Metadata=Query.Query("discid",DiscID); + if (Metadata.Disc() && Metadata.Disc()->ReleaseList()) + { + MusicBrainz5::CReleaseList *ReleaseList=Metadata.Disc()->ReleaseList(); + + std::cout << "Found " << ReleaseList->NumItems() << " release(s)" << std::endl; + + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CRelease *Release=ReleaseList->Item(count); + + std::cout << "Basic release: " << std::endl << (*Release) << std::endl; + + //The releases returned from LookupDiscID don't contain full information + + MusicBrainz5::CQuery::tParamMap Params; + Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits"; + + std::string ReleaseID=Release->ID(); + + MusicBrainz5::CMetadata Metadata2=Query.Query("release",ReleaseID,"",Params); + if (Metadata2.Release()) + { + MusicBrainz5::CRelease *FullRelease=Metadata2.Release(); + + //However, these releases will include information for all media in the release + //So we need to filter out the only the media we want. + + MusicBrainz5::CMediumList MediaList=FullRelease->MediaMatchingDiscID(DiscID); + + if (0!=MediaList.NumItems()) + { + if (FullRelease->ReleaseGroup()) + std::cout << "Release group title: '" << FullRelease->ReleaseGroup()->Title() << "'" << std::endl; + else + std::cout << "No release group for this release" << std::endl; + + std::cout << "Found " << MediaList.NumItems() << " media item(s)" << std::endl; + + for (int count=0;countTitle() << "', position " << Medium->Position() << std::endl; + + MusicBrainz5::CTrackList *TrackList=Medium->TrackList(); + if (TrackList) + { + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CTrack *Track=TrackList->Item(count); + MusicBrainz5::CRecording *Recording=Track->Recording(); + + if (Recording) + std::cout << "Track: " << Track->Position() << " - '" << Recording->Title() << "'" << std::endl; + else + std::cout << "Track: " << Track->Position() << " - '" << Track->Title() << "'" << std::endl; + } + } + } + } + } + } + } + } + + catch (MusicBrainz5::CConnectionError& Error) + { + std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CTimeoutError& Error) + { + std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CAuthenticationError& Error) + { + std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CFetchError& Error) + { + std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CRequestError& Error) + { + std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CResourceNotFoundError& Error) + { + std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + } + else + { + std::cerr << "Usage: " << argv[0] << " discid" << std::endl; + } + + return 0; +} diff --git a/examples/cdlookup_c.c b/examples/cdlookup_c.c new file mode 100644 index 0000000..adfdb75 --- /dev/null +++ b/examples/cdlookup_c.c @@ -0,0 +1,230 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id: Lifespan.cc 13211 2012-07-20 16:15:03Z adhawkins $ + +----------------------------------------------------------------------------*/ + +#include +#include +#include + +#include "musicbrainz5/mb5_c.h" + +int main(int argc, const char *argv[]) +{ + if (argc==2) + { + const char *DiscID=argv[1]; + + Mb5Query Query=mb5_query_new("cdlookupcexample-1.0",NULL,0); + if (Query) + { + Mb5Metadata Metadata1=mb5_query_query(Query,"discid",DiscID,"",0,NULL,NULL); + char ErrorMessage[256]; + + tQueryResult Result=mb5_query_get_lastresult(Query); + int HTTPCode=mb5_query_get_lasthttpcode(Query); + + mb5_query_get_lasterrormessage(Query,ErrorMessage,sizeof(ErrorMessage)); + printf("Result: %d\nHTTPCode: %d\nErrorMessage: '%s'\n",Result,HTTPCode,ErrorMessage); + + if (Metadata1) + { + Mb5Disc Disc=mb5_metadata_get_disc(Metadata1); + if (Disc) + { + Mb5ReleaseList ReleaseList=mb5_disc_get_releaselist(Disc); + if (ReleaseList) + { + /* + *if we want to keep an object around for a while, we can + *clone it. We are now responsible for deleting the object + */ + + Mb5ReleaseList CloneReleaseList=mb5_release_list_clone(ReleaseList); + int ThisRelease=0; + + printf("Found %d release(s)\n",mb5_release_list_size(ReleaseList)); + + for (ThisRelease=0;ThisReleaseAllocSize) + { + MediumTitle=realloc(MediumTitle,RequiredSize+1); + mb5_medium_get_title(Medium,MediumTitle,RequiredSize+1); + } + + printf("Found media: '%s', position %d\n",MediumTitle,mb5_medium_get_position(Medium)); + + if (TrackList) + { + int ThisTrack=0; + + for (ThisTrack=0;ThisTrack. + + $Id$ + +----------------------------------------------------------------------------*/ + +#include + +#include "musicbrainz5/Query.h" +#include "musicbrainz5/Collection.h" +#include "musicbrainz5/CollectionList.h" +#include "musicbrainz5/HTTPFetch.h" + +void ListCollection(MusicBrainz5::CQuery& Query, const std::string& CollectionID) +{ + MusicBrainz5::CMetadata Metadata=Query.Query("collection",CollectionID,"releases"); + std::cout << Metadata << std::endl; +} + +int main(int argc, const char *argv[]) +{ + MusicBrainz5::CQuery Query("collectionexample-1.0","test.musicbrainz.org"); + + if (argc>1) + { + if (argc>1) + Query.SetUserName(argv[1]); + + if (argc>2) + Query.SetPassword(argv[2]); + + try + { + MusicBrainz5::CMetadata Metadata=Query.Query("collection"); + MusicBrainz5::CCollectionList *CollectionList=Metadata.CollectionList(); + if (CollectionList) + { + if (0!=CollectionList->NumItems()) + { + MusicBrainz5::CCollection *Collection=CollectionList->Item(0); + std::cout << "Collection ID is " << Collection->ID() << std::endl; + + ListCollection(Query,Collection->ID()); + + std::vector Releases; + Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); + Releases.push_back("f6335672-c521-4129-86c3-490d20533e08"); + bool Ret=Query.AddCollectionEntries(Collection->ID(),Releases); + + std::cout << "AddCollectionEntries returns " << std::boolalpha << Ret << std::endl; + + ListCollection(Query,Collection->ID()); + + Releases.clear(); + Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); + Ret=Query.DeleteCollectionEntries(Collection->ID(),Releases); + + std::cout << "DeleteCollectionEntries returns " << std::boolalpha << Ret << std::endl; + + ListCollection(Query,Collection->ID()); + } + else + std::cout << "No collections found" << std::endl; + } + } + + catch (MusicBrainz5::CConnectionError& Error) + { + std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CTimeoutError& Error) + { + std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CAuthenticationError& Error) + { + std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CFetchError& Error) + { + std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CRequestError& Error) + { + std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CResourceNotFoundError& Error) + { + std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + } + else + { + std::cout << "Usage: " << argv[0] << " username [password]" << std::endl << std::endl << + "Note that this example uses test.musicbrainz.org by default." << std::endl << + "You may need to create an account there." << std::endl; + } + + + return 0; +} diff --git a/examples/search.cc b/examples/search.cc new file mode 100644 index 0000000..bee827f --- /dev/null +++ b/examples/search.cc @@ -0,0 +1,116 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include + +#include "musicbrainz5/Query.h" +#include "musicbrainz5/HTTPFetch.h" + +/* For further information, see the web service search documentation: + * + * http://wiki.musicbrainz.org/Text_Search_Syntax + */ + +void DoSearch(const std::string& Entity, const std::string Search) +{ + MusicBrainz5::CQuery Query("queryexample-1.0"); + + MusicBrainz5::CQuery::tParamMap Params; + Params["query"]=Search; + Params["limit"]="10"; + + try + { + MusicBrainz5::CMetadata Metadata=Query.Query(Entity,"","",Params); + + std::cout << "First 10 " << Entity << "s matching: " << Search << std::endl << Metadata << std::endl; + } + + catch (MusicBrainz5::CConnectionError& Error) + { + std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CTimeoutError& Error) + { + std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CAuthenticationError& Error) + { + std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CFetchError& Error) + { + std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CRequestError& Error) + { + std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } + + catch (MusicBrainz5::CResourceNotFoundError& Error) + { + std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; + } +} + +int main(int argc, const char *argv[]) +{ + argc=argc; + argv=argv; + + //Search for all releases by Kate Bush + + DoSearch("release","artist:\"Kate Bush\""); + + //Search for all releases with 'sensual' in the title + + DoSearch("release","release:sensual"); + + //Search for all artists with 'john' in the name + + DoSearch("artist","artist:john"); +} diff --git a/examples/search_c.c b/examples/search_c.c new file mode 100644 index 0000000..77da2c7 --- /dev/null +++ b/examples/search_c.c @@ -0,0 +1,132 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id: Lifespan.cc 13211 2012-07-20 16:15:03Z adhawkins $ + +----------------------------------------------------------------------------*/ + +#include +#include +#include + +#include "musicbrainz5/mb5_c.h" + +int main(int argc, const char *argv[]) +{ + Mb5Query Query; + + argc=argc; + argv=argv; + + Query=mb5_query_new("searchcexample-1.0",NULL,0); + if (Query) + { + char **ParamNames; + char **ParamValues; + Mb5Metadata Metadata; + char ErrorMessage[256]; + tQueryResult Result; + int HTTPCode; + + ParamNames=malloc(2*sizeof(char *)); + ParamNames[0]=malloc(256); + ParamNames[1]=malloc(256); + ParamValues=malloc(2*sizeof(char *)); + ParamValues[0]=malloc(256); + ParamValues[1]=malloc(256); + + strcpy(ParamNames[0],"query"); + strcpy(ParamValues[0],"artist:john"); + + strcpy(ParamNames[1],"limit"); + strcpy(ParamValues[1],"10"); + + Metadata=mb5_query_query(Query,"artist","","",2,ParamNames,ParamValues); + + Result=mb5_query_get_lastresult(Query); + HTTPCode=mb5_query_get_lasthttpcode(Query); + + mb5_query_get_lasterrormessage(Query,ErrorMessage,sizeof(ErrorMessage)); + printf("Result: %d\nHTTPCode: %d\nErrorMessage: '%s'\n",Result,HTTPCode,ErrorMessage); + + if (Metadata) + { + int ThisArtist; + Mb5ArtistList ArtistList=mb5_metadata_get_artistlist(Metadata); + + printf("Found %d artist(s)\n",mb5_artist_list_size(ArtistList)); + + for (ThisArtist=0;ThisArtist. + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ALIAS_H +#define _MUSICBRAINZ5_ALIAS_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CAliasPrivate; + + class CAlias: public CEntity + { + public: + CAlias(const XMLNode& Node); + CAlias(const CAlias& Other); + CAlias& operator =(const CAlias& Other); + virtual ~CAlias(); + + virtual CAlias *Clone(); + + std::string Locale() const; + std::string Text() const; + std::string SortName() const; + std::string Type() const; + std::string Primary() const; + std::string BeginDate() const; + std::string EndDate() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CAliasPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/AliasList.h b/include/musicbrainz5/AliasList.h new file mode 100644 index 0000000..dda09cc --- /dev/null +++ b/include/musicbrainz5/AliasList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ALIAS_LIST_H +#define _MUSICBRAINZ5_ALIAS_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CAlias; + + typedef CListImpl CAliasList; +} + +#endif diff --git a/include/musicbrainz5/Annotation.h b/include/musicbrainz5/Annotation.h new file mode 100644 index 0000000..7ad0d92 --- /dev/null +++ b/include/musicbrainz5/Annotation.h @@ -0,0 +1,67 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ANNOTATION_H +#define _MUSICBRAINZ5_ANNOTATION_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CAnnotationPrivate; + + class CAnnotation: public CEntity + { + public: + CAnnotation(const XMLNode& Node); + CAnnotation(const CAnnotation& Other); + CAnnotation& operator =(const CAnnotation& Other); + virtual ~CAnnotation(); + + virtual CAnnotation *Clone(); + + std::string Type() const; + std::string Entity() const; + std::string Name() const; + std::string Text() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CAnnotationPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/AnnotationList.h b/include/musicbrainz5/AnnotationList.h new file mode 100644 index 0000000..18c50d9 --- /dev/null +++ b/include/musicbrainz5/AnnotationList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ANNOTATION_LIST_H +#define _MUSICBRAINZ5_ANNOTATION_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CAnnotation; + + typedef CListImpl CAnnotationList; +} + +#endif diff --git a/include/musicbrainz5/Artist.h b/include/musicbrainz5/Artist.h new file mode 100644 index 0000000..c7b4fe6 --- /dev/null +++ b/include/musicbrainz5/Artist.h @@ -0,0 +1,98 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ARTIST_H +#define _MUSICBRAINZ5_ARTIST_H + +#include +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/IPIList.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/AliasList.h" +#include "musicbrainz5/RecordingList.h" +#include "musicbrainz5/ReleaseGroupList.h" +#include "musicbrainz5/LabelList.h" +#include "musicbrainz5/WorkList.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTagList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CArtistPrivate; + class CLifespan; + class CRating; + class CUserRating; + + class CArtist: public CEntity + { + public: + CArtist(const XMLNode& Node=XMLNode::emptyNode()); + CArtist(const CArtist& Other); + CArtist& operator =(const CArtist& Other); + virtual ~CArtist(); + + virtual CArtist *Clone(); + + std::string ID() const; + std::string Type() const; + std::string Name() const; + std::string SortName() const; + std::string Gender() const; + std::string Country() const; + std::string Disambiguation() const; + CIPIList *IPIList() const; + CLifespan *Lifespan() const; + CAliasList *AliasList() const; + CRecordingList *RecordingList() const; + CReleaseList *ReleaseList() const; + CReleaseGroupList *ReleaseGroupList() const; + CLabelList *LabelList() const; + CWorkList *WorkList() const; + CRelationListList *RelationListList() const; + CTagList *TagList() const; + CUserTagList *UserTagList() const; + CRating *Rating() const; + CUserRating *UserRating() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CArtistPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/ArtistCredit.h b/include/musicbrainz5/ArtistCredit.h new file mode 100644 index 0000000..1ed4f31 --- /dev/null +++ b/include/musicbrainz5/ArtistCredit.h @@ -0,0 +1,66 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ARTIST_CREDIT_H +#define _MUSICBRAINZ5_ARTIST_CREDIT_H + +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/NameCreditList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CArtistCreditPrivate; + + class CArtistCredit: public CEntity + { + public: + CArtistCredit(const XMLNode& Node=XMLNode::emptyNode()); + CArtistCredit(const CArtistCredit& Other); + CArtistCredit& operator =(const CArtistCredit& Other); + virtual ~CArtistCredit(); + + virtual CArtistCredit *Clone(); + + CNameCreditList *NameCreditList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CArtistCreditPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/ArtistList.h b/include/musicbrainz5/ArtistList.h new file mode 100644 index 0000000..eb92759 --- /dev/null +++ b/include/musicbrainz5/ArtistList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ARTIST_LIST_H +#define _MUSICBRAINZ5_ARTIST_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CArtist; + + typedef CListImpl CArtistList; +} + +#endif diff --git a/include/musicbrainz5/Attribute.h b/include/musicbrainz5/Attribute.h new file mode 100644 index 0000000..2fac33c --- /dev/null +++ b/include/musicbrainz5/Attribute.h @@ -0,0 +1,64 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ATTRIBUTE_H +#define _MUSICBRAINZ5_ATTRIBUTE_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CAttributePrivate; + + class CAttribute: public CEntity + { + public: + CAttribute(const XMLNode& Node=XMLNode::emptyNode()); + CAttribute(const CAttribute& Other); + CAttribute& operator =(const CAttribute& Other); + virtual ~CAttribute(); + + virtual CAttribute *Clone(); + + std::string Text() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CAttributePrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/AttributeList.h b/include/musicbrainz5/AttributeList.h new file mode 100644 index 0000000..66b867a --- /dev/null +++ b/include/musicbrainz5/AttributeList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ATTRIBUTE_LIST_H +#define _MUSICBRAINZ5_ATTRIBUTE_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CAttribute; + + typedef CListImpl CAttributeList; +} + +#endif diff --git a/include/musicbrainz5/CDStub.h b/include/musicbrainz5/CDStub.h new file mode 100644 index 0000000..85a5834 --- /dev/null +++ b/include/musicbrainz5/CDStub.h @@ -0,0 +1,72 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_CDSTUB_H +#define _MUSICBRAINZ5_CDSTUB_H + +#include +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/NonMBTrackList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CCDStubPrivate; + + class CCDStub: public CEntity + { + public: + CCDStub(const XMLNode& Node); + CCDStub(const CCDStub& Other); + CCDStub& operator =(const CCDStub& Other); + virtual ~CCDStub(); + + virtual CCDStub *Clone(); + + std::string ID() const; + std::string Title() const; + std::string Artist() const; + std::string Barcode() const; + std::string Comment() const; + CNonMBTrackList *NonMBTrackList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CCDStubPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/CDStubList.h b/include/musicbrainz5/CDStubList.h new file mode 100644 index 0000000..57c401d --- /dev/null +++ b/include/musicbrainz5/CDStubList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_CDSTUB_LIST_H +#define _MUSICBRAINZ5_CDSTUB_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CCDStub; + + typedef CListImpl CCDStubList; +} + +#endif diff --git a/include/musicbrainz5/Collection.h b/include/musicbrainz5/Collection.h new file mode 100644 index 0000000..a2b9fd7 --- /dev/null +++ b/include/musicbrainz5/Collection.h @@ -0,0 +1,67 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_COLLECTION_H +#define _MUSICBRAINZ5_COLLECTION_H + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/ReleaseList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CCollectionPrivate; + + class CCollection: public CEntity + { + public: + CCollection(const XMLNode& Node); + CCollection(const CCollection& Other); + CCollection& operator =(const CCollection& Other); + virtual ~CCollection(); + + virtual CCollection *Clone(); + + std::string ID() const; + std::string Name() const; + std::string Editor() const; + CReleaseList *ReleaseList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CCollectionPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/CollectionList.h b/include/musicbrainz5/CollectionList.h new file mode 100644 index 0000000..a9ac83f --- /dev/null +++ b/include/musicbrainz5/CollectionList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_COLLECTION_LIST_H +#define _MUSICBRAINZ5_COLLECTION_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CCollection; + + typedef CListImpl CCollectionList; +} + +#endif diff --git a/include/musicbrainz5/Disc.h b/include/musicbrainz5/Disc.h new file mode 100644 index 0000000..b9a399e --- /dev/null +++ b/include/musicbrainz5/Disc.h @@ -0,0 +1,71 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_DISC_H +#define _MUSICBRAINZ5_DISC_H + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/ReleaseList.h" + +#include "musicbrainz5/Lifespan.h" + +#include +#include + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CDiscPrivate; + + class CDisc: public CEntity + { + public: + CDisc(const XMLNode& Node=XMLNode::emptyNode()); + CDisc(const CDisc& Other); + CDisc& operator =(const CDisc& Other); + virtual ~CDisc(); + + virtual CDisc *Clone(); + + std::string ID() const; + int Sectors() const; + CReleaseList *ReleaseList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CDiscPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/DiscList.h b/include/musicbrainz5/DiscList.h new file mode 100644 index 0000000..a9f29fb --- /dev/null +++ b/include/musicbrainz5/DiscList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_DISC_LIST_H +#define _MUSICBRAINZ5_DISC_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CDisc; + + typedef CListImpl CDiscList; +} + +#endif diff --git a/include/musicbrainz5/Entity.h b/include/musicbrainz5/Entity.h new file mode 100644 index 0000000..fca7a14 --- /dev/null +++ b/include/musicbrainz5/Entity.h @@ -0,0 +1,117 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ENTITY_H +#define _MUSICBRAINZ5_ENTITY_H + +#include +#include +#include +#include + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CEntityPrivate; + + class CRelationListList; + + class CEntity + { + public: + CEntity(); + CEntity(const CEntity& Other); + CEntity& operator =(const CEntity& Other); + virtual ~CEntity(); + + virtual CEntity *Clone()=0; + + void Parse(const XMLNode& Node); + + std::map ExtAttributes() const; + std::map ExtElements() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + void ProcessRelationList(const XMLNode& Node, CRelationListList* & RetVal); + + template + void ProcessItem(const XMLNode& Node, T* & RetVal) + { + RetVal=new T(Node); + } + + template + void ProcessItem(const XMLNode& Node, T& RetVal) + { + std::stringstream os; + if (Node.getText()) + os << (const char *)Node.getText(); + + os >> RetVal; + if (os.fail()) + { + std::cerr << "Error parsing value '"; + if (Node.getText()) + std::cerr << Node.getText(); + std::cerr << "'" << std::endl; + } + } + + template + void ProcessItem(const std::string& Text, T& RetVal) + { + std::stringstream os; + os << Text; + + os >> RetVal; + if (os.fail()) + { + std::cerr << "Error parsing value '" << Text << "'" << std::endl; + } + } + + void ProcessItem(const XMLNode& Node, std::string& RetVal) + { + if (Node.getText()) + RetVal=Node.getText(); + } + + virtual void ParseAttribute(const std::string& Name, const std::string& Value)=0; + virtual void ParseElement(const XMLNode& Node)=0; + + private: + CEntityPrivate *m_d; + + void Cleanup(); + }; +} + +std::ostream& operator << (std::ostream& os, const MusicBrainz5::CEntity& Entity); + +#endif diff --git a/include/musicbrainz5/FreeDBDisc.h b/include/musicbrainz5/FreeDBDisc.h new file mode 100644 index 0000000..4b2f1f1 --- /dev/null +++ b/include/musicbrainz5/FreeDBDisc.h @@ -0,0 +1,72 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_FREEDB_DISC_H +#define _MUSICBRAINZ5_FREEDB_DISC_H + +#include +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/NonMBTrackList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CFreeDBDiscPrivate; + + class CFreeDBDisc: public CEntity + { + public: + CFreeDBDisc(const XMLNode& Node); + CFreeDBDisc(const CFreeDBDisc& Other); + CFreeDBDisc& operator =(const CFreeDBDisc& Other); + virtual ~CFreeDBDisc(); + + virtual CFreeDBDisc *Clone(); + + std::string ID() const; + std::string Title() const; + std::string Artist() const; + std::string Category() const; + std::string Year() const; + CNonMBTrackList *NonMBTrackList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CFreeDBDiscPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/FreeDBDiscList.h b/include/musicbrainz5/FreeDBDiscList.h new file mode 100644 index 0000000..c132206 --- /dev/null +++ b/include/musicbrainz5/FreeDBDiscList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_FREEDBDISC_LIST_H +#define _MUSICBRAINZ5_FREEDBDISC_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CFreeDBDisc; + + typedef CListImpl CFreeDBDiscList; +} + +#endif diff --git a/include/musicbrainz5/HTTPFetch.h b/include/musicbrainz5/HTTPFetch.h new file mode 100644 index 0000000..b13cef2 --- /dev/null +++ b/include/musicbrainz5/HTTPFetch.h @@ -0,0 +1,289 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_HTTP_FETCH_ +#define _MUSICBRAINZ5_HTTP_FETCH_ + +#include +#include + +namespace MusicBrainz5 +{ + class CHTTPFetchPrivate; + + class CExceptionBase: public std::exception + { + public: + CExceptionBase(const std::string& ErrorMessage, const std::string& Exception) + : m_ErrorMessage(ErrorMessage), + m_Exception(Exception) + { + m_FullMessage=m_Exception + ": " + m_ErrorMessage; + } + + virtual ~CExceptionBase() throw() {}; + + virtual const char* what() const throw() + { + return m_FullMessage.c_str(); + } + + private: + std::string m_ErrorMessage; + std::string m_Exception; + std::string m_FullMessage; + }; + + /** + * Exception thrown when an error occurs connecting to web service + */ + + class CConnectionError: public CExceptionBase + { + public: + CConnectionError(const std::string& ErrorMessage) + : CExceptionBase(ErrorMessage,"Connection error") + { + } + }; + + /** + * Exception thrown when a connection to the web service times out + */ + + class CTimeoutError: public CExceptionBase + { + public: + CTimeoutError(const std::string& ErrorMessage) + : CExceptionBase(ErrorMessage,"Timeout error") + { + } + }; + + /** + * Exception thrown when an authentication error occurs + */ + + class CAuthenticationError: public CExceptionBase + { + public: + CAuthenticationError(const std::string& ErrorMessage) + : CExceptionBase(ErrorMessage,"Authentication error") + { + } + }; + + /** + * Exception thrown when an error occurs fetching data + */ + + class CFetchError: public CExceptionBase + { + public: + CFetchError(const std::string& ErrorMessage) + : CExceptionBase(ErrorMessage,"Fetch error") + { + } + }; + + /** + * Exception thrown when an invalid request is made + */ + + class CRequestError: public CExceptionBase + { + public: + CRequestError(const std::string& ErrorMessage) + : CExceptionBase(ErrorMessage,"Request error") + { + } + }; + + /** + * Exception thrown when the requested resource is not found + */ + + class CResourceNotFoundError: public CExceptionBase + { + public: + CResourceNotFoundError(const std::string& ErrorMessage) + : CExceptionBase(ErrorMessage,"Resource not found error") + { + } + }; + + /** + * @brief Object for make HTTP requests + * + * Object to be used to make HTTP requests + * + */ + class CHTTPFetch + { + public: + /** + * @brief Constructor + * + * Constructor + * + * @param UserAgent User agent string to send + * @param Host Host name to connect to + * @param Port Port to connect to (80 by default) + */ + + + CHTTPFetch(const std::string& UserAgent, const std::string& Host, int Port=80); + ~CHTTPFetch(); + + /** + * @brief Set the user name to use + * + * Set the user name to use when authenticating with the web server + * + * @param UserName User name to use + */ + + void SetUserName(const std::string& UserName); + + /** + * @brief Set the password to use + * + * Set the password to use when authenticating with the web server + * + * @param Password Password to use + */ + + void SetPassword(const std::string& Password); + + /** + * @brief Set the proxy server to use + * + * Set the proxy server to use when connecting with the web server + * + * @param ProxyHost Proxy server to use + */ + + void SetProxyHost(const std::string& ProxyHost); + + /** + * @brief Set the proxy port to use + * + * Set the proxy server port to use when connecting to the web server + * + * @param ProxyPort Proxy server port to use + */ + + void SetProxyPort(int ProxyPort); + + /** + * @brief Set the proxy user name to use + * + * Set the user name to use when authenticating with the proxy server + * + * @param ProxyUserName Proxy user name to use + */ + + void SetProxyUserName(const std::string& ProxyUserName); + + /** + * @brief Set the proxy password to use + * + * Set the password to use when authenticating with the proxy server + * + * @param ProxyPassword Proxy server password to use + */ + + void SetProxyPassword(const std::string& ProxyPassword); + + /** + * @brief Make a request to the server + * + * Make a request to the server + * + * @param URL URL to request + * @param Request Request type (GET by default) + * + * @return Number of bytes received + * + * @throw CConnectionError An error occurred connecting to the web server + * @throw CTimeoutError A timeout occurred when connecting to the web server + * @throw CAuthenticationError An authentication error occurred + * @throw CFetchError An error occurred fetching data + * @throw CRequestError The request was invalid + * @throw CResourceNotFoundError The requested resource was not found + */ + + int Fetch(const std::string& URL, const std::string& Request="GET"); + + /** + * @brief Get the data receieved + * + * Get the data received from the request + * + * @return Data received + */ + + std::vector Data() const; + + /** + * @brief libneon result code from the request + * + * Return the result code from the request + * + * @return libneon result code from the request + */ + + int Result() const; + + /** + * @brief Status + * + * Return the HTTP status code from the request + * + * @return HTTP status code from the request + */ + + int Status() const; + + /** + * @brief Return the error message from the request + * + * Return the error message from the request + * + * @return Error message from the request + */ + + std::string ErrorMessage() const; + + private: + CHTTPFetchPrivate * const m_d; + + static int httpAuth(void *userdata, const char *realm, int attempts, char *username, char *password); + static int proxyAuth(void *userdata, const char *realm, int attempts, char *username, char *password); + static int httpResponseReader(void *userdata, const char *buf, size_t len); + }; +} + +#endif diff --git a/include/musicbrainz5/IPI.h b/include/musicbrainz5/IPI.h new file mode 100644 index 0000000..e308e9d --- /dev/null +++ b/include/musicbrainz5/IPI.h @@ -0,0 +1,64 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_IPI_H +#define _MUSICBRAINZ5_IPI_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CIPIPrivate; + + class CIPI: public CEntity + { + public: + CIPI(const XMLNode& Node=XMLNode::emptyNode()); + CIPI(const CIPI& Other); + CIPI& operator =(const CIPI& Other); + virtual ~CIPI(); + + virtual CIPI *Clone(); + + std::string IPI() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CIPIPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/IPIList.h b/include/musicbrainz5/IPIList.h new file mode 100644 index 0000000..9fe58e6 --- /dev/null +++ b/include/musicbrainz5/IPIList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_IPI_LIST_H +#define _MUSICBRAINZ5_IPI_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CIPI; + + typedef CListImpl CIPIList; +} + +#endif diff --git a/include/musicbrainz5/ISRC.h b/include/musicbrainz5/ISRC.h new file mode 100644 index 0000000..75b9619 --- /dev/null +++ b/include/musicbrainz5/ISRC.h @@ -0,0 +1,65 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ISRC_H +#define _MUSICBRAINZ5_ISRC_H + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/RecordingList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CISRCPrivate; + + class CISRC: public CEntity + { + public: + CISRC(const XMLNode& Node=XMLNode::emptyNode()); + CISRC(const CISRC& Other); + CISRC& operator =(const CISRC& Other); + virtual ~CISRC(); + + virtual CISRC *Clone(); + + std::string ID() const; + CRecordingList *RecordingList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CISRCPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/ISRCList.h b/include/musicbrainz5/ISRCList.h new file mode 100644 index 0000000..df54db9 --- /dev/null +++ b/include/musicbrainz5/ISRCList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ISRC_LIST_H +#define _MUSICBRAINZ5_ISRC_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CISRC; + + typedef CListImpl CISRCList; +} + +#endif diff --git a/include/musicbrainz5/ISWC.h b/include/musicbrainz5/ISWC.h new file mode 100644 index 0000000..d693e10 --- /dev/null +++ b/include/musicbrainz5/ISWC.h @@ -0,0 +1,66 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ISWC_H +#define _MUSICBRAINZ5_ISWC_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CISWCPrivate; + + class CISWC: public CEntity + { + public: + CISWC(const XMLNode& Node=XMLNode::emptyNode()); + CISWC(const CISWC& Other); + CISWC& operator =(const CISWC& Other); + virtual ~CISWC(); + + virtual CISWC *Clone(); + + std::string ISWC() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CISWCPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/ISWCList.h b/include/musicbrainz5/ISWCList.h new file mode 100644 index 0000000..22354b7 --- /dev/null +++ b/include/musicbrainz5/ISWCList.h @@ -0,0 +1,63 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_ISWC_LIST_H +#define _MUSICBRAINZ5_ISWC_LIST_H + +#include +#include + +#include "musicbrainz5/ListImpl.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CISWC; + class CISWCListPrivate; + + class CISWCList: public CListImpl + { + public: + CISWCList(const XMLNode& Node=XMLNode::emptyNode()); + CISWCList(const CISWCList& Other); + CISWCList& operator =(const CISWCList& Other); + virtual ~CISWCList(); + + virtual CISWCList *Clone(); + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CISWCListPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/Label.h b/include/musicbrainz5/Label.h new file mode 100644 index 0000000..ba7df2f --- /dev/null +++ b/include/musicbrainz5/Label.h @@ -0,0 +1,91 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_LABEL_H +#define _MUSICBRAINZ5_LABEL_H + +#include +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/IPIList.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/AliasList.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTagList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CLabelPrivate; + + class CLifespan; + class CRating; + class CUserRating; + + class CLabel: public CEntity + { + public: + CLabel(const XMLNode& Node=XMLNode::emptyNode()); + CLabel(const CLabel& Other); + CLabel& operator =(const CLabel& Other); + virtual ~CLabel(); + + virtual CLabel *Clone(); + + std::string ID() const; + std::string Type() const; + std::string Name() const; + std::string SortName() const; + int LabelCode() const; + CIPIList *IPIList() const; + std::string Disambiguation() const; + std::string Country() const; + CLifespan *Lifespan() const; + CAliasList *AliasList() const; + CReleaseList *ReleaseList() const; + CRelationListList *RelationListList() const; + CTagList *TagList() const; + CUserTagList *UserTagList() const; + CRating *Rating() const; + CUserRating *UserRating() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CLabelPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/LabelInfo.h b/include/musicbrainz5/LabelInfo.h new file mode 100644 index 0000000..220cce9 --- /dev/null +++ b/include/musicbrainz5/LabelInfo.h @@ -0,0 +1,70 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_LABEL_INFO_H +#define _MUSICBRAINZ5_LABEL_INFO_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CLabelInfoPrivate; + + class CLabel; + + class CLabelInfo: public CEntity + { + public: + CLabelInfo(const XMLNode& Node=XMLNode::emptyNode()); + CLabelInfo(const CLabelInfo& Other); + CLabelInfo& operator =(const CLabelInfo& Other); + virtual ~CLabelInfo(); + + virtual CLabelInfo *Clone(); + + std::string CatalogNumber() const; + CLabel *Label() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CLabelInfoPrivate * const m_d; + }; +} + +#endif + diff --git a/include/musicbrainz5/LabelInfoList.h b/include/musicbrainz5/LabelInfoList.h new file mode 100644 index 0000000..c9de4bb --- /dev/null +++ b/include/musicbrainz5/LabelInfoList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_LABELINFO_LIST_H +#define _MUSICBRAINZ5_LABELINFO_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CLabelInfo; + + typedef CListImpl CLabelInfoList; +} + +#endif diff --git a/include/musicbrainz5/LabelList.h b/include/musicbrainz5/LabelList.h new file mode 100644 index 0000000..7ddba6d --- /dev/null +++ b/include/musicbrainz5/LabelList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_LABEL_LIST_H +#define _MUSICBRAINZ5_LABEL_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CLabel; + + typedef CListImpl CLabelList; +} + +#endif diff --git a/include/musicbrainz5/Lifespan.h b/include/musicbrainz5/Lifespan.h new file mode 100644 index 0000000..b50dbd6 --- /dev/null +++ b/include/musicbrainz5/Lifespan.h @@ -0,0 +1,66 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_LIFESPAN_H +#define _MUSICBRAINZ5_LIFESPAN_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CLifespanPrivate; + + class CLifespan: public CEntity + { + public: + CLifespan(const XMLNode& Node=XMLNode::emptyNode()); + CLifespan(const CLifespan& Other); + CLifespan& operator =(const CLifespan& Other); + virtual ~CLifespan(); + + virtual CLifespan *Clone(); + + std::string Begin() const; + std::string End() const; + std::string Ended() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CLifespanPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/List.h b/include/musicbrainz5/List.h new file mode 100644 index 0000000..5b8b21a --- /dev/null +++ b/include/musicbrainz5/List.h @@ -0,0 +1,69 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_LIST_H +#define _MUSICBRAINZ5_LIST_H + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CListPrivate; + + class CList: public CEntity + { + public: + CList(); + CList(const CList& Other); + CList& operator =(const CList& Other); + virtual ~CList(); + + virtual CList *Clone(); + + int NumItems() const; + int Offset() const; + int Count() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + void AddItem(CEntity *Item); + CEntity *Item(int Item) const; + + private: + CListPrivate *m_d; + + void Cleanup(); + }; +} + +#endif + diff --git a/include/musicbrainz5/ListImpl.h b/include/musicbrainz5/ListImpl.h new file mode 100644 index 0000000..17d64a7 --- /dev/null +++ b/include/musicbrainz5/ListImpl.h @@ -0,0 +1,122 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_LIST_IMPL_H +#define _MUSICBRAINZ5_LIST_IMPL_H + +#include "musicbrainz5/List.h" + +namespace MusicBrainz5 +{ + template + class CListImpl: public CList + { + public: + CListImpl(const XMLNode& Node=XMLNode::emptyNode()) + : CList() + { + if (!Node.isEmpty()) + { + //std::cout << T::GetElementName() << " List node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } + } + + CListImpl(const CListImpl& Other) + : CList() + { + *this=Other; + } + + MusicBrainz5::CListImpl& operator =(const CListImpl& Other) + { + if (this!=&Other) + { + CList::operator =(Other); + } + + return *this; + } + + virtual ~CListImpl() + { + } + + CListImpl *Clone() + { + return new CListImpl(*this); + } + + virtual std::ostream& Serialise(std::ostream& os) const + { + os << T::GetElementName() << " List (impl):" << std::endl; + + CList::Serialise(os); + + for (int count=0;count(CList::Item(Item)); + } + + void AddItem(T *Item) + { + CList::AddItem(Item); + } + + protected: + void ParseElement(const XMLNode& Node) + { + std::string NodeName=Node.getName(); + + if (T::GetElementName()==NodeName) + { + T *Item=0; + + ProcessItem(Node,Item); + AddItem(Item); + } + else + CList::ParseElement(Node); + } + }; +} + +#endif diff --git a/include/musicbrainz5/Medium.h b/include/musicbrainz5/Medium.h new file mode 100644 index 0000000..0894fb4 --- /dev/null +++ b/include/musicbrainz5/Medium.h @@ -0,0 +1,74 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_MEDIUM_H +#define _MUSICBRAINZ5_MEDIUM_H + +#include +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/DiscList.h" +#include "musicbrainz5/TrackList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CMediumPrivate; + + class CMedium: public CEntity + { + public: + CMedium(const XMLNode& Node=XMLNode::emptyNode()); + CMedium(const CMedium& Other); + CMedium& operator =(const CMedium& Other); + virtual ~CMedium(); + + virtual CMedium *Clone(); + + std::string Title() const; + int Position() const; + std::string Format() const; + CDiscList *DiscList() const; + CTrackList *TrackList() const; + + bool ContainsDiscID(const std::string& DiscID) const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CMediumPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/MediumList.h b/include/musicbrainz5/MediumList.h new file mode 100644 index 0000000..15fc3fa --- /dev/null +++ b/include/musicbrainz5/MediumList.h @@ -0,0 +1,65 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_MEDIUM_LIST_H +#define _MUSICBRAINZ5_MEDIUM_LIST_H + +#include +#include + +#include "musicbrainz5/ListImpl.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CMedium; + class CMediumListPrivate; + + class CMediumList: public CListImpl + { + public: + CMediumList(const XMLNode& Node=XMLNode::emptyNode()); + CMediumList(const CMediumList& Other); + CMediumList& operator =(const CMediumList& Other); + virtual ~CMediumList(); + + virtual CMediumList *Clone(); + + int TrackCount() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CMediumListPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/Message.h b/include/musicbrainz5/Message.h new file mode 100644 index 0000000..583907a --- /dev/null +++ b/include/musicbrainz5/Message.h @@ -0,0 +1,64 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_MESSAGE_H +#define _MUSICBRAINZ5_MESSAGE_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CMessagePrivate; + + class CMessage: public CEntity + { + public: + CMessage(const XMLNode& Node); + CMessage(const CMessage& Other); + CMessage& operator =(const CMessage& Other); + virtual ~CMessage(); + + virtual CMessage *Clone(); + + std::string Text() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CMessagePrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/Metadata.h b/include/musicbrainz5/Metadata.h new file mode 100644 index 0000000..dcaba89 --- /dev/null +++ b/include/musicbrainz5/Metadata.h @@ -0,0 +1,126 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_METADATA_H +#define _MUSICBRAINZ5_METADATA_H + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/ArtistList.h" +#include "musicbrainz5/WorkList.h" +#include "musicbrainz5/ISRCList.h" +#include "musicbrainz5/LabelInfoList.h" +#include "musicbrainz5/ReleaseGroupList.h" +#include "musicbrainz5/RecordingList.h" +#include "musicbrainz5/LabelList.h" +#include "musicbrainz5/AnnotationList.h" +#include "musicbrainz5/CDStubList.h" +#include "musicbrainz5/FreeDBDiscList.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/CollectionList.h" + +#include "musicbrainz5/xmlParser.h" + +#include + +namespace MusicBrainz5 +{ + class CMetadataPrivate; + + class CArtist; + class CRelease; + class CReleaseGroup; + class CRecording; + class CLabel; + class CPUID; + class CISRC; + class CDisc; + class CRating; + class CUserRating; + class CCollection; + class CArtist; + class CWork; + class CCDStub; + class CMessage; + + class CMetadata: public CEntity + { + public: + CMetadata(const XMLNode& Node=XMLNode::emptyNode()); + CMetadata(const CMetadata& Other); + CMetadata& operator =(const CMetadata& Other); + virtual ~CMetadata(); + + virtual CMetadata *Clone(); + + std::string XMLNS() const; + std::string XMLNSExt() const; + std::string Generator() const; + std::string Created() const; + CArtist *Artist() const; + CRelease *Release() const; + CReleaseGroup *ReleaseGroup() const; + CRecording *Recording() const; + CLabel *Label() const; + CWork *Work() const; + CPUID *PUID() const; + CISRC *ISRC() const; + CDisc *Disc() const; + CLabelInfoList *LabelInfoList() const; + CRating *Rating() const; + CUserRating *UserRating() const; + CCollection *Collection() const; + CArtistList *ArtistList() const; + CReleaseList *ReleaseList() const; + CReleaseGroupList *ReleaseGroupList() const; + CRecordingList *RecordingList() const; + CLabelList *LabelList() const; + CWorkList *WorkList() const; + CISRCList *ISRCList() const; + CAnnotationList *AnnotationList() const; + CCDStubList *CDStubList() const; + CFreeDBDiscList *FreeDBDiscList() const; + CTagList *TagList() const; + CUserTagList *UserTagList() const; + CCollectionList *CollectionList() const; + CCDStub *CDStub() const; + CMessage *Message() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CMetadataPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/NameCredit.h b/include/musicbrainz5/NameCredit.h new file mode 100644 index 0000000..058adfd --- /dev/null +++ b/include/musicbrainz5/NameCredit.h @@ -0,0 +1,70 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_NAME_CREDIT_H +#define _MUSICBRAINZ5_NAME_CREDIT_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CNameCreditPrivate; + + class CArtist; + + class CNameCredit: public CEntity + { + public: + CNameCredit(const XMLNode& Node=XMLNode::emptyNode()); + CNameCredit(const CNameCredit& Other); + CNameCredit& operator =(const CNameCredit& Other); + virtual ~CNameCredit(); + + virtual CNameCredit *Clone(); + + std::string JoinPhrase() const; + std::string Name() const; + CArtist *Artist() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CNameCreditPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/NameCreditList.h b/include/musicbrainz5/NameCreditList.h new file mode 100644 index 0000000..18a31b3 --- /dev/null +++ b/include/musicbrainz5/NameCreditList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_NAMECREDIT_LIST_H +#define _MUSICBRAINZ5_NAMECREDIT_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CNameCredit; + + typedef CListImpl CNameCreditList; +} + +#endif diff --git a/include/musicbrainz5/NonMBTrack.h b/include/musicbrainz5/NonMBTrack.h new file mode 100644 index 0000000..f37fa83 --- /dev/null +++ b/include/musicbrainz5/NonMBTrack.h @@ -0,0 +1,66 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_NON_MB_TRACK_H +#define _MUSICBRAINZ5_NON_MB_TRACK_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CNonMBTrackPrivate; + + class CNonMBTrack: public CEntity + { + public: + CNonMBTrack(const XMLNode& Node); + CNonMBTrack(const CNonMBTrack& Other); + CNonMBTrack& operator =(const CNonMBTrack& Other); + virtual ~CNonMBTrack(); + + virtual CNonMBTrack *Clone(); + + std::string Title() const; + std::string Artist() const; + int Length() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CNonMBTrackPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/NonMBTrackList.h b/include/musicbrainz5/NonMBTrackList.h new file mode 100644 index 0000000..1b5d2fd --- /dev/null +++ b/include/musicbrainz5/NonMBTrackList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_NONMBTRACK_LIST_H +#define _MUSICBRAINZ5_NONMBTRACK_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CNonMBTrack; + + typedef CListImpl CNonMBTrackList; +} + +#endif diff --git a/include/musicbrainz5/PUID.h b/include/musicbrainz5/PUID.h new file mode 100644 index 0000000..0679894 --- /dev/null +++ b/include/musicbrainz5/PUID.h @@ -0,0 +1,67 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_PUID_H +#define _MUSICBRAINZ5_PUID_H + +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/RecordingList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CPUIDPrivate; + + class CPUID: public CEntity + { + public: + CPUID(const XMLNode& Node=XMLNode::emptyNode()); + CPUID(const CPUID& Other); + CPUID& operator =(const CPUID& Other); + virtual ~CPUID(); + + virtual CPUID *Clone(); + + std::string ID() const; + CRecordingList *RecordingList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CPUIDPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/PUIDList.h b/include/musicbrainz5/PUIDList.h new file mode 100644 index 0000000..b4e5512 --- /dev/null +++ b/include/musicbrainz5/PUIDList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_PUID_LIST_H +#define _MUSICBRAINZ5_PUID_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CPUID; + + typedef CListImpl CPUIDList; +} + +#endif diff --git a/include/musicbrainz5/Query.h b/include/musicbrainz5/Query.h new file mode 100644 index 0000000..f6e15e3 --- /dev/null +++ b/include/musicbrainz5/Query.h @@ -0,0 +1,449 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_QUERY_H +#define _MUSICBRAINZ5_QUERY_H + +#include "defines.h" + +#include "Entity.h" + +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Metadata.h" + +#include "musicbrainz5/xmlParser.h" + +#include +#include +#include + +/** + * @mainpage libmusicbrainz5 + * + * This is the documentation for libmusicbrainz5, a library for retrieving data from + * the MusicBrainz service. + * + * The main entry point to the library is the MusicBrainz5::CQuery object. + * + * For details of the C interface, see the documentation for the file mb5_c.h. + * + * Please report any issues with this library at + * http://tickets.musicbrainz.org/. + * + * @par Compiling and Linking + * + * This package provides a pkg-config script that returns the necessary compiler + * and linker flags, as well as the version number. To build a small sample + * program one would use: + * + * @par + * g++ -o test_app test_app.cpp `pkg-config libmusicbrainz5 --cflags --libs` + * + * If you don't want/can't use pkg-config and you are using the C API, make sure + * you link in the C++ standard library: + * + * @par + * gcc -o test_app test_app.c -lmusicbrainz5 -lm -lstdc++ + * + * @par Example: + * + * A brief example showing how to lookup a list of releases matching a disc id + * +@code +MusicBrainz5::CQuery Query("cdlookupexample-1.0"); + +try +{ + MusicBrainz5::CMetadata Metadata=Query.Query("discid",DiscID); + if (Metadata.Disc() && Metadata.Disc()->ReleaseList()) + { + MusicBrainz5::CReleaseList *ReleaseList=Metadata.Disc()->ReleaseList(); + + std::cout << "Found " << ReleaseList->NumItems() << " release(s)" << std::endl; + + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CRelease *Release=ReleaseList->Item(count); + + std::cout << "Basic release: " << std::endl << *Release << std::endl; + + //The releases returned from LookupDiscID don't contain full information + + MusicBrainz5::CQuery::tParamMap Params; + Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits"; + + Metadata=Query.Query("release",Release.ID(),"",Params); + if (Metadata.Release()) + { + MusicBrainz5::CRelease *FullRelease=Metadata.Release(); + + std::cout << *FullRelease << std::endl; + } + } + } +} + +catch (MusicBrainz5::CConnectionError& Error) +{ + std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; +} + +catch (MusicBrainz5::CTimeoutError& Error) +{ + std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; +} + +catch (MusicBrainz5::CAuthenticationError& Error) +{ + std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; +} + +catch (MusicBrainz5::CFetchError& Error) +{ + std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; +} + +catch (MusicBrainz5::CRequestError& Error) +{ + std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; +} + +catch (MusicBrainz5::CResourceNotFoundError& Error) +{ + std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; + std::cout << "LastResult: " << Query.LastResult() << std::endl; + std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; + std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; +} +@endcode + */ + +namespace MusicBrainz5 +{ + class CQueryPrivate; + + /** + * @brief Main object for generating queries to MusicBrainz + * + * This object is the main entry point for the library, generating a query to the + * MusicBrainz service, and parsing the results. The resultant objects can be used + * to retrieve information appropriate to the query. + * + * For information on generating queries and the expected responses, see the + * documentation for the + * web service. + * + * For information on search syntax, see the documentation for + * search syntax. + * + * @b Note It is the responsibility of the caller to validate any pointers returned + * from the library. It is valid for a pointer to be NULL if the information was not + * present in the response from the MusicBrainz service. + * + * @b Note The ownership of any pointers returned from the C++ interfaces remains + * with the library. The caller should not delete any pointer returned from the + * library. Users of the C library should take note of the documentation for each + * individual function in mb5_c.h + */ + class CQuery + { + public: + typedef std::map tParamMap; + + /** + * @brief Enumerated type for query status + * + * Enumerated type for query status + */ + enum tQueryResult + { + eQuery_Success=0, + eQuery_ConnectionError, + eQuery_Timeout, + eQuery_AuthenticationError, + eQuery_FetchError, + eQuery_RequestError, + eQuery_ResourceNotFound + }; + + /** + * @brief Constructor for MusicBrainz::CQuery object + * + * This is the constructor for the MusicBrainz::CQuery object. + * + * @param UserAgent User agent to use in any queries and submissions. The format + * is @c "application-version", where application is your application's name + * and version is a version number which may not contain a '-' character. + * @param Server Server to be used (defaults to musicbrainz.org if not specified) + * @param Port Port to use (defaults to 80 if not specified) + * + */ + + CQuery(const std::string& UserAgent, const std::string& Server="musicbrainz.org", int Port=80); + + ~CQuery(); + + /** + * @brief Set the user name + * + * Set the user name to use when authenticating to the MusicBrainz service + * + * @param UserName Username to use + */ + + void SetUserName(const std::string& UserName); + + /** + * @brief Set the password + * + * Set the password to use when authenticating to the MusicBrainz service + * + * @param Password Password to use + */ + + void SetPassword(const std::string& Password); + + /** + * @brief Set proxy server + * + * Set the proxy server to use for queries. @b Note The http_proxy environment variable + * will be used to set a 'default' proxy server. Calls to this method will override any + * proxy settings set by the http_proxy environment variable. + * + * @param ProxyHost Proxy server to use + */ + + void SetProxyHost(const std::string& ProxyHost); + + /** + * @brief Set proxy server port + * + * Set the proxy server port to use for queries. @b Note The http_proxy environment variable + * will be used to set a 'default' proxy server. Calls to this method will override any + * proxy settings set by the http_proxy environment variable. + * + * @param ProxyPort Proxy port to use + */ + + void SetProxyPort(int ProxyPort); + + /** + * @brief Set proxy server user name + * + * Set the user name to use when authenticating to the proxy server. @b Note The http_proxy + * environment variable will be used to set a 'default' proxy server. Calls to this method + * will override any proxy settings set by the http_proxy environment variable. + * + * @param ProxyUserName Proxy user name to use + */ + + void SetProxyUserName(const std::string& ProxyUserName); + + /** + * @brief Set proxy server password + * + * Set the password to use when authenticating to the proxy server. @b Note The http_proxy + * environment variable will be used to set a 'default' proxy server. Calls to this method + * will override any proxy settings set by the http_proxy environment variable. + * + * @param ProxyPassword Proxy password to use + */ + + void SetProxyPassword(const std::string& ProxyPassword); + + /** + * @brief Return a list of releases that match a disc ID + * + * Request a list of releases matching the specified disc ID. + * + * @param DiscID Disc id to match + * + * @return MusicBrainz5::CReleaseList + */ + + CReleaseList LookupDiscID(const std::string& DiscID); + + /** + * @brief Return full information about a release + * + * Query for detailed information about a specific release + * + * @param ReleaseID MusicBrainz release ID to lookup + * + * @return MusicBrainz::CRelease object + * + * @throw CConnectionError An error occurred connecting to the web server + * @throw CTimeoutError A timeout occurred when connecting to the web server + * @throw CAuthenticationError An authentication error occurred + * @throw CFetchError An error occurred fetching data + * @throw CRequestError The request was invalid + * @throw CResourceNotFoundError The requested resource was not found + */ + + CRelease LookupRelease(const std::string& ReleaseID); + + /** + * @brief Perform a generic query + * + * Performs a generic query. + * + * Assuming the following parameters are set: + * + * "param1" = "p1v1 p1v2 p1v3"
+ * "param2" = "p2v1"
+ * "param3" = ""
+ * + * The following query will be generated: + * + * /ws/2/Entity/ID/Resource?param1=p1v1+p1v2+p1v3¶m2=p2v1¶m3 + * + * If any of ID or Resource are empty, those components will be omitted from the query. + * + * For full details about generating queries, see the + * web service + * documentation. + * + * @param Entity Entity to lookup (e.g. artist, release, discid) + * @param ID The MusicBrainz ID of the entity + * @param Resource The resource (currently only used for collections) + * @param Params Map of parameters to add to the query (e.g. inc) + * + * @return MusicBrainz5::CMetadata object + * + * @throw CConnectionError An error occurred connecting to the web server + * @throw CTimeoutError A timeout occurred when connecting to the web server + * @throw CAuthenticationError An authentication error occurred + * @throw CFetchError An error occurred fetching data + * @throw CRequestError The request was invalid + * @throw CResourceNotFoundError The requested resource was not found + */ + + CMetadata Query(const std::string& Entity,const std::string& ID="",const std::string& Resource="",const tParamMap& Params=tParamMap()); + + /** + * @brief Add entries to the specified collection + * + * Add a list of releases to the specified collection. + * + * @param CollectionID The MusicBrainz ID of the collection to add entries to + * @param Entries List of MusicBrainz Release IDs to add to the collection + * + * @return true if successful, false otherwise + * + * @throw CConnectionError An error occurred connecting to the web server + * @throw CTimeoutError A timeout occurred when connecting to the web server + * @throw CAuthenticationError An authentication error occurred + * @throw CFetchError An error occurred fetching data + * @throw CRequestError The request was invalid + * @throw CResourceNotFoundError The requested resource was not found + */ + + bool AddCollectionEntries(const std::string& CollectionID, const std::vector& Entries); + + /** + * @brief Delete entries from the specified collection + * + * Delete a list of releases from the specified collection. + * + * @param CollectionID The MusicBrainz ID of the collection to delete entries from + * @param Entries List of MusicBrainz Release IDs to delete from the collection + * + * @return true if successful, false otherwise + * + * @throw CConnectionError An error occurred connecting to the web server + * @throw CTimeoutError A timeout occurred when connecting to the web server + * @throw CAuthenticationError An authentication error occurred + * @throw CFetchError An error occurred fetching data + * @throw CRequestError The request was invalid + * @throw CResourceNotFoundError The requested resource was not found + */ + + bool DeleteCollectionEntries(const std::string& CollectionID, const std::vector& Entries); + + /** + * @brief Return result of the last query + * + * Return the result of the last query + * + * @return Result of last query + */ + + CQuery::tQueryResult LastResult() const; + + /** + * @brief Return HTTP code of the last query + * + * Return the HTTP code of the last query + * + * @return HTTP code of last query + */ + int LastHTTPCode() const; + + /** + * @brief Return error message from the last query + * + * Return the error message from the last query + * + * @return Error message from last query + */ + std::string LastErrorMessage() const; + + /** + * @brief Return the library version + * + * Return the library version + * + * @return Library version + */ + std::string Version() const; + + private: + CQueryPrivate * const m_d; + + CMetadata PerformQuery(const std::string& Query); + void WaitRequest() const; + std::string UserAgent() const; + bool EditCollection(const std::string& CollectionID, const std::vector& Entries, const std::string& Action); + std::string URIEscape(const std::string& URI); + std::string URLEncode(const std::map& Params); + }; +} + +#endif diff --git a/include/musicbrainz5/Rating.h b/include/musicbrainz5/Rating.h new file mode 100644 index 0000000..c8bc3eb --- /dev/null +++ b/include/musicbrainz5/Rating.h @@ -0,0 +1,64 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RATING_H +#define _MUSICBRAINZ5_RATING_H + +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CRatingPrivate; + + class CRating: public CEntity + { + public: + CRating(const XMLNode& Node=XMLNode::emptyNode()); + CRating(const CRating& Other); + CRating& operator =(const CRating& Other); + virtual ~CRating(); + + virtual CRating *Clone(); + + int VotesCount() const; + double Rating() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CRatingPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/Recording.h b/include/musicbrainz5/Recording.h new file mode 100644 index 0000000..0b8952e --- /dev/null +++ b/include/musicbrainz5/Recording.h @@ -0,0 +1,93 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RECORDING_H +#define _MUSICBRAINZ5_RECORDING_H + +#include +#include + +namespace MusicBrainz5 +{ + class CRecording; +} + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/PUIDList.h" +#include "musicbrainz5/ISRCList.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTagList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CRecordingPrivate; + + class CArtistCredit; + class CRating; + class CUserRating; + + class CRecording: public CEntity + { + public: + CRecording(const XMLNode& Node=XMLNode::emptyNode()); + CRecording(const CRecording& Other); + CRecording& operator =(const CRecording& Other); + virtual ~CRecording(); + + virtual CRecording *Clone(); + + std::string ID() const; + std::string Title() const; + int Length() const; + std::string Disambiguation() const; + CArtistCredit *ArtistCredit() const; + CReleaseList *ReleaseList() const; + CPUIDList *PUIDList() const; + CISRCList *ISRCList() const; + CRelationListList *RelationListList() const; + CTagList *TagList() const; + CUserTagList *UserTagList() const; + CRating *Rating() const; + CUserRating *UserRating() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CRecordingPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/RecordingList.h b/include/musicbrainz5/RecordingList.h new file mode 100644 index 0000000..1c28641 --- /dev/null +++ b/include/musicbrainz5/RecordingList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RECORDING_LIST_H +#define _MUSICBRAINZ5_RECORDING_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CRecording; + + typedef CListImpl CRecordingList; +} + +#endif diff --git a/include/musicbrainz5/Relation.h b/include/musicbrainz5/Relation.h new file mode 100644 index 0000000..9d692b0 --- /dev/null +++ b/include/musicbrainz5/Relation.h @@ -0,0 +1,86 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RELATION_H +#define _MUSICBRAINZ5_RELATION_H + +#include +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/AttributeList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CRelationPrivate; + + class CArtist; + class CRelease; + class CReleaseGroup; + class CRecording; + class CLabel; + class CWork; + + class CRelation: public CEntity + { + public: + CRelation(const XMLNode& Node=XMLNode::emptyNode()); + CRelation(const CRelation& Other); + CRelation& operator =(const CRelation& Other); + virtual ~CRelation(); + + virtual CRelation *Clone(); + + std::string Type() const; + std::string Target() const; + std::string Direction() const; + CAttributeList *AttributeList() const; + std::string Begin() const; + std::string End() const; + std::string Ended() const; + CArtist *Artist() const; + CRelease *Release() const; + CReleaseGroup *ReleaseGroup() const; + CRecording *Recording() const; + CLabel *Label() const; + CWork *Work() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CRelationPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/RelationList.h b/include/musicbrainz5/RelationList.h new file mode 100644 index 0000000..fb16e75 --- /dev/null +++ b/include/musicbrainz5/RelationList.h @@ -0,0 +1,65 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RELATION_LIST_H +#define _MUSICBRAINZ5_RELATION_LIST_H + +#include +#include + +#include "musicbrainz5/ListImpl.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CRelation; + class CRelationListPrivate; + + class CRelationList: public CListImpl + { + public: + CRelationList(const XMLNode& Node); + CRelationList(const CRelationList& Other); + CRelationList& operator =(const CRelationList& Other); + virtual ~CRelationList(); + + virtual CRelationList *Clone(); + + std::string TargetType() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CRelationListPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/RelationListList.h b/include/musicbrainz5/RelationListList.h new file mode 100644 index 0000000..56cb9e1 --- /dev/null +++ b/include/musicbrainz5/RelationListList.h @@ -0,0 +1,64 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RELATIONLIST_GROUP_H +#define _MUSICBRAINZ5_RELATIONLIST_GROUP_H + +#include + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CRelationListListPrivate; + + class CRelationList; + + class CRelationListList + { + public: + CRelationListList(); + CRelationListList(const CRelationListList& Other); + CRelationListList& operator =(const CRelationListList& Other); + virtual ~CRelationListList(); + + void Add(CRelationList *RelationList); + int NumItems() const; + CRelationList *Item(int Item) const; + int Offset() const { return 0; } + int Count() const { return NumItems(); } + + std::ostream& Serialise(std::ostream& os) const; + + private: + void Cleanup(); + + CRelationListListPrivate * const m_d; + }; +} + +std::ostream& operator << (std::ostream& os, const MusicBrainz5::CRelationListList& RelationListList); + +#endif diff --git a/include/musicbrainz5/Release.h b/include/musicbrainz5/Release.h new file mode 100644 index 0000000..15b3fcb --- /dev/null +++ b/include/musicbrainz5/Release.h @@ -0,0 +1,93 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RELEASE_H +#define _MUSICBRAINZ5_RELEASE_H + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/LabelInfoList.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/MediumList.h" +#include "musicbrainz5/CollectionList.h" + +#include "musicbrainz5/xmlParser.h" + +#include +#include + +namespace MusicBrainz5 +{ + class CReleasePrivate; + + class CTextRepresentation; + class CArtistCredit; + class CReleaseGroup; + class CMedium; + + class CRelease: public CEntity + { + public: + CRelease(const XMLNode& Node=XMLNode::emptyNode()); + CRelease(const CRelease& Other); + CRelease& operator =(const CRelease& Other); + virtual ~CRelease(); + + virtual CRelease *Clone(); + + std::string ID() const; + std::string Title() const; + std::string Status() const; + std::string Quality() const; + std::string Disambiguation() const; + std::string Packaging() const; + CTextRepresentation *TextRepresentation() const; + CArtistCredit *ArtistCredit() const; + CReleaseGroup *ReleaseGroup() const; + std::string Date() const; + std::string Country() const; + std::string Barcode() const; + std::string ASIN() const; + CLabelInfoList *LabelInfoList() const; + CMediumList *MediumList() const; + CRelationListList *RelationListList() const; + CCollectionList *CollectionList() const; + + CMediumList MediaMatchingDiscID(const std::string& DiscID) const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CReleasePrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/ReleaseGroup.h b/include/musicbrainz5/ReleaseGroup.h new file mode 100644 index 0000000..e106f4a --- /dev/null +++ b/include/musicbrainz5/ReleaseGroup.h @@ -0,0 +1,88 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RELEASE_GROUP_H +#define _MUSICBRAINZ5_RELEASE_GROUP_H + +#include +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/SecondaryTypeList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CReleaseGroupPrivate; + + class CArtistCredit; + class CRating; + class CUserRating; + class CSecondaryType; + + class CReleaseGroup: public CEntity + { + public: + CReleaseGroup(const XMLNode& Node=XMLNode::emptyNode()); + CReleaseGroup(const CReleaseGroup& Other); + CReleaseGroup& operator =(const CReleaseGroup& Other); + virtual ~CReleaseGroup(); + + virtual CReleaseGroup *Clone(); + + std::string ID() const; + std::string PrimaryType() const; + std::string Title() const; + std::string Disambiguation() const; + std::string FirstReleaseDate() const; + CArtistCredit *ArtistCredit() const; + CReleaseList *ReleaseList() const; + CRelationListList *RelationListList() const; + CTagList *TagList() const; + CUserTagList *UserTagList() const; + CRating *Rating() const; + CUserRating *UserRating() const; + CSecondaryTypeList *SecondaryTypeList() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CReleaseGroupPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/ReleaseGroupList.h b/include/musicbrainz5/ReleaseGroupList.h new file mode 100644 index 0000000..6bf8be0 --- /dev/null +++ b/include/musicbrainz5/ReleaseGroupList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RELEASEGROUP_LIST_H +#define _MUSICBRAINZ5_RELEASEGROUP_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CReleaseGroup; + + typedef CListImpl CReleaseGroupList; +} + +#endif diff --git a/include/musicbrainz5/ReleaseList.h b/include/musicbrainz5/ReleaseList.h new file mode 100644 index 0000000..2b19e64 --- /dev/null +++ b/include/musicbrainz5/ReleaseList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_RELEASE_LIST_H +#define _MUSICBRAINZ5_RELEASE_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CRelease; + + typedef CListImpl CReleaseList; +} + +#endif diff --git a/include/musicbrainz5/SecondaryType.h b/include/musicbrainz5/SecondaryType.h new file mode 100644 index 0000000..056649c --- /dev/null +++ b/include/musicbrainz5/SecondaryType.h @@ -0,0 +1,66 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_SECONDARY_TYPE_H +#define _MUSICBRAINZ5_SECONDARY_TYPE_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CSecondaryTypePrivate; + + class CSecondaryType: public CEntity + { + public: + CSecondaryType(const XMLNode& Node=XMLNode::emptyNode()); + CSecondaryType(const CSecondaryType& Other); + CSecondaryType& operator =(const CSecondaryType& Other); + virtual ~CSecondaryType(); + + virtual CSecondaryType *Clone(); + + std::string SecondaryType() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CSecondaryTypePrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/SecondaryTypeList.h b/include/musicbrainz5/SecondaryTypeList.h new file mode 100644 index 0000000..6c51cd0 --- /dev/null +++ b/include/musicbrainz5/SecondaryTypeList.h @@ -0,0 +1,63 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_SECONDARY_TYPE_LIST_H +#define _MUSICBRAINZ5_SECONDARY_TYPE_LIST_H + +#include +#include + +#include "musicbrainz5/ListImpl.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CSecondaryType; + class CSecondaryTypeListPrivate; + + class CSecondaryTypeList: public CListImpl + { + public: + CSecondaryTypeList(const XMLNode& Node=XMLNode::emptyNode()); + CSecondaryTypeList(const CSecondaryTypeList& Other); + CSecondaryTypeList& operator =(const CSecondaryTypeList& Other); + virtual ~CSecondaryTypeList(); + + virtual CSecondaryTypeList *Clone(); + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CSecondaryTypeListPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/Tag.h b/include/musicbrainz5/Tag.h new file mode 100644 index 0000000..fcbb350 --- /dev/null +++ b/include/musicbrainz5/Tag.h @@ -0,0 +1,65 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_TAG_H +#define _MUSICBRAINZ5_TAG_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CTagPrivate; + + class CTag: public CEntity + { + public: + CTag(const XMLNode& Node); + CTag(const CTag& Other); + CTag& operator =(const CTag& Other); + virtual ~CTag(); + + virtual CTag *Clone(); + + int Count() const; + std::string Name() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CTagPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/TagList.h b/include/musicbrainz5/TagList.h new file mode 100644 index 0000000..e2c3860 --- /dev/null +++ b/include/musicbrainz5/TagList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_TAG_LIST_H +#define _MUSICBRAINZ5_TAG_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CTag; + + typedef CListImpl CTagList; +} + +#endif diff --git a/include/musicbrainz5/TextRepresentation.h b/include/musicbrainz5/TextRepresentation.h new file mode 100644 index 0000000..fdb27c5 --- /dev/null +++ b/include/musicbrainz5/TextRepresentation.h @@ -0,0 +1,65 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_TEXT_REPRESENTATION_H +#define _MUSICBRAINZ5_TEXT_REPRESENTATION_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CTextRepresentationPrivate; + + class CTextRepresentation: public CEntity + { + public: + CTextRepresentation(const XMLNode& Node=XMLNode::emptyNode()); + CTextRepresentation(const CTextRepresentation& Other); + CTextRepresentation& operator =(const CTextRepresentation& Other); + virtual ~CTextRepresentation(); + + virtual CTextRepresentation *Clone(); + + std::string Language() const; + std::string Script() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CTextRepresentationPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/Track.h b/include/musicbrainz5/Track.h new file mode 100644 index 0000000..25d4416 --- /dev/null +++ b/include/musicbrainz5/Track.h @@ -0,0 +1,74 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_TRACK_H +#define _MUSICBRAINZ5_TRACK_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CTrackPrivate; + + class CRecording; + class CArtistCredit; + + class CTrack: public CEntity + { + public: + CTrack(const XMLNode& Node=XMLNode::emptyNode()); + CTrack(const CTrack& Other); + CTrack& operator =(const CTrack& Other); + virtual ~CTrack(); + + virtual CTrack *Clone(); + + int Position() const; + std::string Title() const; + CRecording *Recording() const; + int Length() const; + CArtistCredit *ArtistCredit() const; + std::string Number() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CTrackPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/TrackList.h b/include/musicbrainz5/TrackList.h new file mode 100644 index 0000000..24e71b9 --- /dev/null +++ b/include/musicbrainz5/TrackList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_TRACK_LIST_H +#define _MUSICBRAINZ5_TRACK_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CTrack; + + typedef CListImpl CTrackList; +} + +#endif diff --git a/include/musicbrainz5/UserRating.h b/include/musicbrainz5/UserRating.h new file mode 100644 index 0000000..a2215fa --- /dev/null +++ b/include/musicbrainz5/UserRating.h @@ -0,0 +1,63 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_USER_RATING_H +#define _MUSICBRAINZ5_USER_RATING_H + +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CUserRatingPrivate; + + class CUserRating: public CEntity + { + public: + CUserRating(const XMLNode& Node); + CUserRating(const CUserRating& Other); + CUserRating& operator =(const CUserRating& Other); + virtual ~CUserRating(); + + virtual CUserRating *Clone(); + + int UserRating() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CUserRatingPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/UserTag.h b/include/musicbrainz5/UserTag.h new file mode 100644 index 0000000..2115d84 --- /dev/null +++ b/include/musicbrainz5/UserTag.h @@ -0,0 +1,64 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_USER_TAG_H +#define _MUSICBRAINZ5_USER_TAG_H + +#include +#include + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CUserTagPrivate; + + class CUserTag: public CEntity + { + public: + CUserTag(const XMLNode& Node); + CUserTag(const CUserTag& Other); + CUserTag& operator =(const CUserTag& Other); + virtual ~CUserTag(); + + virtual CUserTag *Clone(); + + std::string Name() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + CUserTagPrivate * const m_d; + }; +} + +#endif diff --git a/include/musicbrainz5/UserTagList.h b/include/musicbrainz5/UserTagList.h new file mode 100644 index 0000000..2e8f6af --- /dev/null +++ b/include/musicbrainz5/UserTagList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_USERTAG_LIST_H +#define _MUSICBRAINZ5_USERTAG_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CUserTag; + + typedef CListImpl CUserTagList; +} + +#endif diff --git a/include/musicbrainz5/Work.h b/include/musicbrainz5/Work.h new file mode 100644 index 0000000..c73cf52 --- /dev/null +++ b/include/musicbrainz5/Work.h @@ -0,0 +1,88 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_WORK_H +#define _MUSICBRAINZ5_WORK_H + +#include + +#include "musicbrainz5/Entity.h" +#include "musicbrainz5/AliasList.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/ISWCList.h" + +#include "musicbrainz5/xmlParser.h" + +namespace MusicBrainz5 +{ + class CWorkPrivate; + + class CArtistCredit; + class CISWC; + class CRating; + class CUserRating; + + class CWork: public CEntity + { + public: + CWork(const XMLNode& Node=XMLNode::emptyNode()); + CWork(const CWork& Other); + CWork& operator =(const CWork& Other); + virtual ~CWork(); + + virtual CWork *Clone(); + + std::string ID() const; + std::string Type() const; + std::string Title() const; + CArtistCredit *ArtistCredit() const; + CISWCList *ISWCList() const; + std::string Disambiguation() const; + CAliasList *AliasList() const; + CRelationListList *RelationListList() const; + CTagList *TagList() const; + CUserTagList *UserTagList() const; + CRating *Rating() const; + CUserRating *UserRating() const; + std::string Language() const; + + virtual std::ostream& Serialise(std::ostream& os) const; + static std::string GetElementName(); + + protected: + virtual void ParseAttribute(const std::string& Name, const std::string& Value); + virtual void ParseElement(const XMLNode& Node); + + private: + void Cleanup(); + + CWorkPrivate * const m_d; + }; +} + +#endif + diff --git a/include/musicbrainz5/WorkList.h b/include/musicbrainz5/WorkList.h new file mode 100644 index 0000000..3bf5fd7 --- /dev/null +++ b/include/musicbrainz5/WorkList.h @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_WORK_LIST_H +#define _MUSICBRAINZ5_WORK_LIST_H + +#include "musicbrainz5/ListImpl.h" + +namespace MusicBrainz5 +{ + class CWork; + + typedef CListImpl CWorkList; +} + +#endif diff --git a/include/musicbrainz5/defines.h b/include/musicbrainz5/defines.h new file mode 100644 index 0000000..c33e8ad --- /dev/null +++ b/include/musicbrainz5/defines.h @@ -0,0 +1,43 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#ifndef _MUSICBRAINZ5_DEFINES_H +#define _MUSICBRAINZ5_DEFINES_H + +#if defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) + +#define LIBMB5_DEPRECATED(f) __attribute__((deprecated("Use '" #f "' instead"))) + +#elif defined(__GNUC__) && __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) + +#define LIBMB5_DEPRECATED(f) __attribute__ ((deprecated)) + +#else + +#define LIBMB5_DEPRECATED(f) + +#endif + +#endif diff --git a/include/musicbrainz5/xmlParser.h b/include/musicbrainz5/xmlParser.h new file mode 100644 index 0000000..85ba29f --- /dev/null +++ b/include/musicbrainz5/xmlParser.h @@ -0,0 +1,109 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Christophe Fergeau + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ +#ifndef _MUSICBRAINZ5_XMLPARSER_H +#define _MUSICBRAINZ5_XMLPARSER_H + +#include + +struct _xmlNode; +typedef _xmlNode* xmlNodePtr; + +struct _xmlDoc; +typedef _xmlDoc* xmlDocPtr; + +struct _xmlAttr; +typedef _xmlAttr* xmlAttrPtr; + +struct XMLResults +{ + std::string message; + int line; + int code; + + XMLResults(); +}; + +const int eXMLErrorNone = 0; + +class XMLAttribute; +class XMLNode +{ + public: + static XMLNode emptyNode(); + bool isEmpty() const; + + virtual ~XMLNode(); + + const XMLAttribute getAttribute(const char *name = NULL) const; + bool isAttributeSet(const char *name) const; + + XMLNode getChildNode(const char *name = NULL) const; + XMLNode next() const; + const char *getName() const; + const char *getText() const; + + bool operator ==(const XMLNode &rhs) const; + + protected: + XMLNode(xmlNodePtr node); + + xmlNodePtr mNode; + + private: + xmlAttrPtr getAttributeRaw(const char *name) const; +}; + +bool operator !=(const XMLNode &lhs, const XMLNode &rhs); + +class XMLRootNode: public XMLNode +{ + public: + static XMLNode* parseString(const std::string &xml, XMLResults *results); + static XMLNode* parseFile(const std::string &filename, XMLResults *results); + + virtual ~XMLRootNode(); + + private: + XMLRootNode(xmlDocPtr doc); + + xmlDocPtr mDoc; +}; + +class XMLAttribute +{ + public: + bool isEmpty() const; + std::string name() const; + std::string value() const; + const XMLAttribute next() const; + + friend const XMLAttribute XMLNode::getAttribute(const char *name) const; + + private: + XMLAttribute(xmlAttrPtr attr); + xmlAttrPtr mAttr; +}; + +#endif diff --git a/libmusicbrainz5.pc.cmake b/libmusicbrainz5.pc.cmake new file mode 100644 index 0000000..b9cb903 --- /dev/null +++ b/libmusicbrainz5.pc.cmake @@ -0,0 +1,13 @@ +prefix=${CMAKE_INSTALL_PREFIX} +exec_prefix=${EXEC_INSTALL_PREFIX} +libdir=${LIB_INSTALL_DIR} +includedir=${INCLUDE_INSTALL_DIR} + +Name: ${PROJECT_NAME} +Description: The Musicbrainz Client Library. +URL: http://musicbrainz.org/doc/libmusicbrainz +Version: ${PROJECT_VERSION} +Requires.private: neon >= 0.25 libxml-2.0 +Libs: -L${LIB_INSTALL_DIR} -lmusicbrainz5 +Cflags: -I${INCLUDE_INSTALL_DIR} + diff --git a/src/Alias.cc b/src/Alias.cc new file mode 100644 index 0000000..bdafc99 --- /dev/null +++ b/src/Alias.cc @@ -0,0 +1,174 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Alias.h" + +class MusicBrainz5::CAliasPrivate +{ +public: + std::string m_Locale; + std::string m_Text; + std::string m_SortName; + std::string m_Type; + std::string m_Primary; + std::string m_BeginDate; + std::string m_EndDate; +}; + +MusicBrainz5::CAlias::CAlias(const XMLNode& Node) +: CEntity(), + m_d(new CAliasPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Alias node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + if (Node.getText()) + ProcessItem(Node,m_d->m_Text); + } +} + +MusicBrainz5::CAlias::CAlias(const CAlias& Other) +: CEntity(), + m_d(new CAliasPrivate) +{ + *this=Other; +} + +MusicBrainz5::CAlias& MusicBrainz5::CAlias::operator =(const CAlias& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Locale=Other.m_d->m_Locale; + m_d->m_Text=Other.m_d->m_Text; + m_d->m_SortName=Other.m_d->m_SortName; + m_d->m_Type=Other.m_d->m_Type; + m_d->m_Primary=Other.m_d->m_Primary; + m_d->m_BeginDate=Other.m_d->m_BeginDate; + m_d->m_EndDate=Other.m_d->m_EndDate; + } + + return *this; +} + +MusicBrainz5::CAlias::~CAlias() +{ + delete m_d; +} + +MusicBrainz5::CAlias *MusicBrainz5::CAlias::Clone() +{ + return new CAlias(*this); +} + +void MusicBrainz5::CAlias::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("locale"==Name) + m_d->m_Locale=Value; + else if ("sort-name"==Name) + m_d->m_SortName=Value; + else if ("type"==Name) + m_d->m_Type=Value; + else if ("primary"==Name) + m_d->m_Primary=Value; + else if ("begin-date"==Name) + m_d->m_BeginDate=Value; + else if ("end-date"==Name) + m_d->m_EndDate=Value; + else + { + std::cerr << "Unrecognised alias attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CAlias::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + std::cerr << "Unrecognised alias element: '" << NodeName << std::endl; +} + +std::string MusicBrainz5::CAlias::GetElementName() +{ + return "alias"; +} + +std::string MusicBrainz5::CAlias::Locale() const +{ + return m_d->m_Locale; +} + +std::string MusicBrainz5::CAlias::Text() const +{ + return m_d->m_Text; +} + +std::string MusicBrainz5::CAlias::SortName() const +{ + return m_d->m_SortName; +} + +std::string MusicBrainz5::CAlias::Type() const +{ + return m_d->m_Type; +} + +std::string MusicBrainz5::CAlias::Primary() const +{ + return m_d->m_Primary; +} + +std::string MusicBrainz5::CAlias::BeginDate() const +{ + return m_d->m_BeginDate; +} + +std::string MusicBrainz5::CAlias::EndDate() const +{ + return m_d->m_EndDate; +} + +std::ostream& MusicBrainz5::CAlias::Serialise(std::ostream& os) const +{ + os << "Alias:" << std::endl; + + CEntity::Serialise(os); + + os << "\tLocale: " << Locale() << std::endl; + os << "\tText: " << Text() << std::endl; + os << "\tSort Name: " << SortName() << std::endl; + os << "\tType: " << Type() << std::endl; + os << "\tPrimary: " << Primary() << std::endl; + os << "\tBeginDate: " << BeginDate() << std::endl; + os << "\tEndDate: " << EndDate() << std::endl; + + return os; +} diff --git a/src/Annotation.cc b/src/Annotation.cc new file mode 100644 index 0000000..e138c83 --- /dev/null +++ b/src/Annotation.cc @@ -0,0 +1,153 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Annotation.h" + +class MusicBrainz5::CAnnotationPrivate +{ +public: + std::string m_Type; + std::string m_Entity; + std::string m_Name; + std::string m_Text; +}; + +MusicBrainz5::CAnnotation::CAnnotation(const XMLNode& Node) +: CEntity(), + m_d(new CAnnotationPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Annotation node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CAnnotation::CAnnotation(const CAnnotation& Other) +: CEntity(), + m_d(new CAnnotationPrivate) +{ + *this=Other; +} + +MusicBrainz5::CAnnotation& MusicBrainz5::CAnnotation::operator =(const CAnnotation& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Type=Other.m_d->m_Type; + m_d->m_Entity=Other.m_d->m_Entity; + m_d->m_Name=Other.m_d->m_Name; + m_d->m_Text=Other.m_d->m_Text; + } + + return *this; +} + +MusicBrainz5::CAnnotation::~CAnnotation() +{ + delete m_d; +} + +MusicBrainz5::CAnnotation *MusicBrainz5::CAnnotation::Clone() +{ + return new CAnnotation(*this); +} + +void MusicBrainz5::CAnnotation::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("type"==Name) + m_d->m_Type=Value; + else + { + std::cerr << "Unrecognised annotation attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CAnnotation::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("entity"==NodeName) + { + ProcessItem(Node,m_d->m_Entity); + } + else if ("name"==NodeName) + { + ProcessItem(Node,m_d->m_Name); + } + else if ("text"==NodeName) + { + ProcessItem(Node,m_d->m_Text); + } + else + { + std::cerr << "Unrecognised annotation element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CAnnotation::GetElementName() +{ + return "annotation"; +} + +std::string MusicBrainz5::CAnnotation::Type() const +{ + return m_d->m_Type; +} + +std::string MusicBrainz5::CAnnotation::Entity() const +{ + return m_d->m_Entity; +} + +std::string MusicBrainz5::CAnnotation::Name() const +{ + return m_d->m_Name; +} + +std::string MusicBrainz5::CAnnotation::Text() const +{ + return m_d->m_Text; +} + +std::ostream& MusicBrainz5::CAnnotation::Serialise(std::ostream& os) const +{ + os << "Annotation:" << std::endl; + + CEntity::Serialise(os); + + os << "\tType: " << Type() << std::endl; + os << "\tEntity: " << Entity() << std::endl; + os << "\tName: " << Name() << std::endl; + os << "\tText: " << Text() << std::endl; + + return os; +} diff --git a/src/Artist.cc b/src/Artist.cc new file mode 100644 index 0000000..bcf37c3 --- /dev/null +++ b/src/Artist.cc @@ -0,0 +1,487 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Artist.h" + +#include "musicbrainz5/Lifespan.h" +#include "musicbrainz5/IPI.h" +#include "musicbrainz5/Rating.h" +#include "musicbrainz5/UserRating.h" +#include "musicbrainz5/AliasList.h" +#include "musicbrainz5/Alias.h" +#include "musicbrainz5/RecordingList.h" +#include "musicbrainz5/Recording.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/ReleaseGroupList.h" +#include "musicbrainz5/ReleaseGroup.h" +#include "musicbrainz5/LabelList.h" +#include "musicbrainz5/Label.h" +#include "musicbrainz5/WorkList.h" +#include "musicbrainz5/Work.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/Relation.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/Tag.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/UserTag.h" + +class MusicBrainz5::CArtistPrivate +{ + public: + CArtistPrivate() + : m_IPIList(0), + m_Lifespan(0), + m_AliasList(0), + m_RecordingList(0), + m_ReleaseList(0), + m_ReleaseGroupList(0), + m_LabelList(0), + m_WorkList(0), + m_RelationListList(0), + m_TagList(0), + m_UserTagList(0), + m_Rating(0), + m_UserRating(0) + { + } + + std::string m_ID; + std::string m_Type; + std::string m_Name; + std::string m_SortName; + std::string m_Gender; + std::string m_Country; + std::string m_Disambiguation; + CIPIList *m_IPIList; + CLifespan *m_Lifespan; + CAliasList *m_AliasList; + CRecordingList *m_RecordingList; + CReleaseList *m_ReleaseList; + CReleaseGroupList *m_ReleaseGroupList; + CLabelList *m_LabelList; + CWorkList *m_WorkList; + CRelationListList *m_RelationListList; + CTagList *m_TagList; + CUserTagList *m_UserTagList; + CRating *m_Rating; + CUserRating *m_UserRating; +}; + +MusicBrainz5::CArtist::CArtist(const XMLNode& Node) +: CEntity(), + m_d(new CArtistPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Artist node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CArtist::CArtist(const CArtist& Other) +: CEntity(), + m_d(new CArtistPrivate) +{ + *this=Other; +} + +MusicBrainz5::CArtist& MusicBrainz5::CArtist::operator =(const CArtist& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Type=Other.m_d->m_Type; + m_d->m_Name=Other.m_d->m_Name; + m_d->m_SortName=Other.m_d->m_SortName; + m_d->m_Gender=Other.m_d->m_Gender; + m_d->m_Country=Other.m_d->m_Country; + m_d->m_Disambiguation=Other.m_d->m_Disambiguation; + + if (Other.m_d->m_IPIList) + m_d->m_IPIList=new CIPIList(*Other.m_d->m_IPIList); + + if (Other.m_d->m_Lifespan) + m_d->m_Lifespan=new CLifespan(*Other.m_d->m_Lifespan); + + if (Other.m_d->m_AliasList) + m_d->m_AliasList=new CAliasList(*Other.m_d->m_AliasList); + + if (Other.m_d->m_RecordingList) + m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); + + if (Other.m_d->m_ReleaseList) + m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); + + if (Other.m_d->m_ReleaseGroupList) + m_d->m_ReleaseGroupList=new CReleaseGroupList(*Other.m_d->m_ReleaseGroupList); + + if (Other.m_d->m_LabelList) + m_d->m_LabelList=new CLabelList(*Other.m_d->m_LabelList); + + if (Other.m_d->m_WorkList) + m_d->m_WorkList=new CWorkList(*Other.m_d->m_WorkList); + + if (Other.m_d->m_RelationListList) + m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); + + if (Other.m_d->m_TagList) + m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); + + if (Other.m_d->m_UserTagList) + m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); + + if (Other.m_d->m_Rating) + m_d->m_Rating=new CRating(*Other.m_d->m_Rating); + + if (Other.m_d->m_UserRating) + m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); + } + + return *this; +} + +MusicBrainz5::CArtist::~CArtist() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CArtist::Cleanup() +{ + delete m_d->m_IPIList; + m_d->m_IPIList=0; + + delete m_d->m_Lifespan; + m_d->m_Lifespan=0; + + delete m_d->m_AliasList; + m_d->m_AliasList=0; + + delete m_d->m_RecordingList; + m_d->m_RecordingList=0; + + delete m_d->m_ReleaseList; + m_d->m_ReleaseList=0; + + delete m_d->m_ReleaseGroupList; + m_d->m_ReleaseGroupList=0; + + delete m_d->m_LabelList; + m_d->m_LabelList=0; + + delete m_d->m_WorkList; + m_d->m_WorkList=0; + + delete m_d->m_RelationListList; + m_d->m_RelationListList=0; + + delete m_d->m_TagList; + m_d->m_TagList=0; + + delete m_d->m_UserTagList; + m_d->m_UserTagList=0; + + delete m_d->m_Rating; + m_d->m_Rating=0; + + delete m_d->m_UserRating; + m_d->m_UserRating=0; +} + +MusicBrainz5::CArtist *MusicBrainz5::CArtist::Clone() +{ + return new CArtist(*this); +} + +void MusicBrainz5::CArtist::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else if ("type"==Name) + m_d->m_Type=Value; + else + { + std::cerr << "Unrecognised artist attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CArtist::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("name"==NodeName) + { + ProcessItem(Node,m_d->m_Name); + } + else if ("sort-name"==NodeName) + { + ProcessItem(Node,m_d->m_SortName); + } + else if ("gender"==NodeName) + { + ProcessItem(Node,m_d->m_Gender); + } + else if ("country"==NodeName) + { + ProcessItem(Node,m_d->m_Country); + } + else if ("disambiguation"==NodeName) + { + ProcessItem(Node,m_d->m_Disambiguation); + } + else if ("ipi"==NodeName) + { + //Ignore IPI + } + else if ("ipi-list"==NodeName) + { + ProcessItem(Node,m_d->m_IPIList); + } + else if ("life-span"==NodeName) + { + ProcessItem(Node,m_d->m_Lifespan); + } + else if ("alias-list"==NodeName) + { + ProcessItem(Node,m_d->m_AliasList); + } + else if ("recording-list"==NodeName) + { + ProcessItem(Node,m_d->m_RecordingList); + } + else if ("release-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseList); + } + else if ("release-group-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseGroupList); + } + else if ("label-list"==NodeName) + { + ProcessItem(Node,m_d->m_LabelList); + } + else if ("work-list"==NodeName) + { + ProcessItem(Node,m_d->m_WorkList); + } + else if ("relation-list"==NodeName) + { + ProcessRelationList(Node,m_d->m_RelationListList); + } + else if ("tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_TagList); + } + else if ("user-tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_UserTagList); + } + else if ("rating"==NodeName) + { + ProcessItem(Node,m_d->m_Rating); + } + else if ("user-rating"==NodeName) + { + ProcessItem(Node,m_d->m_UserRating); + } + else + { + std::cerr << "Unrecognised artist element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CArtist::GetElementName() +{ + return "artist"; +} + +std::string MusicBrainz5::CArtist::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CArtist::Type() const +{ + return m_d->m_Type; +} + +std::string MusicBrainz5::CArtist::Name() const +{ + return m_d->m_Name; +} + +std::string MusicBrainz5::CArtist::SortName() const +{ + return m_d->m_SortName; +} + +std::string MusicBrainz5::CArtist::Gender() const +{ + return m_d->m_Gender; +} + +std::string MusicBrainz5::CArtist::Country() const +{ + return m_d->m_Country; +} + +std::string MusicBrainz5::CArtist::Disambiguation() const +{ + return m_d->m_Disambiguation; +} + +MusicBrainz5::CIPIList *MusicBrainz5::CArtist::IPIList() const +{ + return m_d->m_IPIList; +} + +MusicBrainz5::CLifespan *MusicBrainz5::CArtist::Lifespan() const +{ + return m_d->m_Lifespan; +} + +MusicBrainz5::CAliasList *MusicBrainz5::CArtist::AliasList() const +{ + return m_d->m_AliasList; +} + +MusicBrainz5::CRecordingList *MusicBrainz5::CArtist::RecordingList() const +{ + return m_d->m_RecordingList; +} + +MusicBrainz5::CReleaseList *MusicBrainz5::CArtist::ReleaseList() const +{ + return m_d->m_ReleaseList; +} + +MusicBrainz5::CReleaseGroupList *MusicBrainz5::CArtist::ReleaseGroupList() const +{ + return m_d->m_ReleaseGroupList; +} + +MusicBrainz5::CLabelList *MusicBrainz5::CArtist::LabelList() const +{ + return m_d->m_LabelList; +} + +MusicBrainz5::CWorkList *MusicBrainz5::CArtist::WorkList() const +{ + return m_d->m_WorkList; +} + +MusicBrainz5::CRelationListList *MusicBrainz5::CArtist::RelationListList() const +{ + return m_d->m_RelationListList; +} + +MusicBrainz5::CTagList *MusicBrainz5::CArtist::TagList() const +{ + return m_d->m_TagList; +} + +MusicBrainz5::CUserTagList *MusicBrainz5::CArtist::UserTagList() const +{ + return m_d->m_UserTagList; +} + +MusicBrainz5::CRating *MusicBrainz5::CArtist::Rating() const +{ + return m_d->m_Rating; +} + +MusicBrainz5::CUserRating *MusicBrainz5::CArtist::UserRating() const +{ + return m_d->m_UserRating; +} + +std::ostream& MusicBrainz5::CArtist::Serialise(std::ostream& os) const +{ + os << "Artist:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tType: " << Type() << std::endl; + os << "\tName: " << Name() << std::endl; + os << "\tSort name: " << SortName() << std::endl; + os << "\tGender: " << Gender() << std::endl; + os << "\tCountry: " << Country() << std::endl; + os << "\tDisambiguation: " << Disambiguation() << std::endl; + + if (IPIList()) + os << *IPIList() << std::endl; + + if (Lifespan()) + os << *Lifespan() << std::endl; + + if (AliasList()) + os << *AliasList() << std::endl; + + if (RecordingList()) + os << *RecordingList() << std::endl; + + if (ReleaseList()) + os << *ReleaseList() << std::endl; + + if (ReleaseGroupList()) + os << *ReleaseGroupList() << std::endl; + + if (LabelList()) + os << *LabelList() << std::endl; + + if (WorkList()) + os << *WorkList() << std::endl; + + if (RelationListList()) + os << *RelationListList() << std::endl; + + if (TagList()) + os << *TagList() << std::endl; + + if (UserTagList()) + os << *UserTagList() << std::endl; + + if (Rating()) + os << *Rating() << std::endl; + + if (UserRating()) + os << *UserRating() << std::endl; + + return os; +} + diff --git a/src/ArtistCredit.cc b/src/ArtistCredit.cc new file mode 100644 index 0000000..6ad7e64 --- /dev/null +++ b/src/ArtistCredit.cc @@ -0,0 +1,139 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/ArtistCredit.h" + +#include "musicbrainz5/NameCreditList.h" +#include "musicbrainz5/NameCredit.h" + +class MusicBrainz5::CArtistCreditPrivate +{ + public: + CArtistCreditPrivate() + : m_NameCreditList(0) + { + } + + CNameCreditList *m_NameCreditList; +}; + +MusicBrainz5::CArtistCredit::CArtistCredit(const XMLNode& Node) +: CEntity(), + m_d(new CArtistCreditPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Artist credit node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + m_d->m_NameCreditList=new CNameCreditList(Node); + } +} + +MusicBrainz5::CArtistCredit::CArtistCredit(const CArtistCredit& Other) +: CEntity(), + m_d(new CArtistCreditPrivate) +{ + *this=Other; +} + +MusicBrainz5::CArtistCredit& MusicBrainz5::CArtistCredit::operator =(const CArtistCredit& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + if (Other.m_d->m_NameCreditList) + m_d->m_NameCreditList=new CNameCreditList(*Other.m_d->m_NameCreditList); + } + + return *this; +} + +MusicBrainz5::CArtistCredit::~CArtistCredit() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CArtistCredit::Cleanup() +{ + delete m_d->m_NameCreditList; + m_d->m_NameCreditList=0; +} + +MusicBrainz5::CArtistCredit *MusicBrainz5::CArtistCredit::Clone() +{ + return new CArtistCredit(*this); +} + +void MusicBrainz5::CArtistCredit::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised artistcredit attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CArtistCredit::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("name-credit"==NodeName) + { + //The artist credit element is a special case, in that all it contains is a list of name-credits + //Parsing of this list is handled in the constructor + } + else + { + std::cerr << "Unrecognised artistcredit element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CArtistCredit::GetElementName() +{ + return "artist-credit"; +} + +MusicBrainz5::CNameCreditList *MusicBrainz5::CArtistCredit::NameCreditList() const +{ + return m_d->m_NameCreditList; +} + +std::ostream& MusicBrainz5::CArtistCredit::Serialise(std::ostream& os) const +{ + os << "Artist credit:" << std::endl; + + CEntity::Serialise(os); + + if (NameCreditList()) + os << *NameCreditList() << std::endl; + + return os; +} diff --git a/src/Attribute.cc b/src/Attribute.cc new file mode 100644 index 0000000..9e0afce --- /dev/null +++ b/src/Attribute.cc @@ -0,0 +1,114 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Attribute.h" + +class MusicBrainz5::CAttributePrivate +{ + public: + std::string m_Text; +}; + +MusicBrainz5::CAttribute::CAttribute(const XMLNode& Node) +: CEntity(), + m_d(new CAttributePrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Attribute node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + if (Node.getText()) + ProcessItem(Node,m_d->m_Text); + } +} + +MusicBrainz5::CAttribute::CAttribute(const CAttribute& Other) +: CEntity(), + m_d(new CAttributePrivate) +{ + *this=Other; +} + +MusicBrainz5::CAttribute& MusicBrainz5::CAttribute::operator =(const CAttribute& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Text=Other.m_d->m_Text; + } + + return *this; +} + +MusicBrainz5::CAttribute::~CAttribute() +{ + delete m_d; +} + +MusicBrainz5::CAttribute *MusicBrainz5::CAttribute::Clone() +{ + return new CAttribute(*this); +} + +void MusicBrainz5::CAttribute::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised attribute attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CAttribute::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + std::cerr << "Unrecognised attribute element: '" << NodeName << "'" << std::endl; +} + +std::string MusicBrainz5::CAttribute::GetElementName() +{ + return "attribute"; +} + +std::string MusicBrainz5::CAttribute::Text() const +{ + return m_d->m_Text; +} + +std::ostream& MusicBrainz5::CAttribute::Serialise(std::ostream& os) const +{ + os << "Attribute:" << std::endl; + + CEntity::Serialise(os); + + os << "\tText: " << Text() << std::endl; + + return os; +} + + diff --git a/src/CDStub.cc b/src/CDStub.cc new file mode 100644 index 0000000..f237351 --- /dev/null +++ b/src/CDStub.cc @@ -0,0 +1,199 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/CDStub.h" + +#include "musicbrainz5/NonMBTrackList.h" +#include "musicbrainz5/NonMBTrack.h" + +class MusicBrainz5::CCDStubPrivate +{ + public: + CCDStubPrivate() + : m_NonMBTrackList(0) + { + } + + std::string m_ID; + std::string m_Title; + std::string m_Artist; + std::string m_Barcode; + std::string m_Comment; + CNonMBTrackList *m_NonMBTrackList; +}; + +MusicBrainz5::CCDStub::CCDStub(const XMLNode& Node) +: CEntity(), + m_d(new CCDStubPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "CDStub node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CCDStub::CCDStub(const CCDStub& Other) +: CEntity(), + m_d(new CCDStubPrivate) +{ + *this=Other; +} + +MusicBrainz5::CCDStub& MusicBrainz5::CCDStub::operator =(const CCDStub& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Title=Other.m_d->m_Title; + m_d->m_Artist=Other.m_d->m_Artist; + m_d->m_Barcode=Other.m_d->m_Barcode; + m_d->m_Comment=Other.m_d->m_Comment; + + if (Other.m_d->m_NonMBTrackList) + m_d->m_NonMBTrackList=new CNonMBTrackList(*Other.m_d->m_NonMBTrackList); + } + + return *this; +} + +MusicBrainz5::CCDStub::~CCDStub() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CCDStub::Cleanup() +{ + delete m_d->m_NonMBTrackList; + m_d->m_NonMBTrackList=0; +} + +MusicBrainz5::CCDStub *MusicBrainz5::CCDStub::Clone() +{ + return new CCDStub(*this); +} + +void MusicBrainz5::CCDStub::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else + { + std::cerr << "Unrecognised cdstub attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CCDStub::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("artist"==NodeName) + { + ProcessItem(Node,m_d->m_Artist); + } + else if ("barcode"==NodeName) + { + ProcessItem(Node,m_d->m_Barcode); + } + else if ("comment"==NodeName) + { + ProcessItem(Node,m_d->m_Comment); + } + else if ("track-list"==NodeName) + { + ProcessItem(Node,m_d->m_NonMBTrackList); + } + else + { + std::cerr << "Unrecognised cd stub element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CCDStub::GetElementName() +{ + return "cdstub"; +} + +std::string MusicBrainz5::CCDStub::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CCDStub::Title() const +{ + return m_d->m_Title; +} + +std::string MusicBrainz5::CCDStub::Artist() const +{ + return m_d->m_Artist; +} + +std::string MusicBrainz5::CCDStub::Barcode() const +{ + return m_d->m_Barcode; +} + +std::string MusicBrainz5::CCDStub::Comment() const +{ + return m_d->m_Comment; +} + +MusicBrainz5::CNonMBTrackList *MusicBrainz5::CCDStub::NonMBTrackList() const +{ + return m_d->m_NonMBTrackList; +} + +std::ostream& MusicBrainz5::CCDStub::Serialise(std::ostream& os) const +{ + os << "CDStub:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tTitle: " << Title() << std::endl; + os << "\tArtist: " << Artist() << std::endl; + os << "\tBarcode: " << Barcode() << std::endl; + os << "\tComment: " << Comment() << std::endl; + + if (NonMBTrackList()) + os << *NonMBTrackList() << std::endl; + + return os; +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..c91a565 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,75 @@ +SET(CMAKE_INCLUDE_CURRENT_DIR ON) +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_BINARY_DIR}/../include + ${NEON_INCLUDE_DIR} + ${LIBXML2_INCLUDE_DIR} +) + +SET(_sources Alias.cc Annotation.cc Artist.cc ArtistCredit.cc Attribute.cc CDStub.cc Collection.cc + Disc.cc Entity.cc FreeDBDisc.cc HTTPFetch.cc ISRC.cc Label.cc LabelInfo.cc Lifespan.cc List.cc + mb5_c.cc Medium.cc MediumList.cc Message.cc Metadata.cc NameCredit.cc NonMBTrack.cc PUID.cc + Query.cc Rating.cc Recording.cc Relation.cc RelationList.cc Release.cc ReleaseGroup.cc Tag.cc + TextRepresentation.cc Track.cc UserRating.cc UserTag.cc Work.cc xmlParser.cc + RelationListList.cc ISWCList.cc ISWC.cc SecondaryType.cc SecondaryTypeList.cc IPI.cc) + +# when crosscompiling import the executable targets from a file +IF(CMAKE_CROSSCOMPILING) + SET(IMPORT_EXECUTABLES "IMPORTFILE-NOTFOUND" CACHE FILEPATH "Point it to the export file from a native build") + INCLUDE(${IMPORT_EXECUTABLES}) +ENDIF(CMAKE_CROSSCOMPILING) + +# only build the generator if not crosscompiling +IF(NOT CMAKE_CROSSCOMPILING) + ADD_EXECUTABLE(make-c-interface make-c-interface.cc xmlParser.cc) + TARGET_LINK_LIBRARIES(make-c-interface ${LIBXML2_LIBRARIES}) +ENDIF(NOT CMAKE_CROSSCOMPILING) + +# export the generator target to a file, so it can be imported (see above) by another build +# the IF() is not necessary, but makes the intention clearer +IF(NOT CMAKE_CROSSCOMPILING) + EXPORT(TARGETS make-c-interface FILE ${CMAKE_BINARY_DIR}/ImportExecutables.cmake ) +ENDIF(NOT CMAKE_CROSSCOMPILING) + +ADD_CUSTOM_COMMAND( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.cc ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.h ${CMAKE_CURRENT_BINARY_DIR}/../include/musicbrainz5/mb5_c.h + COMMAND make-c-interface ${CMAKE_CURRENT_SOURCE_DIR} cinterface.xml ${CMAKE_CURRENT_BINARY_DIR} mb5_c.cc mb5_c.h + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.h ${CMAKE_CURRENT_BINARY_DIR}/../include/musicbrainz5/mb5_c.h + DEPENDS make-c-interface cinterface.xml *.inc +) + +ADD_CUSTOM_TARGET(src_gen DEPENDS mb5_c.h) + +ADD_LIBRARY(musicbrainz5 SHARED ${_sources}) + +SET_TARGET_PROPERTIES(musicbrainz5 PROPERTIES + VERSION ${musicbrainz5_VERSION} + SOVERSION ${musicbrainz5_SOVERSION} + DEFINE_SYMBOL MB_API_EXPORTS +) + +if(CMAKE_BUILD_TYPE STREQUAL Debug) + SET_TARGET_PROPERTIES(musicbrainz5 PROPERTIES + DEFINE_SYMBOL _MB5_DEBUG_ + ) + IF(CMAKE_COMPILER_IS_GNUCXX) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb -O0") + ENDIF(CMAKE_COMPILER_IS_GNUCXX) +endif(CMAKE_BUILD_TYPE STREQUAL Debug) + +TARGET_LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES} ${LIBXML2_LIBRARIES}) + +IF(WIN32) + TARGET_LINK_LIBRARIES(musicbrainz5 wsock32 winmm ws2_32) +ENDIF(WIN32) + +IF(CMAKE_COMPILER_IS_GNUCXX) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors") + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) + #set_source_files_properties(mb5_c.cc PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") +ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +INSTALL(TARGETS musicbrainz5 DESTINATION ${LIB_INSTALL_DIR}) diff --git a/src/Collection.cc b/src/Collection.cc new file mode 100644 index 0000000..293af2c --- /dev/null +++ b/src/Collection.cc @@ -0,0 +1,174 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Collection.h" + +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Release.h" + +class MusicBrainz5::CCollectionPrivate +{ + public: + CCollectionPrivate() + : m_ReleaseList(0) + { + } + + std::string m_ID; + std::string m_Name; + std::string m_Editor; + CReleaseList *m_ReleaseList; +}; +MusicBrainz5::CCollection::CCollection(const XMLNode& Node) +: CEntity(), + m_d(new CCollectionPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Medium node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CCollection::CCollection(const CCollection& Other) +: CEntity(), + m_d(new CCollectionPrivate) +{ + *this=Other; +} + +MusicBrainz5::CCollection& MusicBrainz5::CCollection::operator =(const CCollection& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Name=Other.m_d->m_Name; + m_d->m_Editor=Other.m_d->m_Editor; + + if (Other.m_d->m_ReleaseList) + m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); + } + + return *this; +} + +MusicBrainz5::CCollection::~CCollection() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CCollection::Cleanup() +{ + delete m_d->m_ReleaseList; + m_d->m_ReleaseList=0; +} + +MusicBrainz5::CCollection *MusicBrainz5::CCollection::Clone() +{ + return new CCollection(*this); +} + +void MusicBrainz5::CCollection::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else + { + std::cerr << "Unrecognised collection attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CCollection::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("name"==NodeName) + { + ProcessItem(Node,m_d->m_Name); + } + else if ("editor"==NodeName) + { + ProcessItem(Node,m_d->m_Editor); + } + else if ("release-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseList); + } + else + { + std::cerr << "Unrecognised collection element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CCollection::GetElementName() +{ + return "collection"; +} + +std::string MusicBrainz5::CCollection::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CCollection::Name() const +{ + return m_d->m_Name; +} + +std::string MusicBrainz5::CCollection::Editor() const +{ + return m_d->m_Editor; +} + +MusicBrainz5::CReleaseList *MusicBrainz5::CCollection::ReleaseList() const +{ + return m_d->m_ReleaseList; +} + +std::ostream& MusicBrainz5::CCollection::Serialise(std::ostream& os) const +{ + os << "Collection:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tName: " << Name() << std::endl; + os << "\tEditor: " << Editor() << std::endl; + + if (ReleaseList()) + os << *ReleaseList() << std::endl; + + return os; +} diff --git a/src/Disc.cc b/src/Disc.cc new file mode 100644 index 0000000..0616ea7 --- /dev/null +++ b/src/Disc.cc @@ -0,0 +1,165 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Disc.h" + +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Release.h" + +class MusicBrainz5::CDiscPrivate +{ + public: + CDiscPrivate() + : m_Sectors(0), + m_ReleaseList(0) + { + } + + std::string m_ID; + int m_Sectors; + CReleaseList *m_ReleaseList; +}; + +MusicBrainz5::CDisc::CDisc(const XMLNode& Node) +: CEntity(), + m_d(new CDiscPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Disc node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CDisc::CDisc(const CDisc& Other) +: CEntity(), + m_d(new CDiscPrivate) +{ + *this=Other; +} + +MusicBrainz5::CDisc& MusicBrainz5::CDisc::operator =(const CDisc& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Sectors=Other.m_d->m_Sectors; + + if (Other.m_d->m_ReleaseList) + m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); + } + + return *this; +} + +MusicBrainz5::CDisc::~CDisc() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CDisc::Cleanup() +{ + delete m_d->m_ReleaseList; + m_d->m_ReleaseList=0; +} + +MusicBrainz5::CDisc *MusicBrainz5::CDisc::Clone() +{ + return new CDisc(*this); +} + +void MusicBrainz5::CDisc::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + ProcessItem(Value,m_d->m_ID); + else + { + std::cerr << "Unrecognised disc attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CDisc::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("sectors"==NodeName) + { + ProcessItem(Node,m_d->m_Sectors); + } + else if ("release-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseList); + } + else + { + std::cerr << "Unrecognised disc element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CDisc::GetElementName() +{ + return "disc"; +} + +std::string MusicBrainz5::CDisc::ID() const +{ + return m_d->m_ID; +} + +int MusicBrainz5::CDisc::Sectors() const +{ + return m_d->m_Sectors; +} + +MusicBrainz5::CReleaseList *MusicBrainz5::CDisc::ReleaseList() const +{ + return m_d->m_ReleaseList; +} + +std::ostream& MusicBrainz5::CDisc::Serialise(std::ostream& os) const +{ + os << "Disc:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tSectors: " << Sectors() << std::endl; + + if (ReleaseList()) + os << *ReleaseList() << std::endl; + + return os; +} + diff --git a/src/Entity.cc b/src/Entity.cc new file mode 100644 index 0000000..3a5e870 --- /dev/null +++ b/src/Entity.cc @@ -0,0 +1,172 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Entity.h" + +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/RelationListList.h" + +class MusicBrainz5::CEntityPrivate +{ + public: + CEntityPrivate() + { + } + + std::map m_ExtAttributes; + std::map m_ExtElements; +}; + +MusicBrainz5::CEntity::CEntity() +: m_d(new CEntityPrivate) +{ +} + +MusicBrainz5::CEntity::CEntity(const CEntity& Other) +: m_d(new CEntityPrivate) +{ + *this=Other; +} + +MusicBrainz5::CEntity& MusicBrainz5::CEntity::operator =(const CEntity& Other) +{ + if (this!=&Other) + { + Cleanup(); + + m_d->m_ExtAttributes=Other.m_d->m_ExtAttributes; + m_d->m_ExtElements=Other.m_d->m_ExtElements; + } + + return *this; +} + +MusicBrainz5::CEntity::~CEntity() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CEntity::Cleanup() +{ +} + +void MusicBrainz5::CEntity::Parse(const XMLNode& Node) +{ + if (!Node.isEmpty()) + { + for (XMLAttribute Attr = Node.getAttribute(); + !Attr.isEmpty(); + Attr = Attr.next()) + { + std::string Name=Attr.name(); + std::string Value=Attr.value(); + + if ("ext:"==Name.substr(0,4)) + m_d->m_ExtAttributes[Name.substr(4)]=Value; + else + ParseAttribute(Name,Value); + } + + //std::cout << "Node: " << std::endl << Node.createXMLString(true) << std::endl; + + for (XMLNode ChildNode = Node.getChildNode(); + !ChildNode.isEmpty(); + ChildNode = ChildNode.next()) + { + std::string Name=ChildNode.getName(); + std::string Value; + if (ChildNode.getText()) + Value=ChildNode.getText(); + + if ("ext:"==Name.substr(0,4)) + m_d->m_ExtElements[Name.substr(4)]=Value; + else + ParseElement(ChildNode); + } + } +} + +std::map MusicBrainz5::CEntity::ExtAttributes() const +{ + return m_d->m_ExtAttributes; +} + +std::map MusicBrainz5::CEntity::ExtElements() const +{ + return m_d->m_ExtElements; +} + +void MusicBrainz5::CEntity::ProcessRelationList(const XMLNode& Node, CRelationListList* & RetVal) +{ + if (0==RetVal) + RetVal=new CRelationListList; + + CRelationList *RelationList=0; + ProcessItem(Node,RelationList); + RetVal->Add(RelationList); + delete RelationList; +} + +std::ostream& MusicBrainz5::CEntity::Serialise(std::ostream& os) const +{ + if (!ExtAttributes().empty()) + { + os << "Ext attrs: " << std::endl; + std::map ExtAttrs=ExtAttributes(); + std::map::const_iterator ThisExtAttr=ExtAttrs.begin(); + while (ThisExtAttr!=ExtAttrs.end()) + { + os << (*ThisExtAttr).first << " = " << (*ThisExtAttr).second << std::endl; + + ++ThisExtAttr; + } + } + + if (!ExtElements().empty()) + { + os << "Ext elements: " << std::endl; + std::map ExtElems=ExtElements(); + std::map::const_iterator ThisExtElement=ExtElems.begin(); + while (ThisExtElement!=ExtElems.end()) + { + os << (*ThisExtElement).first << " = " << (*ThisExtElement).second << std::endl; + + ++ThisExtElement; + } + } + + return os; +} + +std::ostream& operator << (std::ostream& os, const MusicBrainz5::CEntity& Entity) +{ + return Entity.Serialise(os); +} + diff --git a/src/FreeDBDisc.cc b/src/FreeDBDisc.cc new file mode 100644 index 0000000..a888192 --- /dev/null +++ b/src/FreeDBDisc.cc @@ -0,0 +1,199 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/FreeDBDisc.h" + +#include "musicbrainz5/NonMBTrackList.h" +#include "musicbrainz5/NonMBTrack.h" + +class MusicBrainz5::CFreeDBDiscPrivate +{ + public: + CFreeDBDiscPrivate() + : m_NonMBTrackList(0) + { + } + + std::string m_ID; + std::string m_Title; + std::string m_Artist; + std::string m_Category; + std::string m_Year; + CNonMBTrackList *m_NonMBTrackList; +}; + +MusicBrainz5::CFreeDBDisc::CFreeDBDisc(const XMLNode& Node) +: CEntity(), + m_d(new CFreeDBDiscPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "FreeDBDisc node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CFreeDBDisc::CFreeDBDisc(const CFreeDBDisc& Other) +: CEntity(), + m_d(new CFreeDBDiscPrivate) +{ + *this=Other; +} + +MusicBrainz5::CFreeDBDisc& MusicBrainz5::CFreeDBDisc::operator =(const CFreeDBDisc& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Title=Other.m_d->m_Title; + m_d->m_Artist=Other.m_d->m_Artist; + m_d->m_Category=Other.m_d->m_Category; + m_d->m_Year=Other.m_d->m_Year; + + if (Other.m_d->m_NonMBTrackList) + m_d->m_NonMBTrackList=new CNonMBTrackList(*Other.m_d->m_NonMBTrackList); + } + + return *this; +} + +MusicBrainz5::CFreeDBDisc::~CFreeDBDisc() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CFreeDBDisc::Cleanup() +{ + delete m_d->m_NonMBTrackList; + m_d->m_NonMBTrackList=0; +} + +MusicBrainz5::CFreeDBDisc *MusicBrainz5::CFreeDBDisc::Clone() +{ + return new CFreeDBDisc(*this); +} + +void MusicBrainz5::CFreeDBDisc::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else + { + std::cerr << "Unrecognised freedb disc attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CFreeDBDisc::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("artist"==NodeName) + { + ProcessItem(Node,m_d->m_Artist); + } + else if ("category"==NodeName) + { + ProcessItem(Node,m_d->m_Category); + } + else if ("year"==NodeName) + { + ProcessItem(Node,m_d->m_Year); + } + else if ("nonmb-track-list"==NodeName) + { + ProcessItem(Node,m_d->m_NonMBTrackList); + } + else + { + std::cerr << "Unrecognised freedb disc element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CFreeDBDisc::GetElementName() +{ + return "freedb-disc"; +} + +std::string MusicBrainz5::CFreeDBDisc::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CFreeDBDisc::Title() const +{ + return m_d->m_Title; +} + +std::string MusicBrainz5::CFreeDBDisc::Artist() const +{ + return m_d->m_Artist; +} + +std::string MusicBrainz5::CFreeDBDisc::Category() const +{ + return m_d->m_Category; +} + +std::string MusicBrainz5::CFreeDBDisc::Year() const +{ + return m_d->m_Year; +} + +MusicBrainz5::CNonMBTrackList *MusicBrainz5::CFreeDBDisc::NonMBTrackList() const +{ + return m_d->m_NonMBTrackList; +} + +std::ostream& MusicBrainz5::CFreeDBDisc::Serialise(std::ostream& os) const +{ + os << "FreeDBDisc:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tTitle: " << Title() << std::endl; + os << "\tArtist: " << Artist() << std::endl; + os << "\tCategory: " << Category() << std::endl; + os << "\tYear: " << Year() << std::endl; + + if (NonMBTrackList()) + os << *NonMBTrackList() << std::endl; + + return os; +} diff --git a/src/HTTPFetch.cc b/src/HTTPFetch.cc new file mode 100644 index 0000000..ac3f9b4 --- /dev/null +++ b/src/HTTPFetch.cc @@ -0,0 +1,287 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/HTTPFetch.h" + +#include +#include + +#include "ne_session.h" +#include "ne_auth.h" +#include "ne_string.h" +#include "ne_request.h" + +class MusicBrainz5::CHTTPFetchPrivate +{ + public: + CHTTPFetchPrivate() + : m_Port(80), + m_Result(0), + m_Status(0), + m_ProxyPort(0) + { + } + + std::string m_UserAgent; + std::string m_Host; + int m_Port; + std::vector m_Data; + int m_Result; + int m_Status; + std::string m_ErrorMessage; + std::string m_UserName; + std::string m_Password; + std::string m_ProxyHost; + int m_ProxyPort; + std::string m_ProxyUserName; + std::string m_ProxyPassword; +}; + +MusicBrainz5::CHTTPFetch::CHTTPFetch(const std::string& UserAgent, const std::string& Host, int Port) +: m_d(new CHTTPFetchPrivate) +{ + m_d->m_UserAgent=UserAgent; + + for (std::string::size_type Pos=0;Posm_UserAgent.length();Pos++) + if (m_d->m_UserAgent[Pos]=='-') + m_d->m_UserAgent[Pos]='/'; + + m_d->m_Host=Host; + m_d->m_Port=Port; + + // Parse http_proxy environmnent variable + const char *http_proxy = getenv("http_proxy"); + if (http_proxy) + { + ne_uri uri; + if (!ne_uri_parse(http_proxy, &uri)) + { + if (uri.host) + m_d->m_ProxyHost = uri.host; + if (uri.port) + m_d->m_ProxyPort = uri.port; + + if (uri.userinfo) + { + char *pos = strchr(uri.userinfo, ':'); + if (pos) + { + *pos = '\0'; + m_d->m_ProxyUserName = uri.userinfo; + m_d->m_ProxyPassword = pos + 1; + } + else + { + m_d->m_ProxyUserName = uri.userinfo; + } + } + } + + ne_uri_free(&uri); + } +} + +MusicBrainz5::CHTTPFetch::~CHTTPFetch() +{ + delete m_d; +} + +void MusicBrainz5::CHTTPFetch::SetUserName(const std::string& UserName) +{ + m_d->m_UserName=UserName; +} + +void MusicBrainz5::CHTTPFetch::SetPassword(const std::string& Password) +{ + m_d->m_Password=Password; +} + +void MusicBrainz5::CHTTPFetch::SetProxyHost(const std::string& ProxyHost) +{ + m_d->m_ProxyHost=ProxyHost; +} + +void MusicBrainz5::CHTTPFetch::SetProxyPort(int ProxyPort) +{ + m_d->m_ProxyPort=ProxyPort; +} + +void MusicBrainz5::CHTTPFetch::SetProxyUserName(const std::string& ProxyUserName) +{ + m_d->m_ProxyUserName=ProxyUserName; +} + +void MusicBrainz5::CHTTPFetch::SetProxyPassword(const std::string& ProxyPassword) +{ + m_d->m_ProxyPassword=ProxyPassword; +} + +int MusicBrainz5::CHTTPFetch::Fetch(const std::string& URL, const std::string& Request) +{ + int Ret=0; + + m_d->m_Data.clear(); + + ne_sock_init(); + + ne_session *sess=ne_session_create("http", m_d->m_Host.c_str(), m_d->m_Port); + if (sess) + { + ne_set_useragent(sess, m_d->m_UserAgent.c_str()); + + ne_set_server_auth(sess, httpAuth, this); + + // Use proxy server + if (!m_d->m_ProxyHost.empty()) + { + ne_session_proxy(sess, m_d->m_ProxyHost.c_str(), m_d->m_ProxyPort); + ne_set_proxy_auth(sess, proxyAuth, this); + } + + ne_request *req = ne_request_create(sess, Request.c_str(), URL.c_str()); + if (Request=="PUT") + ne_set_request_body_buffer(req,0,0); + + if (Request!="GET") + ne_set_request_flag(req, NE_REQFLAG_IDEMPOTENT, 0); + + ne_add_response_body_reader(req, ne_accept_2xx, httpResponseReader, &m_d->m_Data); + + m_d->m_Result = ne_request_dispatch(req); + m_d->m_Status = ne_get_status(req)->code; + + Ret=m_d->m_Data.size(); + + ne_request_destroy(req); + + m_d->m_ErrorMessage = ne_get_error(sess); + + ne_session_destroy(sess); + + switch (m_d->m_Result) + { + case NE_OK: + break; + + case NE_CONNECT: + case NE_LOOKUP: + throw CConnectionError(m_d->m_ErrorMessage); + break; + + case NE_TIMEOUT: + throw CTimeoutError(m_d->m_ErrorMessage); + break; + + case NE_AUTH: + case NE_PROXYAUTH: + throw CAuthenticationError(m_d->m_ErrorMessage); + break; + + default: + throw CFetchError(m_d->m_ErrorMessage); + break; + } + + switch (m_d->m_Status) + { + case 200: + break; + + case 400: + throw CRequestError(m_d->m_ErrorMessage); + break; + + case 401: + throw CAuthenticationError(m_d->m_ErrorMessage); + break; + + case 404: + throw CResourceNotFoundError(m_d->m_ErrorMessage); + break; + + default: + throw CFetchError(m_d->m_ErrorMessage); + break; + } + } + + ne_sock_exit(); + + return Ret; +} + +int MusicBrainz5::CHTTPFetch::httpAuth(void *userdata, const char *realm, int attempts, + char *username, char *password) +{ + realm=realm; + + MusicBrainz5::CHTTPFetch *Fetch = (MusicBrainz5::CHTTPFetch *)userdata; + strncpy(username, Fetch->m_d->m_UserName.c_str(), NE_ABUFSIZ); + strncpy(password, Fetch->m_d->m_Password.c_str(), NE_ABUFSIZ); + return attempts; +} + +int MusicBrainz5::CHTTPFetch::proxyAuth(void *userdata, const char *realm, int attempts, + char *username, char *password) +{ + realm=realm; + + MusicBrainz5::CHTTPFetch *Fetch = (MusicBrainz5::CHTTPFetch *)userdata; + strncpy(username, Fetch->m_d->m_ProxyUserName.c_str(), NE_ABUFSIZ); + strncpy(password, Fetch->m_d->m_ProxyPassword.c_str(), NE_ABUFSIZ); + return attempts; +} + +int MusicBrainz5::CHTTPFetch::httpResponseReader(void *userdata, const char *buf, size_t len) +{ + std::vector *buffer = reinterpret_cast *>(userdata); + + buffer->insert(buffer->end(),buf,buf+len); + + return 0; +} + +std::vector MusicBrainz5::CHTTPFetch::Data() const +{ + return m_d->m_Data; +} + +int MusicBrainz5::CHTTPFetch::Result() const +{ + return m_d->m_Result; +} + +int MusicBrainz5::CHTTPFetch::Status() const +{ + return m_d->m_Status; +} + +std::string MusicBrainz5::CHTTPFetch::ErrorMessage() const +{ + return m_d->m_ErrorMessage; +} diff --git a/src/IPI.cc b/src/IPI.cc new file mode 100644 index 0000000..8c5e9ad --- /dev/null +++ b/src/IPI.cc @@ -0,0 +1,119 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/IPI.h" + +class MusicBrainz5::CIPIPrivate +{ + public: + CIPIPrivate() + { + } + + std::string m_IPI; +}; + +MusicBrainz5::CIPI::CIPI(const XMLNode& Node) +: CEntity(), + m_d(new CIPIPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "IPI node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + if (Node.getText()) + { + ProcessItem(Node,m_d->m_IPI); + } + } +} + +MusicBrainz5::CIPI::CIPI(const CIPI& Other) +: CEntity(), + m_d(new CIPIPrivate) +{ + *this=Other; +} + +MusicBrainz5::CIPI& MusicBrainz5::CIPI::operator =(const CIPI& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_IPI=Other.m_d->m_IPI; + } + + return *this; +} + +MusicBrainz5::CIPI::~CIPI() +{ + delete m_d; +} + +MusicBrainz5::CIPI *MusicBrainz5::CIPI::Clone() +{ + return new CIPI(*this); +} + +void MusicBrainz5::CIPI::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised IPI attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CIPI::ParseElement(const XMLNode& Node) +{ + std::string Name=Node.getName(); + + std::cerr << "Unrecognised IPI element: '" << Name << "'" << std::endl; +} + +std::string MusicBrainz5::CIPI::GetElementName() +{ + return "ipi"; +} + +std::string MusicBrainz5::CIPI::IPI() const +{ + return m_d->m_IPI; +} + +std::ostream& MusicBrainz5::CIPI::Serialise(std::ostream& os) const +{ + os << "IPI:" << std::endl; + + CEntity::Serialise(os); + + os << "\tIPI: " << IPI() << std::endl; + + return os; +} + diff --git a/src/ISRC.cc b/src/ISRC.cc new file mode 100644 index 0000000..bd63a76 --- /dev/null +++ b/src/ISRC.cc @@ -0,0 +1,152 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/ISRC.h" + +#include "musicbrainz5/RecordingList.h" +#include "musicbrainz5/Recording.h" + +class MusicBrainz5::CISRCPrivate +{ + public: + CISRCPrivate() + : m_RecordingList(0) + { + } + + std::string m_ID; + CRecordingList *m_RecordingList; +}; + +MusicBrainz5::CISRC::CISRC(const XMLNode& Node) +: CEntity(), + m_d(new CISRCPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "ISRC node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CISRC::CISRC(const CISRC& Other) +: CEntity(), + m_d(new CISRCPrivate) +{ + *this=Other; +} + +MusicBrainz5::CISRC& MusicBrainz5::CISRC::operator =(const CISRC& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + + if (Other.m_d->m_RecordingList) + m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); + } + + return *this; +} + +MusicBrainz5::CISRC::~CISRC() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CISRC::Cleanup() +{ + delete m_d->m_RecordingList; + m_d->m_RecordingList=0; +} + +MusicBrainz5::CISRC *MusicBrainz5::CISRC::Clone() +{ + return new CISRC(*this); +} + +void MusicBrainz5::CISRC::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else + { + std::cerr << "Unrecognised isrc attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CISRC::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("recording-list"==NodeName) + { + ProcessItem(Node,m_d->m_RecordingList); + } + else + { + std::cerr << "Unrecognised ISRC element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CISRC::GetElementName() +{ + return "isrc"; +} + +std::string MusicBrainz5::CISRC::ID() const +{ + return m_d->m_ID; +} + +MusicBrainz5::CRecordingList *MusicBrainz5::CISRC::RecordingList() const +{ + return m_d->m_RecordingList; +} + +std::ostream& MusicBrainz5::CISRC::Serialise(std::ostream& os) const +{ + os << "ISRC:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + + if (RecordingList()) + os << *RecordingList() << std::endl; + + return os; +} + diff --git a/src/ISWC.cc b/src/ISWC.cc new file mode 100644 index 0000000..d8d75a4 --- /dev/null +++ b/src/ISWC.cc @@ -0,0 +1,124 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" + +#include "musicbrainz5/ISWC.h" + + +class MusicBrainz5::CISWCPrivate +{ + public: + CISWCPrivate() + { + } + + std::string m_ISWC; +}; + +MusicBrainz5::CISWC::CISWC(const XMLNode& Node) +: CEntity(), + m_d(new CISWCPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "ISWC node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + if (Node.getText()) + ProcessItem(Node,m_d->m_ISWC); + } +} + +MusicBrainz5::CISWC::CISWC(const CISWC& Other) +: CEntity(), + m_d(new CISWCPrivate) +{ + *this=Other; +} + +MusicBrainz5::CISWC& MusicBrainz5::CISWC::operator =(const CISWC& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ISWC=Other.m_d->m_ISWC; + } + + return *this; +} + +MusicBrainz5::CISWC::~CISWC() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CISWC::Cleanup() +{ +} + +MusicBrainz5::CISWC *MusicBrainz5::CISWC::Clone() +{ + return new CISWC(*this); +} + +void MusicBrainz5::CISWC::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised ISWC attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CISWC::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + std::cerr << "Unrecognised ISWC element: '" << NodeName << "'" << std::endl; +} + +std::string MusicBrainz5::CISWC::GetElementName() +{ + return "iswc"; +} + +std::string MusicBrainz5::CISWC::ISWC() const +{ + return m_d->m_ISWC; +} + +std::ostream& MusicBrainz5::CISWC::Serialise(std::ostream& os) const +{ + os << "ISWC:" << std::endl; + + CEntity::Serialise(os); + + os << "\tISWC: " << ISWC() << std::endl; + + return os; +} diff --git a/src/ISWCList.cc b/src/ISWCList.cc new file mode 100644 index 0000000..b78dece --- /dev/null +++ b/src/ISWCList.cc @@ -0,0 +1,102 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/ISWCList.h" + +#include "musicbrainz5/ISWC.h" + +class MusicBrainz5::CISWCListPrivate +{ + public: + CISWCListPrivate() + { + } +}; + +MusicBrainz5::CISWCList::CISWCList(const XMLNode& Node) +: CListImpl(), + m_d(new CISWCListPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "ISWCList node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CISWCList::CISWCList(const CISWCList& Other) +: CListImpl(), + m_d(new CISWCListPrivate) +{ + *this=Other; +} + +MusicBrainz5::CISWCList& MusicBrainz5::CISWCList::operator =(const CISWCList& Other) +{ + if (this!=&Other) + { + CListImpl::operator =(Other); + } + + return *this; +} + +MusicBrainz5::CISWCList::~CISWCList() +{ + delete m_d; +} + +MusicBrainz5::CISWCList *MusicBrainz5::CISWCList::Clone() +{ + return new CISWCList(*this); +} + +void MusicBrainz5::CISWCList::ParseAttribute(const std::string& Name, const std::string& Value) +{ + CListImpl::ParseAttribute(Name,Value); +} + +void MusicBrainz5::CISWCList::ParseElement(const XMLNode& Node) +{ + CListImpl::ParseElement(Node); +} + +std::string MusicBrainz5::CISWCList::GetElementName() +{ + return "iswc-list"; +} + +std::ostream& MusicBrainz5::CISWCList::Serialise(std::ostream& os) const +{ + os << "ISWC list:" << std::endl; + + CListImpl::Serialise(os); + + return os; +} diff --git a/src/Label.cc b/src/Label.cc new file mode 100644 index 0000000..8add21c --- /dev/null +++ b/src/Label.cc @@ -0,0 +1,403 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Label.h" + +#include + +#include "musicbrainz5/Lifespan.h" +#include "musicbrainz5/IPI.h" +#include "musicbrainz5/Rating.h" +#include "musicbrainz5/UserRating.h" +#include "musicbrainz5/Alias.h" +#include "musicbrainz5/AliasList.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Relation.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/Tag.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTag.h" +#include "musicbrainz5/UserTagList.h" + +class MusicBrainz5::CLabelPrivate +{ + public: + CLabelPrivate() + : m_LabelCode(0), + m_IPIList(0), + m_Lifespan(0), + m_AliasList(0), + m_ReleaseList(0), + m_RelationListList(0), + m_TagList(0), + m_UserTagList(0), + m_Rating(0), + m_UserRating(0) + { + } + + std::string m_ID; + std::string m_Type; + std::string m_Name; + std::string m_SortName; + int m_LabelCode; + CIPIList *m_IPIList; + std::string m_Disambiguation; + std::string m_Country; + CLifespan *m_Lifespan; + CAliasList *m_AliasList; + CReleaseList *m_ReleaseList; + CRelationListList *m_RelationListList; + CTagList *m_TagList; + CUserTagList *m_UserTagList; + CRating *m_Rating; + CUserRating *m_UserRating; +}; +MusicBrainz5::CLabel::CLabel(const XMLNode& Node) +: CEntity(), + m_d(new CLabelPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Label node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CLabel::CLabel(const CLabel& Other) +: CEntity(), + m_d(new CLabelPrivate) +{ + *this=Other; +} + +MusicBrainz5::CLabel& MusicBrainz5::CLabel::operator =(const CLabel& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Type=Other.m_d->m_Type; + m_d->m_Name=Other.m_d->m_Name; + m_d->m_SortName=Other.m_d->m_SortName; + m_d->m_LabelCode=Other.m_d->m_LabelCode; + + if (Other.m_d->m_IPIList) + m_d->m_IPIList=new CIPIList(*Other.m_d->m_IPIList); + + m_d->m_Disambiguation=Other.m_d->m_Disambiguation; + m_d->m_Country=Other.m_d->m_Country; + + if (Other.m_d->m_Lifespan) + m_d->m_Lifespan=new CLifespan(*Other.m_d->m_Lifespan); + + if (Other.m_d->m_AliasList) + m_d->m_AliasList=new CAliasList(*Other.m_d->m_AliasList); + + if (Other.m_d->m_ReleaseList) + m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); + + if (Other.m_d->m_RelationListList) + m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); + + if (Other.m_d->m_TagList) + m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); + + if (Other.m_d->m_UserTagList) + m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); + + if (Other.m_d->m_Rating) + m_d->m_Rating=new CRating(*Other.m_d->m_Rating); + + if (Other.m_d->m_UserRating) + m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); + } + + return *this; +} + +MusicBrainz5::CLabel::~CLabel() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CLabel::Cleanup() +{ + delete m_d->m_IPIList; + m_d->m_IPIList=0; + + delete m_d->m_Lifespan; + m_d->m_Lifespan=0; + + delete m_d->m_AliasList; + m_d->m_AliasList=0; + + delete m_d->m_ReleaseList; + m_d->m_ReleaseList=0; + + delete m_d->m_RelationListList; + m_d->m_RelationListList=0; + + delete m_d->m_TagList; + m_d->m_TagList=0; + + delete m_d->m_UserTagList; + m_d->m_UserTagList=0; + + delete m_d->m_Rating; + m_d->m_Rating=0; + + delete m_d->m_UserRating; + m_d->m_UserRating=0; +} + +MusicBrainz5::CLabel *MusicBrainz5::CLabel::Clone() +{ + return new CLabel(*this); +} + +void MusicBrainz5::CLabel::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else if ("type"==Name) + m_d->m_Type=Value; + else + { + std::cerr << "Unrecognised label attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CLabel::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("name"==NodeName) + { + ProcessItem(Node,m_d->m_Name); + } + else if ("sort-name"==NodeName) + { + ProcessItem(Node,m_d->m_SortName); + } + else if ("label-code"==NodeName) + { + ProcessItem(Node,m_d->m_LabelCode); + } + else if ("ipi"==NodeName) + { + //Ignore IPI + } + else if ("ipi-list"==NodeName) + { + ProcessItem(Node,m_d->m_IPIList); + } + else if ("disambiguation"==NodeName) + { + ProcessItem(Node,m_d->m_Disambiguation); + } + else if ("country"==NodeName) + { + ProcessItem(Node,m_d->m_Country); + } + else if ("life-span"==NodeName) + { + ProcessItem(Node,m_d->m_Lifespan); + } + else if ("alias-list"==NodeName) + { + ProcessItem(Node,m_d->m_AliasList); + } + else if ("release-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseList); + } + else if ("relation-list"==NodeName) + { + ProcessRelationList(Node,m_d->m_RelationListList); + } + else if ("tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_TagList); + } + else if ("user-tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_UserTagList); + } + else if ("rating"==NodeName) + { + ProcessItem(Node,m_d->m_Rating); + } + else if ("user-rating"==NodeName) + { + ProcessItem(Node,m_d->m_UserRating); + } + else + { + std::cerr << "Unrecognised label element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CLabel::GetElementName() +{ + return "label"; +} + +std::string MusicBrainz5::CLabel::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CLabel::Type() const +{ + return m_d->m_Type; +} + +std::string MusicBrainz5::CLabel::Name() const +{ + return m_d->m_Name; +} + +std::string MusicBrainz5::CLabel::SortName() const +{ + return m_d->m_SortName; +} + +int MusicBrainz5::CLabel::LabelCode() const +{ + return m_d->m_LabelCode; +} + +MusicBrainz5::CIPIList *MusicBrainz5::CLabel::IPIList() const +{ + return m_d->m_IPIList; +} + +std::string MusicBrainz5::CLabel::Disambiguation() const +{ + return m_d->m_Disambiguation; +} + +std::string MusicBrainz5::CLabel::Country() const +{ + return m_d->m_Country; +} + +MusicBrainz5::CLifespan *MusicBrainz5::CLabel::Lifespan() const +{ + return m_d->m_Lifespan; +} + +MusicBrainz5::CAliasList *MusicBrainz5::CLabel::AliasList() const +{ + return m_d->m_AliasList; +} + +MusicBrainz5::CReleaseList *MusicBrainz5::CLabel::ReleaseList() const +{ + return m_d->m_ReleaseList; +} + +MusicBrainz5::CRelationListList *MusicBrainz5::CLabel::RelationListList() const +{ + return m_d->m_RelationListList; +} + +MusicBrainz5::CTagList *MusicBrainz5::CLabel::TagList() const +{ + return m_d->m_TagList; +} + +MusicBrainz5::CUserTagList *MusicBrainz5::CLabel::UserTagList() const +{ + return m_d->m_UserTagList; +} + +MusicBrainz5::CRating *MusicBrainz5::CLabel::Rating() const +{ + return m_d->m_Rating; +} + +MusicBrainz5::CUserRating *MusicBrainz5::CLabel::UserRating() const +{ + return m_d->m_UserRating; +} + +std::ostream& MusicBrainz5::CLabel::Serialise(std::ostream& os) const +{ + os << "Label:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tType: " << Type() << std::endl; + os << "\tName: " << Name() << std::endl; + os << "\tSort name: " << SortName() << std::endl; + os << "\tLabel code: " << LabelCode() << std::endl; + + if (IPIList()) + os << *IPIList() << std::endl; + + os << "\tDisambiguation: " << Disambiguation() << std::endl; + os << "\tCountry: " << Country() << std::endl; + + if (Lifespan()) + os << *Lifespan() << std::endl; + + if (AliasList()) + os << *AliasList() << std::endl; + + if (ReleaseList()) + os << *ReleaseList() << std::endl; + + if (RelationListList()) + os << *RelationListList() << std::endl; + + if (TagList()) + os << *TagList() << std::endl; + + if (UserTagList()) + os << *UserTagList() << std::endl; + + if (Rating()) + os << *Rating() << std::endl; + + if (UserRating()) + os << *UserRating() << std::endl; + + return os; +} + diff --git a/src/LabelInfo.cc b/src/LabelInfo.cc new file mode 100644 index 0000000..ad04652 --- /dev/null +++ b/src/LabelInfo.cc @@ -0,0 +1,150 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/LabelInfo.h" + +#include "musicbrainz5/Label.h" + +class MusicBrainz5::CLabelInfoPrivate +{ + public: + CLabelInfoPrivate() + : m_Label(0) + { + } + + std::string m_CatalogNumber; + CLabel *m_Label; +}; + +MusicBrainz5::CLabelInfo::CLabelInfo(const XMLNode& Node) +: CEntity(), + m_d(new CLabelInfoPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Label info node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CLabelInfo::CLabelInfo(const CLabelInfo& Other) +: CEntity(), + m_d(new CLabelInfoPrivate) +{ + *this=Other; +} + +MusicBrainz5::CLabelInfo& MusicBrainz5::CLabelInfo::operator =(const CLabelInfo& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_CatalogNumber=Other.m_d->m_CatalogNumber; + + if (Other.m_d->m_Label) + m_d->m_Label=new CLabel(*Other.m_d->m_Label); + } + + return *this; +} + +MusicBrainz5::CLabelInfo::~CLabelInfo() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CLabelInfo::Cleanup() +{ + delete m_d->m_Label; + m_d->m_Label=0; +} + +MusicBrainz5::CLabelInfo *MusicBrainz5::CLabelInfo::Clone() +{ + return new CLabelInfo(*this); +} + +void MusicBrainz5::CLabelInfo::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised labelinfo attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CLabelInfo::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("catalog-number"==NodeName) + { + ProcessItem(Node,m_d->m_CatalogNumber); + } + else if ("label"==NodeName) + { + ProcessItem(Node,m_d->m_Label); + } + else + { + std::cerr << "Unrecognised label info element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CLabelInfo::GetElementName() +{ + return "label-info"; +} + +std::string MusicBrainz5::CLabelInfo::CatalogNumber() const +{ + return m_d->m_CatalogNumber; +} + +MusicBrainz5::CLabel *MusicBrainz5::CLabelInfo::Label() const +{ + return m_d->m_Label; +} + +std::ostream& MusicBrainz5::CLabelInfo::Serialise(std::ostream& os) const +{ + os << "Label info:" << std::endl; + + CEntity::Serialise(os); + + os << "\tCatalog number: " << CatalogNumber() << std::endl; + + if (Label()) + os << *Label() << std::endl; + + return os; +} + diff --git a/src/Lifespan.cc b/src/Lifespan.cc new file mode 100644 index 0000000..35b49d1 --- /dev/null +++ b/src/Lifespan.cc @@ -0,0 +1,140 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Lifespan.h" + +class MusicBrainz5::CLifespanPrivate +{ + public: + std::string m_Begin; + std::string m_End; + std::string m_Ended; +}; + +MusicBrainz5::CLifespan::CLifespan(const XMLNode& Node) +: CEntity(), + m_d(new CLifespanPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Lifespan node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CLifespan::CLifespan(const CLifespan& Other) +: CEntity(), + m_d(new CLifespanPrivate) +{ + *this=Other; +} + +MusicBrainz5::CLifespan& MusicBrainz5::CLifespan::operator =(const CLifespan& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Begin=Other.m_d->m_Begin; + m_d->m_End=Other.m_d->m_End; + m_d->m_Ended=Other.m_d->m_Ended; + } + + return *this; +} + +MusicBrainz5::CLifespan::~CLifespan() +{ + delete m_d; +} + +MusicBrainz5::CLifespan *MusicBrainz5::CLifespan::Clone() +{ + return new CLifespan(*this); +} + +void MusicBrainz5::CLifespan::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised lifespan attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CLifespan::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("begin"==NodeName) + { + ProcessItem(Node,m_d->m_Begin); + } + else if ("end"==NodeName) + { + ProcessItem(Node,m_d->m_End); + } + else if ("ended"==NodeName) + { + ProcessItem(Node,m_d->m_Ended); + } + else + { + std::cerr << "Unrecognised lifespan element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CLifespan::GetElementName() +{ + return "life-span"; +} + +std::string MusicBrainz5::CLifespan::Begin() const +{ + return m_d->m_Begin; +} + +std::string MusicBrainz5::CLifespan::End() const +{ + return m_d->m_End; +} + +std::string MusicBrainz5::CLifespan::Ended() const +{ + return m_d->m_Ended; +} + +std::ostream& MusicBrainz5::CLifespan::Serialise(std::ostream& os) const +{ + os << "Lifespan:" << std::endl; + + CEntity::Serialise(os); + + os << "\tBegin: " << Begin() << std::endl; + os << "\tEnd: " << End() << std::endl; + os << "\tEnded: " << Ended() << std::endl; + + return os; +} diff --git a/src/List.cc b/src/List.cc new file mode 100644 index 0000000..6a8a47c --- /dev/null +++ b/src/List.cc @@ -0,0 +1,166 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/List.h" + +#include + +class MusicBrainz5::CListPrivate +{ +public: + CListPrivate() + : m_Offset(0), + m_Count(0) + { + } + + int m_Offset; + int m_Count; + std::vector m_Items; +}; + +MusicBrainz5::CList::CList() +: CEntity(), + m_d(new CListPrivate) +{ +} + +MusicBrainz5::CList::CList(const CList& Other) +: CEntity(), + m_d(new CListPrivate) +{ + *this=Other; +} + +MusicBrainz5::CList& MusicBrainz5::CList::operator =(const CList& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_Offset=Other.m_d->m_Offset; + m_d->m_Count=Other.m_d->m_Count; + + std::vector::const_iterator ThisItem=Other.m_d->m_Items.begin(); + while (ThisItem!=Other.m_d->m_Items.end()) + { + CEntity *Item=(*ThisItem); + m_d->m_Items.push_back(Item->Clone()); + ++ThisItem; + } + } + + return *this; +} + +MusicBrainz5::CList::~CList() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CList::Cleanup() +{ + while (!m_d->m_Items.empty()) + { + delete m_d->m_Items.back(); + m_d->m_Items.pop_back(); + } +} + +MusicBrainz5::CList *MusicBrainz5::CList::Clone() +{ + return new CList(*this); +} + +void MusicBrainz5::CList::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("offset"==Name) + ProcessItem(Value,m_d->m_Offset); + else if ("count"==Name) + ProcessItem(Value,m_d->m_Count); + else + { + std::cerr << "Unrecognised list attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CList::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + std::cerr << "Unrecognised list element: '" << NodeName << "'" << std::endl; +} + +std::string MusicBrainz5::CList::GetElementName() +{ + return ""; +} + +void MusicBrainz5::CList::AddItem(CEntity *Item) +{ + m_d->m_Items.push_back(Item); +} + +int MusicBrainz5::CList::NumItems() const +{ + return m_d->m_Items.size(); +} + +MusicBrainz5::CEntity *MusicBrainz5::CList::Item(int Item) const +{ + CEntity *Ret=0; + + if (Itemm_Items[Item]; + + return Ret; +} + +int MusicBrainz5::CList::Offset() const +{ + return m_d->m_Offset; +} + +int MusicBrainz5::CList::Count() const +{ + return m_d->m_Count; +} + +std::ostream& MusicBrainz5::CList::Serialise(std::ostream& os) const +{ + os << "List: " << std::endl; + os << "Offset: " << Offset() << std::endl; + os << "Count: " << Count() << std::endl; + + return os; +} + diff --git a/src/Medium.cc b/src/Medium.cc new file mode 100644 index 0000000..03e27da --- /dev/null +++ b/src/Medium.cc @@ -0,0 +1,215 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Medium.h" + +#include "musicbrainz5/Disc.h" +#include "musicbrainz5/DiscList.h" +#include "musicbrainz5/Track.h" +#include "musicbrainz5/TrackList.h" + +class MusicBrainz5::CMediumPrivate +{ + public: + CMediumPrivate() + : m_Position(0), + m_DiscList(0), + m_TrackList(0) + { + } + + std::string m_Title; + int m_Position; + std::string m_Format; + CDiscList *m_DiscList; + CTrackList *m_TrackList; +}; + +MusicBrainz5::CMedium::CMedium(const XMLNode& Node) +: CEntity(), + m_d(new CMediumPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Medium node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CMedium::CMedium(const CMedium& Other) +: CEntity(), + m_d(new CMediumPrivate) +{ + *this=Other; +} + +MusicBrainz5::CMedium& MusicBrainz5::CMedium::operator =(const CMedium& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_Title=Other.m_d->m_Title; + m_d->m_Position=Other.m_d->m_Position; + m_d->m_Format=Other.m_d->m_Format; + + if (Other.m_d->m_DiscList) + m_d->m_DiscList=new CDiscList(*Other.m_d->m_DiscList); + + if (Other.m_d->m_TrackList) + m_d->m_TrackList=new CTrackList(*Other.m_d->m_TrackList); + } + + return *this; +} + +MusicBrainz5::CMedium::~CMedium() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CMedium::Cleanup() +{ + delete m_d->m_DiscList; + m_d->m_DiscList=0; + + delete m_d->m_TrackList; + m_d->m_TrackList=0; +} + +MusicBrainz5::CMedium *MusicBrainz5::CMedium::Clone() +{ + return new CMedium(*this); +} + +void MusicBrainz5::CMedium::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised medium attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CMedium::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("position"==NodeName) + { + ProcessItem(Node,m_d->m_Position); + } + else if ("format"==NodeName) + { + ProcessItem(Node,m_d->m_Format); + } + else if ("disc-list"==NodeName) + { + ProcessItem(Node,m_d->m_DiscList); + } + else if ("track-list"==NodeName) + { + ProcessItem(Node,m_d->m_TrackList); + } + else + { + std::cerr << "Unrecognised medium element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CMedium::GetElementName() +{ + return "medium"; +} + +std::string MusicBrainz5::CMedium::Title() const +{ + return m_d->m_Title; +} + +int MusicBrainz5::CMedium::Position() const +{ + return m_d->m_Position; +} + +std::string MusicBrainz5::CMedium::Format() const +{ + return m_d->m_Format; +} + +MusicBrainz5::CDiscList *MusicBrainz5::CMedium::DiscList() const +{ + return m_d->m_DiscList; +} + +MusicBrainz5::CTrackList *MusicBrainz5::CMedium::TrackList() const +{ + return m_d->m_TrackList; +} + +bool MusicBrainz5::CMedium::ContainsDiscID(const std::string& DiscID) const +{ + bool RetVal=false; + + if (m_d->m_DiscList) + { + for (int count=0;!RetVal && countm_DiscList->NumItems();count++) + { + CDisc *Disc=m_d->m_DiscList->Item(count); + + if (Disc->ID()==DiscID) + RetVal=true; + } + } + + return RetVal; +} + +std::ostream& MusicBrainz5::CMedium::Serialise(std::ostream& os) const +{ + os << "Medium:" << std::endl; + + CEntity::Serialise(os); + + os << "\tTitle: " << Title() << std::endl; + os << "\tPosition: " << Position() << std::endl; + os << "\tFormat: " << Format() << std::endl; + + if (DiscList()) + os << *DiscList() << std::endl; + + if (TrackList()) + os << *TrackList() << std::endl; + + return os; +} diff --git a/src/MediumList.cc b/src/MediumList.cc new file mode 100644 index 0000000..e3d5705 --- /dev/null +++ b/src/MediumList.cc @@ -0,0 +1,123 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/MediumList.h" + +#include "musicbrainz5/Medium.h" + +class MusicBrainz5::CMediumListPrivate +{ + public: + CMediumListPrivate() + : m_TrackCount(0) + { + } + + int m_TrackCount; +}; + +MusicBrainz5::CMediumList::CMediumList(const XMLNode& Node) +: CListImpl(), + m_d(new CMediumListPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "MediumList node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CMediumList::CMediumList(const CMediumList& Other) +: CListImpl(), + m_d(new CMediumListPrivate) +{ + *this=Other; +} + +MusicBrainz5::CMediumList& MusicBrainz5::CMediumList::operator =(const CMediumList& Other) +{ + if (this!=&Other) + { + CListImpl::operator =(Other); + + m_d->m_TrackCount=Other.m_d->m_TrackCount; + } + + return *this; +} + +MusicBrainz5::CMediumList::~CMediumList() +{ + delete m_d; +} + +MusicBrainz5::CMediumList *MusicBrainz5::CMediumList::Clone() +{ + return new CMediumList(*this); +} + +void MusicBrainz5::CMediumList::ParseAttribute(const std::string& Name, const std::string& Value) +{ + CListImpl::ParseAttribute(Name,Value); +} + +void MusicBrainz5::CMediumList::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("track-count"==NodeName) + { + ProcessItem(Node,m_d->m_TrackCount); + } + else + { + CListImpl::ParseElement(Node); + } +} + +std::string MusicBrainz5::CMediumList::GetElementName() +{ + return "medium-list"; +} + +int MusicBrainz5::CMediumList::TrackCount() const +{ + return m_d->m_TrackCount; +} + +std::ostream& MusicBrainz5::CMediumList::Serialise(std::ostream& os) const +{ + os << "Medium list:" << std::endl; + + os << "\tTrack count: " << TrackCount() << std::endl; + + CListImpl::Serialise(os); + + return os; +} diff --git a/src/Message.cc b/src/Message.cc new file mode 100644 index 0000000..63e034b --- /dev/null +++ b/src/Message.cc @@ -0,0 +1,114 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Message.h" + +class MusicBrainz5::CMessagePrivate +{ +public: + std::string m_Text; +}; + +MusicBrainz5::CMessage::CMessage(const XMLNode& Node) +: CEntity(), + m_d(new CMessagePrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Message node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CMessage::CMessage(const CMessage& Other) +: CEntity(), + m_d(new CMessagePrivate) +{ + *this=Other; +} + +MusicBrainz5::CMessage& MusicBrainz5::CMessage::operator =(const CMessage& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Text=Other.m_d->m_Text; + } + + return *this; +} + +MusicBrainz5::CMessage::~CMessage() +{ + delete m_d; +} + +MusicBrainz5::CMessage *MusicBrainz5::CMessage::Clone() +{ + return new CMessage(*this); +} + +void MusicBrainz5::CMessage::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised message attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CMessage::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if (NodeName=="text") + ProcessItem(Node,m_d->m_Text); + else + { + std::cerr << "Unrecognised message element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CMessage::GetElementName() +{ + return "message"; +} + +std::string MusicBrainz5::CMessage::Text() const +{ + return m_d->m_Text; +} + +std::ostream& MusicBrainz5::CMessage::Serialise(std::ostream& os) const +{ + os << "Message:" << std::endl; + + CEntity::Serialise(os); + + os << "\tText: " << Text() << std::endl; + + return os; +} diff --git a/src/Metadata.cc b/src/Metadata.cc new file mode 100644 index 0000000..57b4732 --- /dev/null +++ b/src/Metadata.cc @@ -0,0 +1,746 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Metadata.h" + +#include "musicbrainz5/Artist.h" +#include "musicbrainz5/ArtistList.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/ReleaseGroup.h" +#include "musicbrainz5/ReleaseGroupList.h" +#include "musicbrainz5/Recording.h" +#include "musicbrainz5/RecordingList.h" +#include "musicbrainz5/Label.h" +#include "musicbrainz5/LabelList.h" +#include "musicbrainz5/Work.h" +#include "musicbrainz5/WorkList.h" +#include "musicbrainz5/PUID.h" +#include "musicbrainz5/ISRC.h" +#include "musicbrainz5/ISRCList.h" +#include "musicbrainz5/Disc.h" +#include "musicbrainz5/Rating.h" +#include "musicbrainz5/UserRating.h" +#include "musicbrainz5/Collection.h" +#include "musicbrainz5/CollectionList.h" +#include "musicbrainz5/Annotation.h" +#include "musicbrainz5/AnnotationList.h" +#include "musicbrainz5/CDStub.h" +#include "musicbrainz5/CDStubList.h" +#include "musicbrainz5/FreeDBDisc.h" +#include "musicbrainz5/FreeDBDiscList.h" +#include "musicbrainz5/Tag.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/UserTag.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/LabelInfo.h" +#include "musicbrainz5/LabelInfoList.h" +#include "musicbrainz5/Message.h" + +class MusicBrainz5::CMetadataPrivate +{ + public: + CMetadataPrivate() + : m_Artist(0), + m_Release(0), + m_ReleaseGroup(0), + m_Recording(0), + m_Label(0), + m_Work(0), + m_PUID(0), + m_ISRC(0), + m_Disc(0), + m_LabelInfoList(0), + m_Rating(0), + m_UserRating(0), + m_Collection(0), + m_ArtistList(0), + m_ReleaseList(0), + m_ReleaseGroupList(0), + m_RecordingList(0), + m_LabelList(0), + m_WorkList(0), + m_ISRCList(0), + m_AnnotationList(0), + m_CDStubList(0), + m_FreeDBDiscList(0), + m_TagList(0), + m_UserTagList(0), + m_CollectionList(0), + m_CDStub(0), + m_Message(0) + { + } + + std::string m_XMLNS; + std::string m_XMLNSExt; + std::string m_Generator; + std::string m_Created; + CArtist *m_Artist; + CRelease *m_Release; + CReleaseGroup *m_ReleaseGroup; + CRecording *m_Recording; + CLabel *m_Label; + CWork *m_Work; + CPUID *m_PUID; + CISRC *m_ISRC; + CDisc *m_Disc; + CLabelInfoList *m_LabelInfoList; + CRating *m_Rating; + CUserRating *m_UserRating; + CCollection *m_Collection; + CArtistList *m_ArtistList; + CReleaseList *m_ReleaseList; + CReleaseGroupList *m_ReleaseGroupList; + CRecordingList *m_RecordingList; + CLabelList *m_LabelList; + CWorkList *m_WorkList; + CISRCList *m_ISRCList; + CAnnotationList *m_AnnotationList; + CCDStubList *m_CDStubList; + CFreeDBDiscList *m_FreeDBDiscList; + CTagList *m_TagList; + CUserTagList *m_UserTagList; + CCollectionList *m_CollectionList; + CCDStub *m_CDStub; + CMessage *m_Message; +}; + +MusicBrainz5::CMetadata::CMetadata(const XMLNode& Node) +: CEntity(), + m_d(new CMetadataPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Metadata node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CMetadata::CMetadata(const CMetadata& Other) +: CEntity(), + m_d(new CMetadataPrivate) +{ + *this=Other; +} + +MusicBrainz5::CMetadata& MusicBrainz5::CMetadata::operator =(const CMetadata& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_XMLNS=Other.m_d->m_XMLNS; + m_d->m_XMLNSExt=Other.m_d->m_XMLNSExt; + m_d->m_Generator=Other.m_d->m_Generator; + m_d->m_Created=Other.m_d->m_Created; + + if (Other.m_d->m_Artist) + m_d->m_Artist=new CArtist(*Other.m_d->m_Artist); + + if (Other.m_d->m_Release) + m_d->m_Release=new CRelease(*Other.m_d->m_Release); + + if (Other.m_d->m_ReleaseGroup) + m_d->m_ReleaseGroup=new CReleaseGroup(*Other.m_d->m_ReleaseGroup); + + if (Other.m_d->m_Recording) + m_d->m_Recording=new CRecording(*Other.m_d->m_Recording); + + if (Other.m_d->m_Label) + m_d->m_Label=new CLabel(*Other.m_d->m_Label); + + if (Other.m_d->m_Work) + m_d->m_Work=new CWork(*Other.m_d->m_Work); + + if (Other.m_d->m_PUID) + m_d->m_PUID=new CPUID(*Other.m_d->m_PUID); + + if (Other.m_d->m_ISRC) + m_d->m_ISRC=new CISRC(*Other.m_d->m_ISRC); + + if (Other.m_d->m_Disc) + m_d->m_Disc=new CDisc(*Other.m_d->m_Disc); + + if (Other.m_d->m_LabelInfoList) + m_d->m_LabelInfoList=new CLabelInfoList(*Other.m_d->m_LabelInfoList); + + if (Other.m_d->m_Rating) + m_d->m_Rating=new CRating(*Other.m_d->m_Rating); + + if (Other.m_d->m_UserRating) + m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); + + if (Other.m_d->m_Collection) + m_d->m_Collection=new CCollection(*Other.m_d->m_Collection); + + if (Other.m_d->m_ArtistList) + m_d->m_ArtistList=new CArtistList(*Other.m_d->m_ArtistList); + + if (Other.m_d->m_ReleaseList) + m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); + + if (Other.m_d->m_ReleaseGroupList) + m_d->m_ReleaseGroupList=new CReleaseGroupList(*Other.m_d->m_ReleaseGroupList); + + if (Other.m_d->m_RecordingList) + m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); + + if (Other.m_d->m_LabelList) + m_d->m_LabelList=new CLabelList(*Other.m_d->m_LabelList); + + if (Other.m_d->m_WorkList) + m_d->m_WorkList=new CWorkList(*Other.m_d->m_WorkList); + + if (Other.m_d->m_ISRCList) + m_d->m_ISRCList=new CISRCList(*Other.m_d->m_ISRCList); + + if (Other.m_d->m_AnnotationList) + m_d->m_AnnotationList=new CAnnotationList(*Other.m_d->m_AnnotationList); + + if (Other.m_d->m_CDStubList) + m_d->m_CDStubList=new CCDStubList(*Other.m_d->m_CDStubList); + + if (Other.m_d->m_FreeDBDiscList) + m_d->m_FreeDBDiscList=new CFreeDBDiscList(*Other.m_d->m_FreeDBDiscList); + + if (Other.m_d->m_TagList) + m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); + + if (Other.m_d->m_UserTagList) + m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); + + if (Other.m_d->m_CollectionList) + m_d->m_CollectionList=new CCollectionList(*Other.m_d->m_CollectionList); + + if (Other.m_d->m_CDStub) + m_d->m_CDStub=new CCDStub(*Other.m_d->m_CDStub); + + if (Other.m_d->m_Message) + m_d->m_Message=new CMessage(*Other.m_d->m_Message); + } + + return *this; +} + +MusicBrainz5::CMetadata::~CMetadata() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CMetadata::Cleanup() +{ + delete m_d->m_Artist; + m_d->m_Artist=0; + + delete m_d->m_Release; + m_d->m_Release=0; + + delete m_d->m_ReleaseGroup; + m_d->m_ReleaseGroup=0; + + delete m_d->m_Recording; + m_d->m_Recording=0; + + delete m_d->m_Label; + m_d->m_Label=0; + + delete m_d->m_Work; + m_d->m_Work=0; + + delete m_d->m_PUID; + m_d->m_PUID=0; + + delete m_d->m_ISRC; + m_d->m_ISRC=0; + + delete m_d->m_Disc; + m_d->m_Disc=0; + + delete m_d->m_LabelInfoList; + m_d->m_LabelInfoList=0; + + delete m_d->m_Rating; + m_d->m_Rating=0; + + delete m_d->m_UserRating; + m_d->m_UserRating=0; + + delete m_d->m_Collection; + m_d->m_Collection=0; + + delete m_d->m_ArtistList; + m_d->m_ArtistList=0; + + delete m_d->m_ReleaseList; + m_d->m_ReleaseList=0; + + delete m_d->m_ReleaseGroupList; + m_d->m_ReleaseGroupList=0; + + delete m_d->m_RecordingList; + m_d->m_RecordingList=0; + + delete m_d->m_LabelList; + m_d->m_LabelList=0; + + delete m_d->m_WorkList; + m_d->m_WorkList=0; + + delete m_d->m_ISRCList; + m_d->m_ISRCList=0; + + delete m_d->m_AnnotationList; + m_d->m_AnnotationList=0; + + delete m_d->m_CDStubList; + m_d->m_CDStubList=0; + + delete m_d->m_FreeDBDiscList; + m_d->m_FreeDBDiscList=0; + + delete m_d->m_TagList; + m_d->m_TagList=0; + + delete m_d->m_UserTagList; + m_d->m_UserTagList=0; + + delete m_d->m_CollectionList; + m_d->m_CollectionList=0; + + delete m_d->m_CDStub; + m_d->m_CDStub=0; + + delete m_d->m_Message; + m_d->m_Message=0; +} + +MusicBrainz5::CMetadata *MusicBrainz5::CMetadata::Clone() +{ + return new CMetadata(*this); +} + +void MusicBrainz5::CMetadata::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("xmlns"==Name) + m_d->m_XMLNS=Value; + else if ("xmlns:ext"==Name) + m_d->m_XMLNSExt=Value; + else if ("generator"==Name) + m_d->m_Generator=Value; + else if ("created"==Name) + m_d->m_Created=Value; + else + { + std::cerr << "Unrecognised metadata attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CMetadata::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("artist"==NodeName) + { + ProcessItem(Node,m_d->m_Artist); + } + else if ("release"==NodeName) + { + ProcessItem(Node,m_d->m_Release); + } + else if ("release-group"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseGroup); + } + else if ("recording"==NodeName) + { + ProcessItem(Node,m_d->m_Recording); + } + else if ("label"==NodeName) + { + ProcessItem(Node,m_d->m_Label); + } + else if ("work"==NodeName) + { + ProcessItem(Node,m_d->m_Work); + } + else if ("puid"==NodeName) + { + ProcessItem(Node,m_d->m_PUID); + } + else if ("isrc"==NodeName) + { + ProcessItem(Node,m_d->m_ISRC); + } + else if ("disc"==NodeName) + { + ProcessItem(Node,m_d->m_Disc); + } + else if ("rating"==NodeName) + { + ProcessItem(Node,m_d->m_Rating); + } + else if ("user-rating"==NodeName) + { + ProcessItem(Node,m_d->m_UserRating); + } + else if ("collection"==NodeName) + { + ProcessItem(Node,m_d->m_Collection); + } + else if ("artist-list"==NodeName) + { + ProcessItem(Node,m_d->m_ArtistList); + } + else if ("release-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseList); + } + else if ("release-group-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseGroupList); + } + else if ("recording-list"==NodeName) + { + ProcessItem(Node,m_d->m_RecordingList); + } + else if ("label-list"==NodeName) + { + ProcessItem(Node,m_d->m_LabelList); + } + else if ("work-list"==NodeName) + { + ProcessItem(Node,m_d->m_WorkList); + } + else if ("isrc-list"==NodeName) + { + ProcessItem(Node,m_d->m_ISRCList); + } + else if ("annotation-list"==NodeName) + { + ProcessItem(Node,m_d->m_AnnotationList); + } + else if ("cdstub-list"==NodeName) + { + ProcessItem(Node,m_d->m_CDStubList); + } + else if ("freedb-disc-list"==NodeName) + { + ProcessItem(Node,m_d->m_FreeDBDiscList); + } + else if ("tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_TagList); + } + else if ("user-tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_UserTagList); + } + else if ("collection-list"==NodeName) + { + ProcessItem(Node,m_d->m_CollectionList); + } + else if ("cdstub"==NodeName) + { + ProcessItem(Node,m_d->m_CDStub); + } + else if ("message"==NodeName) + { + ProcessItem(Node,m_d->m_Message); + } + else + { + std::cerr << "Unrecognised metadata element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CMetadata::GetElementName() +{ + return "metadata"; +} + +std::string MusicBrainz5::CMetadata::XMLNS() const +{ + return m_d->m_XMLNS; +} + +std::string MusicBrainz5::CMetadata::XMLNSExt() const +{ + return m_d->m_XMLNSExt; +} + +std::string MusicBrainz5::CMetadata::Generator() const +{ + return m_d->m_Generator; +} + +std::string MusicBrainz5::CMetadata::Created() const +{ + return m_d->m_Created; +} + +MusicBrainz5::CArtist *MusicBrainz5::CMetadata::Artist() const +{ + return m_d->m_Artist; +} + +MusicBrainz5::CRelease *MusicBrainz5::CMetadata::Release() const +{ + return m_d->m_Release; +} + +MusicBrainz5::CReleaseGroup *MusicBrainz5::CMetadata::ReleaseGroup() const +{ + return m_d->m_ReleaseGroup; +} + +MusicBrainz5::CRecording *MusicBrainz5::CMetadata::Recording() const +{ + return m_d->m_Recording; +} + +MusicBrainz5::CLabel *MusicBrainz5::CMetadata::Label() const +{ + return m_d->m_Label; +} + +MusicBrainz5::CWork *MusicBrainz5::CMetadata::Work() const +{ + return m_d->m_Work; +} + +MusicBrainz5::CPUID *MusicBrainz5::CMetadata::PUID() const +{ + return m_d->m_PUID; +} + +MusicBrainz5::CISRC *MusicBrainz5::CMetadata::ISRC() const +{ + return m_d->m_ISRC; +} + +MusicBrainz5::CDisc *MusicBrainz5::CMetadata::Disc() const +{ + return m_d->m_Disc; +} + +MusicBrainz5::CLabelInfoList *MusicBrainz5::CMetadata::LabelInfoList() const +{ + return m_d->m_LabelInfoList; +} + +MusicBrainz5::CRating *MusicBrainz5::CMetadata::Rating() const +{ + return m_d->m_Rating; +} + +MusicBrainz5::CUserRating *MusicBrainz5::CMetadata::UserRating() const +{ + return m_d->m_UserRating; +} + +MusicBrainz5::CCollection *MusicBrainz5::CMetadata::Collection() const +{ + return m_d->m_Collection; +} + +MusicBrainz5::CArtistList *MusicBrainz5::CMetadata::ArtistList() const +{ + return m_d->m_ArtistList; +} + +MusicBrainz5::CReleaseList *MusicBrainz5::CMetadata::ReleaseList() const +{ + return m_d->m_ReleaseList; +} + +MusicBrainz5::CReleaseGroupList *MusicBrainz5::CMetadata::ReleaseGroupList() const +{ + return m_d->m_ReleaseGroupList; +} + +MusicBrainz5::CRecordingList *MusicBrainz5::CMetadata::RecordingList() const +{ + return m_d->m_RecordingList; +} + +MusicBrainz5::CLabelList *MusicBrainz5::CMetadata::LabelList() const +{ + return m_d->m_LabelList; +} + +MusicBrainz5::CWorkList *MusicBrainz5::CMetadata::WorkList() const +{ + return m_d->m_WorkList; +} + +MusicBrainz5::CISRCList *MusicBrainz5::CMetadata::ISRCList() const +{ + return m_d->m_ISRCList; +} + +MusicBrainz5::CAnnotationList *MusicBrainz5::CMetadata::AnnotationList() const +{ + return m_d->m_AnnotationList; +} + +MusicBrainz5::CCDStubList *MusicBrainz5::CMetadata::CDStubList() const +{ + return m_d->m_CDStubList; +} + +MusicBrainz5::CFreeDBDiscList *MusicBrainz5::CMetadata::FreeDBDiscList() const +{ + return m_d->m_FreeDBDiscList; +} + +MusicBrainz5::CTagList *MusicBrainz5::CMetadata::TagList() const +{ + return m_d->m_TagList; +} + +MusicBrainz5::CUserTagList *MusicBrainz5::CMetadata::UserTagList() const +{ + return m_d->m_UserTagList; +} + +MusicBrainz5::CCollectionList *MusicBrainz5::CMetadata::CollectionList() const +{ + return m_d->m_CollectionList; +} + +MusicBrainz5::CCDStub *MusicBrainz5::CMetadata::CDStub() const +{ + return m_d->m_CDStub; +} + +MusicBrainz5::CMessage *MusicBrainz5::CMetadata::Message() const +{ + return m_d->m_Message; +} + +std::ostream& MusicBrainz5::CMetadata::Serialise(std::ostream& os) const +{ + os << "Metadata:" << std::endl; + + CEntity::Serialise(os); + + os << "XMLNS: " << XMLNS() << std::endl; + os << "XMLNS-Ext: " << XMLNSExt() << std::endl; + os << "Generator: " << Generator() << std::endl; + os << "Created: " << Created() << std::endl; + + if (Artist()) + os << *Artist() << std::endl; + + if (Release()) + os << *Release() << std::endl; + + if (ReleaseGroup()) + os << *ReleaseGroup() << std::endl; + + if (Recording()) + os << *Recording() << std::endl; + + if (Label()) + os << *Label() << std::endl; + + if (Work()) + os << *Work() << std::endl; + + if (PUID()) + os << *PUID() << std::endl; + + if (ISRC()) + os << *ISRC() << std::endl; + + if (Disc()) + os << *Disc() << std::endl; + + if (LabelInfoList()) + os << *LabelInfoList() << std::endl; + + if (UserRating()) + os << *UserRating() << std::endl; + + if (Collection()) + os << *Collection() << std::endl; + + if (ArtistList()) + os << *ArtistList() << std::endl; + + if (ReleaseList()) + os << *ReleaseList() << std::endl; + + if (ReleaseGroupList()) + os << *ReleaseGroupList() << std::endl; + + if (RecordingList()) + os << *RecordingList() << std::endl; + + if (LabelList()) + os << *LabelList() << std::endl; + + if (WorkList()) + os << *WorkList() << std::endl; + + if (ISRCList()) + os << *ISRCList() << std::endl; + + if (AnnotationList()) + os << *AnnotationList() << std::endl; + + if (CDStubList()) + os << *CDStubList() << std::endl; + + if (FreeDBDiscList()) + os << *FreeDBDiscList() << std::endl; + + if (TagList()) + os << *TagList() << std::endl; + + if (UserTagList()) + os << *UserTagList() << std::endl; + + if (CollectionList()) + os << *CollectionList() << std::endl; + + if (CDStub()) + os << *CDStub() << std::endl; + + if (Message()) + os << *Message() << std::endl; + + return os; +} + diff --git a/src/NameCredit.cc b/src/NameCredit.cc new file mode 100644 index 0000000..f587caa --- /dev/null +++ b/src/NameCredit.cc @@ -0,0 +1,164 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/NameCredit.h" + +#include "musicbrainz5/Artist.h" + +class MusicBrainz5::CNameCreditPrivate +{ + public: + CNameCreditPrivate() + : m_Artist(0) + { + } + + std::string m_JoinPhrase; + std::string m_Name; + CArtist *m_Artist; +}; + +MusicBrainz5::CNameCredit::CNameCredit(const XMLNode& Node) +: CEntity(), + m_d(new CNameCreditPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Name credit node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CNameCredit::CNameCredit(const CNameCredit& Other) +: CEntity(), + m_d(new CNameCreditPrivate) +{ + *this=Other; +} + +MusicBrainz5::CNameCredit& MusicBrainz5::CNameCredit::operator =(const CNameCredit& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_JoinPhrase=Other.m_d->m_JoinPhrase; + m_d->m_Name=Other.m_d->m_Name; + + if (Other.m_d->m_Artist) + m_d->m_Artist=new CArtist(*Other.m_d->m_Artist); + } + + return *this; +} + +MusicBrainz5::CNameCredit::~CNameCredit() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CNameCredit::Cleanup() +{ + delete m_d->m_Artist; + m_d->m_Artist=0; +} + +MusicBrainz5::CNameCredit *MusicBrainz5::CNameCredit::Clone() +{ + return new CNameCredit(*this); +} + +void MusicBrainz5::CNameCredit::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("joinphrase"==Name) + m_d->m_JoinPhrase=Value; + else + { + std::cerr << "Unrecognised namecredit attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CNameCredit::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("name"==NodeName) + { + ProcessItem(Node,m_d->m_Name); + } + else if ("artist"==NodeName) + { + ProcessItem(Node,m_d->m_Artist); + } + else + { + std::cerr << "Unrecognised name credit element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CNameCredit::GetElementName() +{ + return "name-credit"; +} + +std::string MusicBrainz5::CNameCredit::JoinPhrase() const +{ + return m_d->m_JoinPhrase; +} + +std::string MusicBrainz5::CNameCredit::Name() const +{ + return m_d->m_Name; +} + +MusicBrainz5::CArtist *MusicBrainz5::CNameCredit::Artist() const +{ + return m_d->m_Artist; +} + +std::ostream& MusicBrainz5::CNameCredit::Serialise(std::ostream& os) const +{ + os << "Name credit:" << std::endl; + + CEntity::Serialise(os); + + os << "\tJoin phrase: " << JoinPhrase() << std::endl; + os << "\tName: " << Name() << std::endl; + + if (Artist()) + os << *Artist() << std::endl; + + return os; +} + + diff --git a/src/NonMBTrack.cc b/src/NonMBTrack.cc new file mode 100644 index 0000000..0bd6367 --- /dev/null +++ b/src/NonMBTrack.cc @@ -0,0 +1,145 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/NonMBTrack.h" + +class MusicBrainz5::CNonMBTrackPrivate +{ + public: + CNonMBTrackPrivate() + : m_Length(0) + { + } + + std::string m_Title; + std::string m_Artist; + int m_Length; +}; + +MusicBrainz5::CNonMBTrack::CNonMBTrack(const XMLNode& Node) +: CEntity(), + m_d(new CNonMBTrackPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "NonMBTrack node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CNonMBTrack::CNonMBTrack(const CNonMBTrack& Other) +: CEntity(), + m_d(new CNonMBTrackPrivate) +{ + *this=Other; +} + +MusicBrainz5::CNonMBTrack& MusicBrainz5::CNonMBTrack::operator =(const CNonMBTrack& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Title=Other.m_d->m_Title; + m_d->m_Artist=Other.m_d->m_Artist; + m_d->m_Length=Other.m_d->m_Length; + } + + return *this; +} + +MusicBrainz5::CNonMBTrack::~CNonMBTrack() +{ + delete m_d; +} + +MusicBrainz5::CNonMBTrack *MusicBrainz5::CNonMBTrack::Clone() +{ + return new CNonMBTrack(*this); +} + +void MusicBrainz5::CNonMBTrack::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised non MB track attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CNonMBTrack::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("artist"==NodeName) + { + ProcessItem(Node,m_d->m_Artist); + } + else if ("length"==NodeName) + { + ProcessItem(Node,m_d->m_Length); + } + else + { + std::cerr << "Unrecognised non MB track element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CNonMBTrack::GetElementName() +{ + return "track"; +} + +std::string MusicBrainz5::CNonMBTrack::Title() const +{ + return m_d->m_Title; +} + +std::string MusicBrainz5::CNonMBTrack::Artist() const +{ + return m_d->m_Artist; +} + +int MusicBrainz5::CNonMBTrack::Length() const +{ + return m_d->m_Length; +} + +std::ostream& MusicBrainz5::CNonMBTrack::Serialise(std::ostream& os) const +{ + os << "NonMBTrack:" << std::endl; + + CEntity::Serialise(os); + + os << "\tTitle: " << Title() << std::endl; + os << "\tArtist: " << Artist() << std::endl; + os << "\tLength: " << Length() << std::endl; + + return os; +} diff --git a/src/PUID.cc b/src/PUID.cc new file mode 100644 index 0000000..153d13a --- /dev/null +++ b/src/PUID.cc @@ -0,0 +1,152 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/PUID.h" + +#include "musicbrainz5/RecordingList.h" +#include "musicbrainz5/Recording.h" + +class MusicBrainz5::CPUIDPrivate +{ + public: + CPUIDPrivate() + : m_RecordingList(0) + { + } + + std::string m_ID; + CRecordingList *m_RecordingList; +}; + +MusicBrainz5::CPUID::CPUID(const XMLNode& Node) +: CEntity(), + m_d(new CPUIDPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "PUID node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CPUID::CPUID(const CPUID& Other) +: CEntity(), + m_d(new CPUIDPrivate) +{ + *this=Other; +} + +MusicBrainz5::CPUID& MusicBrainz5::CPUID::operator =(const CPUID& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + + if (Other.m_d->m_RecordingList) + m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); + } + + return *this; +} + +MusicBrainz5::CPUID::~CPUID() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CPUID::Cleanup() +{ + delete m_d->m_RecordingList; + m_d->m_RecordingList=0; +} + +MusicBrainz5::CPUID *MusicBrainz5::CPUID::Clone() +{ + return new CPUID(*this); +} + +void MusicBrainz5::CPUID::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else + { + std::cerr << "Unrecognised puid attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CPUID::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("recording-list"==NodeName) + { + ProcessItem(Node,m_d->m_RecordingList); + } + else + { + std::cerr << "Unrecognised PUID element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CPUID::GetElementName() +{ + return "puid"; +} + +std::string MusicBrainz5::CPUID::ID() const +{ + return m_d->m_ID; +} + +MusicBrainz5::CRecordingList *MusicBrainz5::CPUID::RecordingList() const +{ + return m_d->m_RecordingList; +} + +std::ostream& MusicBrainz5::CPUID::Serialise(std::ostream& os) const +{ + os << "PUID:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + + if (RecordingList()) + os << *RecordingList() << std::endl; + + return os; +} + diff --git a/src/Query.cc b/src/Query.cc new file mode 100644 index 0000000..6aa7a8a --- /dev/null +++ b/src/Query.cc @@ -0,0 +1,526 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +//http://musicbrainz.org/doc/XML_Web_Service/Version_2 +//http://bugs.musicbrainz.org/browser/mmd-schema/trunk/schema/musicbrainz_mmd-2.0.rng +//http://wiki.musicbrainz.org/Picard_Tag_Mapping + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Query.h" + +#include +#include +#include + +#include +#include +#include + +#include + +#include "musicbrainz5/HTTPFetch.h" +#include "musicbrainz5/Disc.h" +#include "musicbrainz5/Message.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Release.h" + +class MusicBrainz5::CQueryPrivate +{ + public: + CQueryPrivate() + : m_Port(80), + m_ProxyPort(0), + m_LastResult(CQuery::eQuery_Success), + m_LastHTTPCode(200) + { + } + + std::string m_UserAgent; + std::string m_Server; + int m_Port; + std::string m_UserName; + std::string m_Password; + std::string m_ProxyHost; + int m_ProxyPort; + std::string m_ProxyUserName; + std::string m_ProxyPassword; + CQuery::tQueryResult m_LastResult; + int m_LastHTTPCode; + std::string m_LastErrorMessage; +}; + +MusicBrainz5::CQuery::CQuery(const std::string& UserAgent, const std::string& Server, int Port) +: m_d(new CQueryPrivate) +{ + m_d->m_UserAgent=UserAgent; + m_d->m_Server=Server; + m_d->m_Port=Port; +} + +MusicBrainz5::CQuery::~CQuery() +{ + delete m_d; +} + +void MusicBrainz5::CQuery::SetUserName(const std::string& UserName) +{ + m_d->m_UserName=UserName; +} + +void MusicBrainz5::CQuery::SetPassword(const std::string& Password) +{ + m_d->m_Password=Password; +} + +void MusicBrainz5::CQuery::SetProxyHost(const std::string& ProxyHost) +{ + m_d->m_ProxyHost=ProxyHost; +} + +void MusicBrainz5::CQuery::SetProxyPort(int ProxyPort) +{ + m_d->m_ProxyPort=ProxyPort; +} + +void MusicBrainz5::CQuery::SetProxyUserName(const std::string& ProxyUserName) +{ + m_d->m_ProxyUserName=ProxyUserName; +} + +void MusicBrainz5::CQuery::SetProxyPassword(const std::string& ProxyPassword) +{ + m_d->m_ProxyPassword=ProxyPassword; +} + +MusicBrainz5::CMetadata MusicBrainz5::CQuery::PerformQuery(const std::string& Query) +{ + WaitRequest(); + + CMetadata Metadata; + + CHTTPFetch Fetch(UserAgent(),m_d->m_Server,m_d->m_Port); + + if (!m_d->m_UserName.empty()) + Fetch.SetUserName(m_d->m_UserName); + + if (!m_d->m_Password.empty()) + Fetch.SetPassword(m_d->m_Password); + + if (!m_d->m_ProxyHost.empty()) + Fetch.SetProxyHost(m_d->m_ProxyHost); + + if (0!=m_d->m_ProxyPort) + Fetch.SetProxyPort(m_d->m_ProxyPort); + + if (!m_d->m_ProxyUserName.empty()) + Fetch.SetProxyUserName(m_d->m_ProxyUserName); + + if (!m_d->m_ProxyPassword.empty()) + Fetch.SetProxyPassword(m_d->m_ProxyPassword); + + try + { + int Ret=Fetch.Fetch(Query); + +#ifdef _MB5_DEBUG_ + std::cerr << "Ret: " << Ret << std::endl; +#endif + + if (Ret>0) + { + std::vector Data=Fetch.Data(); + std::string strData(Data.begin(),Data.end()); + +#ifdef _MB5_DEBUG_ + std::cerr << "Ret is '" << strData << "'" << std::endl; +#endif + + XMLResults Results; + XMLNode *TopNode = XMLRootNode::parseString(strData, &Results); + if (Results.code==eXMLErrorNone) + { + XMLNode MetadataNode=*TopNode; + if (!MetadataNode.isEmpty()) + { + Metadata=CMetadata(MetadataNode); + } + } + delete TopNode; + } + } + + catch (CConnectionError& Error) + { + m_d->m_LastResult=CQuery::eQuery_ConnectionError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CTimeoutError& Error) + { + m_d->m_LastResult=CQuery::eQuery_Timeout; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CAuthenticationError& Error) + { + m_d->m_LastResult=CQuery::eQuery_AuthenticationError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CFetchError& Error) + { + m_d->m_LastResult=CQuery::eQuery_FetchError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CRequestError& Error) + { + m_d->m_LastResult=CQuery::eQuery_RequestError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CResourceNotFoundError& Error) + { + m_d->m_LastResult=CQuery::eQuery_ResourceNotFound; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + return Metadata; +} + +MusicBrainz5::CMetadata MusicBrainz5::CQuery::Query(const std::string& Entity, const std::string& ID, const std::string& Resource, const tParamMap& Params) +{ + std::stringstream os; + + os << "/ws/2/" << Entity; + + if (!ID.empty()) + { + os << "/" << ID; + + if (!Resource.empty()) + os << "/" << Resource; + } + + if (!Params.empty()) + os << "?" << URLEncode(Params); + +#ifdef _MB5_DEBUG_ + std::cerr << "Query is '" << os.str() << "'" << std::endl; +#endif + + return PerformQuery(os.str()); +} + +MusicBrainz5::CReleaseList MusicBrainz5::CQuery::LookupDiscID(const std::string& DiscID) +{ + //Will this work soon (and return disc IDs as well)? + //http://musicbrainz.org/ws/2/discid/arIS30RPWowvwNEqsqdDnZzDGhk-?inc=artists+labels+recordings+release-groups+artist-credits + + MusicBrainz5::CReleaseList ReleaseList; + + CMetadata Metadata=Query("discid",DiscID); + + CDisc *Disc=Metadata.Disc(); + if (Disc && Disc->ReleaseList()) + ReleaseList=*Disc->ReleaseList(); + + return ReleaseList; +} + +MusicBrainz5::CRelease MusicBrainz5::CQuery::LookupRelease(const std::string& ReleaseID) +{ + MusicBrainz5::CRelease Release; + + tParamMap Params; + Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits"; + + CMetadata Metadata=Query("release",ReleaseID,"",Params); + if (Metadata.Release()) + Release=*Metadata.Release(); + + return Release; +} + +void MusicBrainz5::CQuery::WaitRequest() const +{ + if (m_d->m_Server.find("musicbrainz.org")!=std::string::npos) + { + static struct timeval LastRequest; + const int TimeBetweenRequests=2; + + struct timeval TimeNow; + gettimeofday(&TimeNow,0); + + if (LastRequest.tv_sec!=0 || LastRequest.tv_usec!=0) + { + struct timeval Diff; + + do + { + gettimeofday(&TimeNow,0); + timersub(&TimeNow,&LastRequest,&Diff); + + if (Diff.tv_sec& Entries) +{ + return EditCollection(CollectionID,Entries,"PUT"); +} + +bool MusicBrainz5::CQuery::DeleteCollectionEntries(const std::string& CollectionID, const std::vector& Entries) +{ + return EditCollection(CollectionID,Entries,"DELETE"); +} + +bool MusicBrainz5::CQuery::EditCollection(const std::string& CollectionID, const std::vector& Entries, const std::string& Action) +{ + bool RetVal=false; + + std::vector ToProcess=Entries; + + while (!ToProcess.empty()) + { + std::string Query; + + Query="/ws/2/collection/"+CollectionID+"/releases/"; + + std::vector ThisBatch; + while (!ToProcess.empty() && ThisBatch.size()<25) + { + ThisBatch.push_back(ToProcess.back()); + ToProcess.pop_back(); + } + + std::vector::const_iterator ThisRelease=ThisBatch.begin(); + while(ThisRelease!=ThisBatch.end()) + { + if (ThisRelease!=ThisBatch.begin()) + Query+=";"; + + Query+=*ThisRelease; + + ++ThisRelease; + } + + Query+="?client="+m_d->m_UserAgent; + + CHTTPFetch Fetch(UserAgent(),m_d->m_Server,m_d->m_Port); + + if (!m_d->m_UserName.empty()) + Fetch.SetUserName(m_d->m_UserName); + + if (!m_d->m_Password.empty()) + Fetch.SetPassword(m_d->m_Password); + + if (!m_d->m_ProxyHost.empty()) + Fetch.SetProxyHost(m_d->m_ProxyHost); + + if (0!=m_d->m_ProxyPort) + Fetch.SetProxyPort(m_d->m_ProxyPort); + + if (!m_d->m_ProxyUserName.empty()) + Fetch.SetProxyUserName(m_d->m_ProxyUserName); + + if (!m_d->m_ProxyPassword.empty()) + Fetch.SetProxyPassword(m_d->m_ProxyPassword); + + try + { +#ifdef _MB5_DEBUG_ + std::cerr << "Collection " << Action << " Query is '" << Query << "'" << std::endl; +#endif + + int Ret=Fetch.Fetch(Query,Action); + +#ifdef _MB5_DEBUG_ + std::cerr << "Collection Ret: " << Ret << std::endl; +#endif + + if (Ret>0) + { + std::vector Data=Fetch.Data(); + std::string strData(Data.begin(),Data.end()); + +#ifdef _MB5_DEBUG_ + std::cerr << "Collection " << Action << " ret is '" << strData << "'" << std::endl; +#endif + + XMLResults Results; + XMLNode *TopNode = XMLRootNode::parseString(strData, &Results); + if (Results.code==eXMLErrorNone) + { + XMLNode MetadataNode=*TopNode; + if (!MetadataNode.isEmpty()) + { + CMetadata Metadata(MetadataNode); + + if (Metadata.Message() && Metadata.Message()->Text()=="OK") + RetVal=RetVal && true; + } + } + delete TopNode; + } + } + + catch (CConnectionError& Error) + { + m_d->m_LastResult=CQuery::eQuery_ConnectionError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CTimeoutError& Error) + { + m_d->m_LastResult=CQuery::eQuery_Timeout; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CAuthenticationError& Error) + { + m_d->m_LastResult=CQuery::eQuery_AuthenticationError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CFetchError& Error) + { + m_d->m_LastResult=CQuery::eQuery_FetchError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CRequestError& Error) + { + m_d->m_LastResult=CQuery::eQuery_RequestError; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + + catch (CResourceNotFoundError& Error) + { + m_d->m_LastResult=CQuery::eQuery_ResourceNotFound; + m_d->m_LastHTTPCode=Fetch.Status(); + m_d->m_LastErrorMessage=Fetch.ErrorMessage(); + + throw; + } + } + + return RetVal; +} + +std::string MusicBrainz5::CQuery::UserAgent() const +{ + std::string UserAgent=m_d->m_UserAgent; + if (!UserAgent.empty()) + UserAgent+=" "; + UserAgent+=PACKAGE "/v" VERSION; + + return UserAgent; +} + +std::string MusicBrainz5::CQuery::URIEscape(const std::string &URI) +{ + char *EscURIStr = ne_path_escape(URI.c_str()); + std::string EscURI((const char *)EscURIStr); + free(EscURIStr); + return EscURI; +} + +std::string MusicBrainz5::CQuery::URLEncode(const std::map& Params) +{ + std::string EncodedStr; + + for (std::map::const_iterator i = Params.begin(); i != Params.end(); i++) + { + std::string Name = (*i).first; + std::string Value = (*i).second; + + if (i!=Params.begin()) + EncodedStr += "&"; + + EncodedStr += Name + "=" + URIEscape(Value); + } + return EncodedStr; +} + +MusicBrainz5::CQuery::tQueryResult MusicBrainz5::CQuery::LastResult() const +{ + return m_d->m_LastResult; +} + +int MusicBrainz5::CQuery::LastHTTPCode() const +{ + return m_d->m_LastHTTPCode; +} + +std::string MusicBrainz5::CQuery::LastErrorMessage() const +{ + return m_d->m_LastErrorMessage; +} + +std::string MusicBrainz5::CQuery::Version() const +{ + return PACKAGE "-v" VERSION; +} diff --git a/src/Rating.cc b/src/Rating.cc new file mode 100644 index 0000000..2e6e754 --- /dev/null +++ b/src/Rating.cc @@ -0,0 +1,135 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Rating.h" + +class MusicBrainz5::CRatingPrivate +{ + public: + CRatingPrivate() + : m_VotesCount(0), + m_Rating(0.0) + { + } + + int m_VotesCount; + double m_Rating; +}; + +MusicBrainz5::CRating::CRating(const XMLNode& Node) +: CEntity(), + m_d(new CRatingPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Rating node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + if (Node.getText()) + { + ProcessItem(Node,m_d->m_Rating); + } + } +} + +MusicBrainz5::CRating::CRating(const CRating& Other) +: CEntity(), + m_d(new CRatingPrivate) +{ + *this=Other; +} + +MusicBrainz5::CRating& MusicBrainz5::CRating::operator =(const CRating& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_VotesCount=Other.m_d->m_VotesCount; + m_d->m_Rating=Other.m_d->m_Rating; + } + + return *this; +} + +MusicBrainz5::CRating::~CRating() +{ + delete m_d; +} + +MusicBrainz5::CRating *MusicBrainz5::CRating::Clone() +{ + return new CRating(*this); +} + +void MusicBrainz5::CRating::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("votes-count"==Name) + { + ProcessItem(Value,m_d->m_VotesCount); + } + else + { + std::cerr << "Unrecognised rating attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CRating::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + std::cerr << "Unrecognised rating attribute: '" << NodeName << "'" << std::endl; +} + +std::string MusicBrainz5::CRating::GetElementName() +{ + return "rating"; +} + +int MusicBrainz5::CRating::VotesCount() const +{ + return m_d->m_VotesCount; +} + +double MusicBrainz5::CRating::Rating() const +{ + return m_d->m_Rating; +} + +std::ostream& MusicBrainz5::CRating::Serialise(std::ostream& os) const +{ + os << "Rating:" << std::endl; + + CEntity::Serialise(os); + + os << "\tVotes count: " << VotesCount() << std::endl; + os << "\tRating: " << Rating() << std::endl; + + return os; +} diff --git a/src/Recording.cc b/src/Recording.cc new file mode 100644 index 0000000..76536f3 --- /dev/null +++ b/src/Recording.cc @@ -0,0 +1,361 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Recording.h" + +#include "musicbrainz5/ArtistCredit.h" +#include "musicbrainz5/Rating.h" +#include "musicbrainz5/UserRating.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/PUIDList.h" +#include "musicbrainz5/PUID.h" +#include "musicbrainz5/ISRCList.h" +#include "musicbrainz5/ISRC.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/Relation.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/Tag.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/UserTag.h" + +class MusicBrainz5::CRecordingPrivate +{ + public: + CRecordingPrivate() + : m_Length(0), + m_ArtistCredit(0), + m_ReleaseList(0), + m_PUIDList(0), + m_ISRCList(0), + m_RelationListList(0), + m_TagList(0), + m_UserTagList(0), + m_Rating(0), + m_UserRating(0) + { + } + + std::string m_ID; + std::string m_Title; + int m_Length; + std::string m_Disambiguation; + CArtistCredit *m_ArtistCredit; + CReleaseList *m_ReleaseList; + CPUIDList *m_PUIDList; + CISRCList *m_ISRCList; + CRelationListList *m_RelationListList; + CTagList *m_TagList; + CUserTagList *m_UserTagList; + CRating *m_Rating; + CUserRating *m_UserRating; +}; + +MusicBrainz5::CRecording::CRecording(const XMLNode& Node) +: CEntity(), + m_d(new CRecordingPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Recording node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CRecording::CRecording(const CRecording& Other) +: CEntity(), + m_d(new CRecordingPrivate) +{ + *this=Other; +} + +MusicBrainz5::CRecording& MusicBrainz5::CRecording::operator =(const CRecording& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Title=Other.m_d->m_Title; + m_d->m_Length=Other.m_d->m_Length; + m_d->m_Disambiguation=Other.m_d->m_Disambiguation; + + if (Other.m_d->m_ArtistCredit) + m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); + + if (Other.m_d->m_ReleaseList) + m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); + + if (Other.m_d->m_PUIDList) + m_d->m_PUIDList=new CPUIDList(*Other.m_d->m_PUIDList); + + if (Other.m_d->m_ISRCList) + m_d->m_ISRCList=new CISRCList(*Other.m_d->m_ISRCList); + + if (Other.m_d->m_RelationListList) + m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); + + if (Other.m_d->m_TagList) + m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); + + if (Other.m_d->m_UserTagList) + m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); + + if (Other.m_d->m_Rating) + m_d->m_Rating=new CRating(*Other.m_d->m_Rating); + + if (Other.m_d->m_UserRating) + m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); + } + + return *this; +} + +MusicBrainz5::CRecording::~CRecording() +{ + Cleanup(); + + delete m_d; +} + +MusicBrainz5::CRecording *MusicBrainz5::CRecording::Clone() +{ + return new CRecording(*this); +} + +void MusicBrainz5::CRecording::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else + { + std::cerr << "Unrecognised recording attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CRecording::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("length"==NodeName) + { + ProcessItem(Node,m_d->m_Length); + } + else if ("disambiguation"==NodeName) + { + ProcessItem(Node,m_d->m_Disambiguation); + } + else if ("artist-credit"==NodeName) + { + ProcessItem(Node,m_d->m_ArtistCredit); + } + else if ("release-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseList); + } + else if ("puid-list"==NodeName) + { + ProcessItem(Node,m_d->m_PUIDList); + } + else if ("isrc-list"==NodeName) + { + ProcessItem(Node,m_d->m_ISRCList); + } + else if ("relation-list"==NodeName) + { + ProcessRelationList(Node,m_d->m_RelationListList); + } + else if ("tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_TagList); + } + else if ("user-tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_UserTagList); + } + else if ("rating"==NodeName) + { + ProcessItem(Node,m_d->m_Rating); + } + else if ("user-rating"==NodeName) + { + ProcessItem(Node,m_d->m_UserRating); + } + else + { + std::cerr << "Unrecognised recording element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CRecording::GetElementName() +{ + return "recording"; +} + +void MusicBrainz5::CRecording::Cleanup() +{ + delete m_d->m_ArtistCredit; + m_d->m_ArtistCredit=0; + + delete m_d->m_ReleaseList; + m_d->m_ReleaseList=0; + + delete m_d->m_PUIDList; + m_d->m_PUIDList=0; + + delete m_d->m_ISRCList; + m_d->m_ISRCList=0; + + delete m_d->m_RelationListList; + m_d->m_RelationListList=0; + + delete m_d->m_TagList; + m_d->m_TagList=0; + + delete m_d->m_UserTagList; + m_d->m_UserTagList=0; + + delete m_d->m_Rating; + m_d->m_Rating=0; + + delete m_d->m_UserRating; + m_d->m_UserRating=0; +} + +std::string MusicBrainz5::CRecording::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CRecording::Title() const +{ + return m_d->m_Title; +} + +int MusicBrainz5::CRecording::Length() const +{ + return m_d->m_Length; +} + +std::string MusicBrainz5::CRecording::Disambiguation() const +{ + return m_d->m_Disambiguation; +} + +MusicBrainz5::CArtistCredit *MusicBrainz5::CRecording::ArtistCredit() const +{ + return m_d->m_ArtistCredit; +} + +MusicBrainz5::CReleaseList *MusicBrainz5::CRecording::ReleaseList() const +{ + return m_d->m_ReleaseList; +} + +MusicBrainz5::CPUIDList *MusicBrainz5::CRecording::PUIDList() const +{ + return m_d->m_PUIDList; +} + +MusicBrainz5::CISRCList *MusicBrainz5::CRecording::ISRCList() const +{ + return m_d->m_ISRCList; +} + +MusicBrainz5::CRelationListList *MusicBrainz5::CRecording::RelationListList() const +{ + return m_d->m_RelationListList; +} + +MusicBrainz5::CTagList *MusicBrainz5::CRecording::TagList() const +{ + return m_d->m_TagList; +} + +MusicBrainz5::CUserTagList *MusicBrainz5::CRecording::UserTagList() const +{ + return m_d->m_UserTagList; +} + +MusicBrainz5::CRating *MusicBrainz5::CRecording::Rating() const +{ + return m_d->m_Rating; +} + +MusicBrainz5::CUserRating *MusicBrainz5::CRecording::UserRating() const +{ + return m_d->m_UserRating; +} + +std::ostream& MusicBrainz5::CRecording::Serialise(std::ostream& os) const +{ + os << "Recording:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tTitle: " << Title() << std::endl; + os << "\tLength: " << Length() << std::endl; + os << "\tDisambiguation: " << Disambiguation() << std::endl; + + if (ArtistCredit()) + os << *ArtistCredit() << std::endl; + + if (ReleaseList()) + os << *ReleaseList() << std::endl; + + if (PUIDList()) + os << *PUIDList() << std::endl; + + if (ISRCList()) + os << *ISRCList() << std::endl; + + if (RelationListList()) + os << *RelationListList() << std::endl; + + if (TagList()) + os << *TagList() << std::endl; + + if (UserTagList()) + os << *UserTagList() << std::endl; + + if (Rating()) + os << *Rating() << std::endl; + + if (UserRating()) + os << *UserRating() << std::endl; + + return os; +} diff --git a/src/Relation.cc b/src/Relation.cc new file mode 100644 index 0000000..df044c7 --- /dev/null +++ b/src/Relation.cc @@ -0,0 +1,339 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Relation.h" + +#include "musicbrainz5/Artist.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/ReleaseGroup.h" +#include "musicbrainz5/Recording.h" +#include "musicbrainz5/Label.h" +#include "musicbrainz5/Work.h" +#include "musicbrainz5/AttributeList.h" +#include "musicbrainz5/Attribute.h" + +class MusicBrainz5::CRelationPrivate +{ + public: + CRelationPrivate() + : m_AttributeList(0), + m_Artist(0), + m_Release(0), + m_ReleaseGroup(0), + m_Recording(0), + m_Label(0), + m_Work(0) + { + } + + std::string m_Type; + std::string m_Target; + std::string m_Direction; + CAttributeList *m_AttributeList; + std::string m_Begin; + std::string m_End; + std::string m_Ended; + CArtist *m_Artist; + CRelease *m_Release; + CReleaseGroup *m_ReleaseGroup; + CRecording *m_Recording; + CLabel *m_Label; + CWork *m_Work; +}; + +MusicBrainz5::CRelation::CRelation(const XMLNode& Node) +: CEntity(), + m_d(new CRelationPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Relation node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CRelation::CRelation(const CRelation& Other) +: CEntity(), + m_d(new CRelationPrivate) +{ + *this=Other; +} + +MusicBrainz5::CRelation& MusicBrainz5::CRelation::operator =(const CRelation& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_Type=Other.m_d->m_Type; + m_d->m_Target=Other.m_d->m_Target; + m_d->m_Direction=Other.m_d->m_Direction; + + if (Other.m_d->m_AttributeList) + m_d->m_AttributeList=new CAttributeList(*Other.m_d->m_AttributeList); + + m_d->m_Begin=Other.m_d->m_Begin; + m_d->m_End=Other.m_d->m_End; + m_d->m_Ended=Other.m_d->m_Ended; + + if (Other.m_d->m_Artist) + m_d->m_Artist=new CArtist(*Other.m_d->m_Artist); + + if (Other.m_d->m_Release) + m_d->m_Release=new CRelease(*Other.m_d->m_Release); + + if (Other.m_d->m_ReleaseGroup) + m_d->m_ReleaseGroup=new CReleaseGroup(*Other.m_d->m_ReleaseGroup); + + if (Other.m_d->m_Recording) + m_d->m_Recording=new CRecording(*Other.m_d->m_Recording); + + if (Other.m_d->m_Label) + m_d->m_Label=new CLabel(*Other.m_d->m_Label); + + if (Other.m_d->m_Work) + m_d->m_Work=new CWork(*Other.m_d->m_Work); + } + + return *this; +} + +MusicBrainz5::CRelation::~CRelation() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CRelation::Cleanup() +{ + delete m_d->m_AttributeList; + m_d->m_AttributeList=0; + + delete m_d->m_Artist; + m_d->m_Artist=0; + + delete m_d->m_Release; + m_d->m_Release=0; + + delete m_d->m_ReleaseGroup; + m_d->m_ReleaseGroup=0; + + delete m_d->m_Recording; + m_d->m_Recording=0; + + delete m_d->m_Label; + m_d->m_Label=0; + + delete m_d->m_Work; + m_d->m_Work=0; +} + +MusicBrainz5::CRelation *MusicBrainz5::CRelation::Clone() +{ + return new CRelation(*this); +} + +void MusicBrainz5::CRelation::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("type"==Name) + m_d->m_Type=Value; + else + { + std::cerr << "Unrecognised relation attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CRelation::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("target"==NodeName) + { + ProcessItem(Node,m_d->m_Target); + } + else if ("direction"==NodeName) + { + ProcessItem(Node,m_d->m_Direction); + } + else if ("attribute-list"==NodeName) + { + ProcessItem(Node,m_d->m_AttributeList); + } + else if ("begin"==NodeName) + { + ProcessItem(Node,m_d->m_Begin); + } + else if ("end"==NodeName) + { + ProcessItem(Node,m_d->m_End); + } + else if ("ended"==NodeName) + { + ProcessItem(Node,m_d->m_Ended); + } + else if ("artist"==NodeName) + { + ProcessItem(Node,m_d->m_Artist); + } + else if ("release"==NodeName) + { + ProcessItem(Node,m_d->m_Release); + } + else if ("release-group"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseGroup); + } + else if ("recording"==NodeName) + { + ProcessItem(Node,m_d->m_Recording); + } + else if ("label"==NodeName) + { + ProcessItem(Node,m_d->m_Label); + } + else if ("work"==NodeName) + { + ProcessItem(Node,m_d->m_Work); + } + else + { + std::cerr << "Unrecognised relation element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CRelation::GetElementName() +{ + return "relation"; +} + +std::string MusicBrainz5::CRelation::Type() const +{ + return m_d->m_Type; +} + +std::string MusicBrainz5::CRelation::Target() const +{ + return m_d->m_Target; +} + +std::string MusicBrainz5::CRelation::Direction() const +{ + return m_d->m_Direction; +} + +MusicBrainz5::CAttributeList *MusicBrainz5::CRelation::AttributeList() const +{ + return m_d->m_AttributeList; +} + +std::string MusicBrainz5::CRelation::Begin() const +{ + return m_d->m_Begin; +} + +std::string MusicBrainz5::CRelation::End() const +{ + return m_d->m_End; +} + +std::string MusicBrainz5::CRelation::Ended() const +{ + return m_d->m_Ended; +} + +MusicBrainz5::CArtist *MusicBrainz5::CRelation::Artist() const +{ + return m_d->m_Artist; +} + +MusicBrainz5::CRelease *MusicBrainz5::CRelation::Release() const +{ + return m_d->m_Release; +} + +MusicBrainz5::CReleaseGroup *MusicBrainz5::CRelation::ReleaseGroup() const +{ + return m_d->m_ReleaseGroup; +} + +MusicBrainz5::CRecording *MusicBrainz5::CRelation::Recording() const +{ + return m_d->m_Recording; +} + +MusicBrainz5::CLabel *MusicBrainz5::CRelation::Label() const +{ + return m_d->m_Label; +} + +MusicBrainz5::CWork *MusicBrainz5::CRelation::Work() const +{ + return m_d->m_Work; +} + +std::ostream& MusicBrainz5::CRelation::Serialise(std::ostream& os) const +{ + os << "Relation:" << std::endl; + + CEntity::Serialise(os); + + os << "\tType: " << Type() << std::endl; + os << "\tTarget: " << Target() << std::endl; + os << "\tDirection: " << Direction() << std::endl; + + if (AttributeList()) + os << *AttributeList() << std::endl; + + os << "\tBegin: " << Begin() << std::endl; + os << "\tEnd: " << End() << std::endl; + os << "\tEnded: " << Ended() << std::endl; + + if (Artist()) + os << *Artist() << std::endl; + + if (Release()) + os << *Release() << std::endl; + + if (ReleaseGroup()) + os << *ReleaseGroup() << std::endl; + + if (Recording()) + os << *Recording() << std::endl; + + if (Label()) + os << *Label() << std::endl; + + if (Work()) + os << *Work() << std::endl; + + return os; +} diff --git a/src/RelationList.cc b/src/RelationList.cc new file mode 100644 index 0000000..d2addb1 --- /dev/null +++ b/src/RelationList.cc @@ -0,0 +1,112 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/RelationList.h" + +#include "musicbrainz5/Relation.h" + +class MusicBrainz5::CRelationListPrivate +{ + public: + std::string m_TargetType; +}; + +MusicBrainz5::CRelationList::CRelationList(const XMLNode& Node) +: CListImpl(), + m_d(new CRelationListPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "RelationList node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CRelationList::CRelationList(const CRelationList& Other) +: CListImpl(), + m_d(new CRelationListPrivate) +{ + *this=Other; +} + +MusicBrainz5::CRelationList& MusicBrainz5::CRelationList::operator =(const CRelationList& Other) +{ + if (this!=&Other) + { + CListImpl::operator =(Other); + + m_d->m_TargetType=Other.m_d->m_TargetType; + } + + return *this; +} + +MusicBrainz5::CRelationList::~CRelationList() +{ + delete m_d; +} + +MusicBrainz5::CRelationList *MusicBrainz5::CRelationList::Clone() +{ + return new CRelationList(*this); +} + +void MusicBrainz5::CRelationList::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("target-type"==Name) + ProcessItem(Value,m_d->m_TargetType); + else + CListImpl::ParseAttribute(Name,Value); +} + +void MusicBrainz5::CRelationList::ParseElement(const XMLNode& Node) +{ + CListImpl::ParseElement(Node); +} + +std::string MusicBrainz5::CRelationList::GetElementName() +{ + return "relation-list"; +} + +std::string MusicBrainz5::CRelationList::TargetType() const +{ + return m_d->m_TargetType; +} + +std::ostream& MusicBrainz5::CRelationList::Serialise(std::ostream& os) const +{ + os << "Relation list:" << std::endl; + + os << "\tTarget type: " << TargetType() << std::endl; + + CListImpl::Serialise(os); + + return os; +} diff --git a/src/RelationListList.cc b/src/RelationListList.cc new file mode 100644 index 0000000..6ee2d8d --- /dev/null +++ b/src/RelationListList.cc @@ -0,0 +1,149 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/RelationListList.h" + +#include + +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/Relation.h" + +class MusicBrainz5::CRelationListListPrivate +{ + public: + CRelationListListPrivate() + : m_ListGroup(0) + { + } + + std::vector *m_ListGroup; +}; + +MusicBrainz5::CRelationListList::CRelationListList() +: m_d(new CRelationListListPrivate) +{ +} + +MusicBrainz5::CRelationListList::CRelationListList(const CRelationListList& Other) +: m_d(new CRelationListListPrivate) +{ + *this=Other; +} + +MusicBrainz5::CRelationListList& MusicBrainz5::CRelationListList::operator =(const CRelationListList& Other) +{ + if (this!=&Other) + { + Cleanup(); + + if (Other.m_d->m_ListGroup) + { + m_d->m_ListGroup=new std::vector; + + for (std::vector::const_iterator ThisRelationList=Other.m_d->m_ListGroup->begin();ThisRelationList!=Other.m_d->m_ListGroup->end();++ThisRelationList) + { + CRelationList *RelationList=*ThisRelationList; + m_d->m_ListGroup->push_back(new CRelationList(*RelationList)); + } + } + } + + return *this; +} + +MusicBrainz5::CRelationListList::~CRelationListList() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CRelationListList::Cleanup() +{ + if (m_d->m_ListGroup) + { + for (std::vector::const_iterator ThisRelationList=m_d->m_ListGroup->begin();ThisRelationList!=m_d->m_ListGroup->end();++ThisRelationList) + { + CRelationList *RelationList=*ThisRelationList; + + delete RelationList; + } + } + + delete m_d->m_ListGroup; + m_d->m_ListGroup=0; +} + +void MusicBrainz5::CRelationListList::Add(CRelationList *RelationList) +{ + if (!m_d->m_ListGroup) + m_d->m_ListGroup=new std::vector; + + m_d->m_ListGroup->push_back(new CRelationList(*RelationList)); +} + +int MusicBrainz5::CRelationListList::NumItems() const +{ + int Ret=0; + + if (m_d->m_ListGroup) + Ret=m_d->m_ListGroup->size(); + + return Ret; +} + +MusicBrainz5::CRelationList *MusicBrainz5::CRelationListList::Item(int Item) const +{ + CRelationList *RelationList=0; + + if (m_d->m_ListGroup && Item<(int)m_d->m_ListGroup->size()) + RelationList=(*m_d->m_ListGroup)[Item]; + + return RelationList; +} + +std::ostream& MusicBrainz5::CRelationListList::Serialise(std::ostream& os) const +{ + if (m_d->m_ListGroup && m_d->m_ListGroup->size()!=0) + { + os << "RelationLists:" << std::endl; + + for (int count=0;count. + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Release.h" + +#include + +#include "musicbrainz5/TextRepresentation.h" +#include "musicbrainz5/ArtistCredit.h" +#include "musicbrainz5/ReleaseGroup.h" +#include "musicbrainz5/Medium.h" +#include "musicbrainz5/LabelInfoList.h" +#include "musicbrainz5/LabelInfo.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/Relation.h" +#include "musicbrainz5/MediumList.h" +#include "musicbrainz5/Medium.h" +#include "musicbrainz5/Collection.h" +#include "musicbrainz5/CollectionList.h" + +class MusicBrainz5::CReleasePrivate +{ + public: + CReleasePrivate() + : m_TextRepresentation(0), + m_ArtistCredit(0), + m_ReleaseGroup(0), + m_LabelInfoList(0), + m_MediumList(0), + m_RelationListList(0), + m_CollectionList(0) + { + } + + std::string m_ID; + std::string m_Title; + std::string m_Status; + std::string m_Quality; + std::string m_Disambiguation; + std::string m_Packaging; + CTextRepresentation *m_TextRepresentation; + CArtistCredit *m_ArtistCredit; + CReleaseGroup *m_ReleaseGroup; + std::string m_Date; + std::string m_Country; + std::string m_Barcode; + std::string m_ASIN; + CLabelInfoList *m_LabelInfoList; + CMediumList *m_MediumList; + CRelationListList *m_RelationListList; + CCollectionList *m_CollectionList; +}; + +MusicBrainz5::CRelease::CRelease(const XMLNode& Node) +: CEntity(), + m_d(new CReleasePrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Release node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CRelease::CRelease(const CRelease& Other) +: CEntity(), + m_d(new CReleasePrivate) +{ + *this=Other; +} + +MusicBrainz5::CRelease& MusicBrainz5::CRelease::operator =(const CRelease& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Title=Other.m_d->m_Title; + m_d->m_Status=Other.m_d->m_Status; + m_d->m_Quality=Other.m_d->m_Quality; + m_d->m_Disambiguation=Other.m_d->m_Disambiguation; + m_d->m_Packaging=Other.m_d->m_Packaging; + + if (Other.m_d->m_TextRepresentation) + m_d->m_TextRepresentation=new CTextRepresentation(*Other.m_d->m_TextRepresentation); + + if (Other.m_d->m_ArtistCredit) + m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); + + if (Other.m_d->m_ReleaseGroup) + m_d->m_ReleaseGroup=new CReleaseGroup(*Other.m_d->m_ReleaseGroup); + + m_d->m_Date=Other.m_d->m_Date; + m_d->m_Country=Other.m_d->m_Country; + m_d->m_Barcode=Other.m_d->m_Barcode; + m_d->m_ASIN=Other.m_d->m_ASIN; + + if (Other.m_d->m_LabelInfoList) + m_d->m_LabelInfoList=new CLabelInfoList(*Other.m_d->m_LabelInfoList); + + if (Other.m_d->m_MediumList) + m_d->m_MediumList=new CMediumList(*Other.m_d->m_MediumList); + + if (Other.m_d->m_RelationListList) + m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); + + if (Other.m_d->m_CollectionList) + m_d->m_CollectionList=new CCollectionList(*Other.m_d->m_CollectionList); + } + + return *this; +} + +MusicBrainz5::CRelease::~CRelease() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CRelease::Cleanup() +{ + delete m_d->m_TextRepresentation; + m_d->m_TextRepresentation=0; + + delete m_d->m_ArtistCredit; + m_d->m_ArtistCredit=0; + + delete m_d->m_ReleaseGroup; + m_d->m_ReleaseGroup=0; + + delete m_d->m_LabelInfoList; + m_d->m_LabelInfoList=0; + + delete m_d->m_MediumList; + m_d->m_MediumList=0; + + delete m_d->m_RelationListList; + m_d->m_RelationListList=0; +} + +MusicBrainz5::CRelease *MusicBrainz5::CRelease::Clone() +{ + return new CRelease(*this); +} + +void MusicBrainz5::CRelease::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else + { + std::cerr << "Unrecognised release attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CRelease::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("status"==NodeName) + { + ProcessItem(Node,m_d->m_Status); + } + else if ("quality"==NodeName) + { + ProcessItem(Node,m_d->m_Quality); + } + else if ("disambiguation"==NodeName) + { + ProcessItem(Node,m_d->m_Disambiguation); + } + else if ("packaging"==NodeName) + { + ProcessItem(Node,m_d->m_Packaging); + } + else if ("text-representation"==NodeName) + { + ProcessItem(Node,m_d->m_TextRepresentation); + } + else if ("artist-credit"==NodeName) + { + ProcessItem(Node,m_d->m_ArtistCredit); + } + else if ("release-group"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseGroup); + } + else if ("date"==NodeName) + { + ProcessItem(Node,m_d->m_Date); + } + else if ("country"==NodeName) + { + ProcessItem(Node,m_d->m_Country); + } + else if ("barcode"==NodeName) + { + ProcessItem(Node,m_d->m_Barcode); + } + else if ("asin"==NodeName) + { + ProcessItem(Node,m_d->m_ASIN); + } + else if ("label-info-list"==NodeName) + { + ProcessItem(Node,m_d->m_LabelInfoList); + } + else if ("medium-list"==NodeName) + { + ProcessItem(Node,m_d->m_MediumList); + } + else if ("relation-list"==NodeName) + { + ProcessRelationList(Node,m_d->m_RelationListList); + } + else if ("collection-list"==NodeName) + { + ProcessItem(Node,m_d->m_CollectionList); + } + else + { + std::cerr << "Unrecognised release element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CRelease::GetElementName() +{ + return "release"; +} + +std::string MusicBrainz5::CRelease::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CRelease::Title() const +{ + return m_d->m_Title; +} + +std::string MusicBrainz5::CRelease::Status() const +{ + return m_d->m_Status; +} + +std::string MusicBrainz5::CRelease::Quality() const +{ + return m_d->m_Quality; +} + +std::string MusicBrainz5::CRelease::Disambiguation() const +{ + return m_d->m_Disambiguation; +} + +std::string MusicBrainz5::CRelease::Packaging() const +{ + return m_d->m_Packaging; +} + +MusicBrainz5::CTextRepresentation *MusicBrainz5::CRelease::TextRepresentation() const +{ + return m_d->m_TextRepresentation; +} + +MusicBrainz5::CArtistCredit *MusicBrainz5::CRelease::ArtistCredit() const +{ + return m_d->m_ArtistCredit; +} + +MusicBrainz5::CReleaseGroup *MusicBrainz5::CRelease::ReleaseGroup() const +{ + return m_d->m_ReleaseGroup; +} + +std::string MusicBrainz5::CRelease::Date() const +{ + return m_d->m_Date; +} + +std::string MusicBrainz5::CRelease::Country() const +{ + return m_d->m_Country; +} + +std::string MusicBrainz5::CRelease::Barcode() const +{ + return m_d->m_Barcode; +} + +std::string MusicBrainz5::CRelease::ASIN() const +{ + return m_d->m_ASIN; +} + +MusicBrainz5::CLabelInfoList *MusicBrainz5::CRelease::LabelInfoList() const +{ + return m_d->m_LabelInfoList; +} + +MusicBrainz5::CMediumList *MusicBrainz5::CRelease::MediumList() const +{ + return m_d->m_MediumList; +} + +MusicBrainz5::CRelationListList *MusicBrainz5::CRelease::RelationListList() const +{ + return m_d->m_RelationListList; +} + +MusicBrainz5::CCollectionList *MusicBrainz5::CRelease::CollectionList() const +{ + return m_d->m_CollectionList; +} + +MusicBrainz5::CMediumList MusicBrainz5::CRelease::MediaMatchingDiscID(const std::string& DiscID) const +{ + MusicBrainz5::CMediumList Ret; + + if (m_d->m_MediumList) + { + for (int count=0;countm_MediumList->NumItems();count++) + { + MusicBrainz5::CMedium *Medium=m_d->m_MediumList->Item(count); + + if (Medium->ContainsDiscID(DiscID)) + Ret.AddItem(new MusicBrainz5::CMedium(*Medium)); + } + } + + return Ret; +} + +std::ostream& MusicBrainz5::CRelease::Serialise(std::ostream& os) const +{ + os << "Release:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tTitle: " << Title() << std::endl; + os << "\tStatus: " << Status() << std::endl; + os << "\tQuality: " << Quality() << std::endl; + os << "\tDisambiguation: " << Disambiguation() << std::endl; + os << "\tPackaging: " << Packaging() << std::endl; + + if (TextRepresentation()) + os << *TextRepresentation(); + + if (ArtistCredit()) + os << *ArtistCredit() << std::endl; + + if (ReleaseGroup()) + os << *ReleaseGroup() << std::endl; + + os << "\tDate: " << Date() << std::endl; + os << "\tCountry: " << Country() << std::endl; + os << "\tBarcode: " << Barcode() << std::endl; + os << "\tASIN: " << ASIN() << std::endl; + + if (LabelInfoList()) + os << *LabelInfoList() << std::endl; + + if (MediumList()) + os << *MediumList() << std::endl; + + if (RelationListList()) + os << *RelationListList() << std::endl; + + if (CollectionList()) + os << *CollectionList() << std::endl; + + return os; +} diff --git a/src/ReleaseGroup.cc b/src/ReleaseGroup.cc new file mode 100644 index 0000000..a8c4edd --- /dev/null +++ b/src/ReleaseGroup.cc @@ -0,0 +1,356 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/ReleaseGroup.h" + +#include "musicbrainz5/ArtistCredit.h" +#include "musicbrainz5/Rating.h" +#include "musicbrainz5/UserRating.h" +#include "musicbrainz5/ReleaseList.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/Relation.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/Tag.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/UserTag.h" +#include "musicbrainz5/SecondaryTypeList.h" +#include "musicbrainz5/SecondaryType.h" + +class MusicBrainz5::CReleaseGroupPrivate +{ + public: + CReleaseGroupPrivate() + : m_ArtistCredit(0), + m_ReleaseList(0), + m_RelationListList(0), + m_TagList(0), + m_UserTagList(0), + m_Rating(0), + m_UserRating(0), + m_SecondaryTypeList(0) + { + } + + std::string m_ID; + std::string m_PrimaryType; + std::string m_Title; + std::string m_Disambiguation; + std::string m_FirstReleaseDate; + CArtistCredit *m_ArtistCredit; + CReleaseList *m_ReleaseList; + CRelationListList *m_RelationListList; + CTagList *m_TagList; + CUserTagList *m_UserTagList; + CRating *m_Rating; + CUserRating *m_UserRating; + CSecondaryTypeList *m_SecondaryTypeList; +}; + +MusicBrainz5::CReleaseGroup::CReleaseGroup(const XMLNode& Node) +: CEntity(), + m_d(new CReleaseGroupPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Name credit node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CReleaseGroup::CReleaseGroup(const CReleaseGroup& Other) +: CEntity(), + m_d(new CReleaseGroupPrivate) +{ + *this=Other; +} + +MusicBrainz5::CReleaseGroup& MusicBrainz5::CReleaseGroup::operator =(const CReleaseGroup& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_PrimaryType=Other.m_d->m_PrimaryType; + m_d->m_Title=Other.m_d->m_Title; + m_d->m_Disambiguation=Other.m_d->m_Disambiguation; + m_d->m_FirstReleaseDate=Other.m_d->m_FirstReleaseDate; + + if (Other.m_d->m_ArtistCredit) + m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); + + if (Other.m_d->m_ReleaseList) + m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); + + if (Other.m_d->m_RelationListList) + m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); + + if (Other.m_d->m_TagList) + m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); + + if (Other.m_d->m_UserTagList) + m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); + + if (Other.m_d->m_Rating) + m_d->m_Rating=new CRating(*Other.m_d->m_Rating); + + if (Other.m_d->m_UserRating) + m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); + + if (Other.m_d->m_SecondaryTypeList) + m_d->m_SecondaryTypeList=new CSecondaryTypeList(*Other.m_d->m_SecondaryTypeList); + } + + return *this; +} + +MusicBrainz5::CReleaseGroup::~CReleaseGroup() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CReleaseGroup::Cleanup() +{ + delete m_d->m_ArtistCredit; + m_d->m_ArtistCredit=0; + + delete m_d->m_ReleaseList; + m_d->m_ReleaseList=0; + + delete m_d->m_RelationListList; + m_d->m_RelationListList=0; + + delete m_d->m_TagList; + m_d->m_TagList=0; + + delete m_d->m_UserTagList; + m_d->m_UserTagList=0; + + delete m_d->m_Rating; + m_d->m_Rating=0; + + delete m_d->m_UserRating; + m_d->m_UserRating=0; + + delete m_d->m_SecondaryTypeList; + m_d->m_SecondaryTypeList=0; +} + +MusicBrainz5::CReleaseGroup *MusicBrainz5::CReleaseGroup::Clone() +{ + return new CReleaseGroup(*this); +} + +void MusicBrainz5::CReleaseGroup::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else if ("type"==Name) + { + //Ignore type + } + else + { + std::cerr << "Unrecognised releasegroup attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CReleaseGroup::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("primary-type"==NodeName) + { + ProcessItem(Node,m_d->m_PrimaryType); + } + else if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("disambiguation"==NodeName) + { + ProcessItem(Node,m_d->m_Disambiguation); + } + else if ("first-release-date"==NodeName) + { + ProcessItem(Node,m_d->m_FirstReleaseDate); + } + else if ("artist-credit"==NodeName) + { + ProcessItem(Node,m_d->m_ArtistCredit); + } + else if ("release-list"==NodeName) + { + ProcessItem(Node,m_d->m_ReleaseList); + } + else if ("relation-list"==NodeName) + { + ProcessRelationList(Node,m_d->m_RelationListList); + } + else if ("tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_TagList); + } + else if ("user-tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_UserTagList); + } + else if ("rating"==NodeName) + { + ProcessItem(Node,m_d->m_Rating); + } + else if ("user-rating"==NodeName) + { + ProcessItem(Node,m_d->m_UserRating); + } + else if ("secondary-type-list"==NodeName) + { + ProcessItem(Node,m_d->m_SecondaryTypeList); + } + else + { + std::cerr << "Unrecognised release group element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CReleaseGroup::GetElementName() +{ + return "release-group"; +} + +std::string MusicBrainz5::CReleaseGroup::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CReleaseGroup::PrimaryType() const +{ + return m_d->m_PrimaryType; +} + +std::string MusicBrainz5::CReleaseGroup::Title() const +{ + return m_d->m_Title; +} + +std::string MusicBrainz5::CReleaseGroup::Disambiguation() const +{ + return m_d->m_Disambiguation; +} + +std::string MusicBrainz5::CReleaseGroup::FirstReleaseDate() const +{ + return m_d->m_FirstReleaseDate; +} + +MusicBrainz5::CArtistCredit *MusicBrainz5::CReleaseGroup::ArtistCredit() const +{ + return m_d->m_ArtistCredit; +} + +MusicBrainz5::CReleaseList *MusicBrainz5::CReleaseGroup::ReleaseList() const +{ + return m_d->m_ReleaseList; +} + +MusicBrainz5::CRelationListList *MusicBrainz5::CReleaseGroup::RelationListList() const +{ + return m_d->m_RelationListList; +} + +MusicBrainz5::CTagList *MusicBrainz5::CReleaseGroup::TagList() const +{ + return m_d->m_TagList; +} + +MusicBrainz5::CUserTagList *MusicBrainz5::CReleaseGroup::UserTagList() const +{ + return m_d->m_UserTagList; +} + +MusicBrainz5::CRating *MusicBrainz5::CReleaseGroup::Rating() const +{ + return m_d->m_Rating; +} + +MusicBrainz5::CUserRating *MusicBrainz5::CReleaseGroup::UserRating() const +{ + return m_d->m_UserRating; +} + +MusicBrainz5::CSecondaryTypeList *MusicBrainz5::CReleaseGroup::SecondaryTypeList() const +{ + return m_d->m_SecondaryTypeList; +} + +std::ostream& MusicBrainz5::CReleaseGroup::Serialise(std::ostream& os) const +{ + os << "Release group:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tPrimaryType: " << PrimaryType() << std::endl; + os << "\tTitle: " << Title() << std::endl; + os << "\tDisambiguation: " << Disambiguation() << std::endl; + os << "\tFirst release date: " << FirstReleaseDate() << std::endl; + + if (ArtistCredit()) + os << *ArtistCredit() << std::endl; + + if (ReleaseList()) + os << *ReleaseList() << std::endl; + + if (RelationListList()) + os << *RelationListList() << std::endl; + + if (TagList()) + os << *TagList() << std::endl; + + if (UserTagList()) + os << *UserTagList() << std::endl; + + if (Rating()) + os << *Rating() << std::endl; + + if (UserRating()) + os << *UserRating() << std::endl; + + if (SecondaryTypeList()) + os << *SecondaryTypeList() << std::endl; + + return os; +} + diff --git a/src/SecondaryType.cc b/src/SecondaryType.cc new file mode 100644 index 0000000..46db98d --- /dev/null +++ b/src/SecondaryType.cc @@ -0,0 +1,125 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/SecondaryType.h" + + +class MusicBrainz5::CSecondaryTypePrivate +{ + public: + CSecondaryTypePrivate() + { + } + + std::string m_SecondaryType; +}; + +MusicBrainz5::CSecondaryType::CSecondaryType(const XMLNode& Node) +: CEntity(), + m_d(new CSecondaryTypePrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "SecondaryType node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + if (Node.getText()) + ProcessItem(Node,m_d->m_SecondaryType); + } +} + +MusicBrainz5::CSecondaryType::CSecondaryType(const CSecondaryType& Other) +: CEntity(), + m_d(new CSecondaryTypePrivate) +{ + *this=Other; +} + +MusicBrainz5::CSecondaryType& MusicBrainz5::CSecondaryType::operator =(const CSecondaryType& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_SecondaryType=Other.m_d->m_SecondaryType; + } + + return *this; +} + +MusicBrainz5::CSecondaryType::~CSecondaryType() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CSecondaryType::Cleanup() +{ +} + +MusicBrainz5::CSecondaryType *MusicBrainz5::CSecondaryType::Clone() +{ + return new CSecondaryType(*this); +} + +void MusicBrainz5::CSecondaryType::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised secondary type attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CSecondaryType::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + std::cerr << "Unrecognised secondary type element: '" << NodeName << "'" << std::endl; +} + +std::string MusicBrainz5::CSecondaryType::GetElementName() +{ + return "secondary-type"; +} + +std::string MusicBrainz5::CSecondaryType::SecondaryType() const +{ + return m_d->m_SecondaryType; +} + +std::ostream& MusicBrainz5::CSecondaryType::Serialise(std::ostream& os) const +{ + os << "Secondary Type:" << std::endl; + + CEntity::Serialise(os); + + os << "\tSecondaryType: " << SecondaryType() << std::endl; + + return os; +} diff --git a/src/SecondaryTypeList.cc b/src/SecondaryTypeList.cc new file mode 100644 index 0000000..603cb04 --- /dev/null +++ b/src/SecondaryTypeList.cc @@ -0,0 +1,102 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/SecondaryTypeList.h" + +#include "musicbrainz5/SecondaryType.h" + +class MusicBrainz5::CSecondaryTypeListPrivate +{ + public: + CSecondaryTypeListPrivate() + { + } +}; + +MusicBrainz5::CSecondaryTypeList::CSecondaryTypeList(const XMLNode& Node) +: CListImpl(), + m_d(new CSecondaryTypeListPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "SecondaryTypeList node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CSecondaryTypeList::CSecondaryTypeList(const CSecondaryTypeList& Other) +: CListImpl(), + m_d(new CSecondaryTypeListPrivate) +{ + *this=Other; +} + +MusicBrainz5::CSecondaryTypeList& MusicBrainz5::CSecondaryTypeList::operator =(const CSecondaryTypeList& Other) +{ + if (this!=&Other) + { + CListImpl::operator =(Other); + } + + return *this; +} + +MusicBrainz5::CSecondaryTypeList::~CSecondaryTypeList() +{ + delete m_d; +} + +MusicBrainz5::CSecondaryTypeList *MusicBrainz5::CSecondaryTypeList::Clone() +{ + return new CSecondaryTypeList(*this); +} + +void MusicBrainz5::CSecondaryTypeList::ParseAttribute(const std::string& Name, const std::string& Value) +{ + CListImpl::ParseAttribute(Name,Value); +} + +void MusicBrainz5::CSecondaryTypeList::ParseElement(const XMLNode& Node) +{ + CListImpl::ParseElement(Node); +} + +std::string MusicBrainz5::CSecondaryTypeList::GetElementName() +{ + return "secondary-type-list"; +} + +std::ostream& MusicBrainz5::CSecondaryTypeList::Serialise(std::ostream& os) const +{ + os << "Secondary type list:" << std::endl; + + CListImpl::Serialise(os); + + return os; +} diff --git a/src/Tag.cc b/src/Tag.cc new file mode 100644 index 0000000..e9f2d6b --- /dev/null +++ b/src/Tag.cc @@ -0,0 +1,136 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Tag.h" + +class MusicBrainz5::CTagPrivate +{ + public: + CTagPrivate() + : m_Count(0) + { + } + + int m_Count; + std::string m_Name; +}; + +MusicBrainz5::CTag::CTag(const XMLNode& Node) +: CEntity(), + m_d(new CTagPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Tag node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CTag::CTag(const CTag& Other) +: CEntity(), + m_d(new CTagPrivate) +{ + *this=Other; +} + +MusicBrainz5::CTag& MusicBrainz5::CTag::operator =(const CTag& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Count=Other.m_d->m_Count; + m_d->m_Name=Other.m_d->m_Name; + } + + return *this; +} + +MusicBrainz5::CTag::~CTag() +{ + delete m_d; +} + +MusicBrainz5::CTag *MusicBrainz5::CTag::Clone() +{ + return new CTag(*this); +} + +void MusicBrainz5::CTag::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("count"==Name) + { + ProcessItem(Value,m_d->m_Count); + } + else + { + std::cerr << "Unrecognised tag attribute: '" << Name << "'" << std::endl; + } +} + +void MusicBrainz5::CTag::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("name"==NodeName) + { + ProcessItem(Node,m_d->m_Name); + } + else + { + std::cerr << "Unrecognised tag element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CTag::GetElementName() +{ + return "tag"; +} + +int MusicBrainz5::CTag::Count() const +{ + return m_d->m_Count; +} + +std::string MusicBrainz5::CTag::Name() const +{ + return m_d->m_Name; +} + +std::ostream& MusicBrainz5::CTag::Serialise(std::ostream& os) const +{ + os << "Tag:" << std::endl; + + CEntity::Serialise(os); + + os << "\tCount: " << Count() << std::endl; + os << "\tName: " << Name() << std::endl; + + return os; +} diff --git a/src/TextRepresentation.cc b/src/TextRepresentation.cc new file mode 100644 index 0000000..0d08414 --- /dev/null +++ b/src/TextRepresentation.cc @@ -0,0 +1,129 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/TextRepresentation.h" + +class MusicBrainz5::CTextRepresentationPrivate +{ + public: + std::string m_Language; + std::string m_Script; +}; + +MusicBrainz5::CTextRepresentation::CTextRepresentation(const XMLNode& Node) +: CEntity(), + m_d(new CTextRepresentationPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Text representation node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CTextRepresentation::CTextRepresentation(const CTextRepresentation& Other) +: CEntity(), + m_d(new CTextRepresentationPrivate) +{ + *this=Other; +} + +MusicBrainz5::CTextRepresentation& MusicBrainz5::CTextRepresentation::operator =(const CTextRepresentation& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Language=Other.m_d->m_Language; + m_d->m_Script=Other.m_d->m_Script; + } + + return *this; +} + +MusicBrainz5::CTextRepresentation::~CTextRepresentation() +{ + delete m_d; +} + +MusicBrainz5::CTextRepresentation *MusicBrainz5::CTextRepresentation::Clone() +{ + return new CTextRepresentation(*this); +} + +void MusicBrainz5::CTextRepresentation::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised textrepresentation attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CTextRepresentation::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("language"==NodeName) + { + ProcessItem(Node,m_d->m_Language); + } + else if ("script"==NodeName) + { + ProcessItem(Node,m_d->m_Script); + } + else + { + std::cerr << "Unrecognised textrepresentation element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CTextRepresentation::GetElementName() +{ + return "text-representation"; +} + +std::string MusicBrainz5::CTextRepresentation::Language() const +{ + return m_d->m_Language; +} + +std::string MusicBrainz5::CTextRepresentation::Script() const +{ + return m_d->m_Script; +} + +std::ostream& MusicBrainz5::CTextRepresentation::Serialise(std::ostream& os) const +{ + os << "\tText Representation:" << std::endl; + + CEntity::Serialise(os); + + os << "\t\tLanguage: " << Language() << std::endl; + os << "\t\tScript: " << Script() << std::endl; + + return os; +} + diff --git a/src/Track.cc b/src/Track.cc new file mode 100644 index 0000000..a1b0730 --- /dev/null +++ b/src/Track.cc @@ -0,0 +1,212 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Track.h" + +#include "musicbrainz5/Recording.h" +#include "musicbrainz5/ArtistCredit.h" + +class MusicBrainz5::CTrackPrivate +{ + public: + CTrackPrivate() + : m_Position(0), + m_Recording(0), + m_Length(0), + m_ArtistCredit(0) + { + } + + int m_Position; + std::string m_Title; + CRecording *m_Recording; + int m_Length; + CArtistCredit *m_ArtistCredit; + std::string m_Number; +}; + +MusicBrainz5::CTrack::CTrack(const XMLNode& Node) +: CEntity(), + m_d(new CTrackPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Track node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CTrack::CTrack(const CTrack& Other) +: CEntity(), + m_d(new CTrackPrivate) +{ + *this=Other; +} + +MusicBrainz5::CTrack& MusicBrainz5::CTrack::operator =(const CTrack& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_Position=Other.m_d->m_Position; + m_d->m_Title=Other.m_d->m_Title; + + if (Other.m_d->m_Recording) + m_d->m_Recording=new CRecording(*Other.m_d->m_Recording); + + m_d->m_Length=Other.m_d->m_Length; + + if (Other.m_d->m_ArtistCredit) + m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); + + m_d->m_Number=Other.m_d->m_Number; + } + + return *this; +} + +MusicBrainz5::CTrack::~CTrack() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CTrack::Cleanup() +{ + delete m_d->m_Recording; + m_d->m_Recording=0; + + delete m_d->m_ArtistCredit; + m_d->m_ArtistCredit=0; +} + +MusicBrainz5::CTrack *MusicBrainz5::CTrack::Clone() +{ + return new CTrack(*this); +} + +void MusicBrainz5::CTrack::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised track attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CTrack::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("position"==NodeName) + { + ProcessItem(Node,m_d->m_Position); + } + else if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("recording"==NodeName) + { + ProcessItem(Node,m_d->m_Recording); + } + else if ("length"==NodeName) + { + ProcessItem(Node,m_d->m_Length); + } + else if ("artist-credit"==NodeName) + { + ProcessItem(Node,m_d->m_ArtistCredit); + } + else if ("number"==NodeName) + { + ProcessItem(Node,m_d->m_Number); + } + else + { + std::cerr << "Unrecognised track element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CTrack::GetElementName() +{ + return "track"; +} + +int MusicBrainz5::CTrack::Position() const +{ + return m_d->m_Position; +} + +std::string MusicBrainz5::CTrack::Title() const +{ + return m_d->m_Title; +} + +MusicBrainz5::CRecording *MusicBrainz5::CTrack::Recording() const +{ + return m_d->m_Recording; +} + +int MusicBrainz5::CTrack::Length() const +{ + return m_d->m_Length; +} + +MusicBrainz5::CArtistCredit *MusicBrainz5::CTrack::ArtistCredit() const +{ + return m_d->m_ArtistCredit; +} + +std::string MusicBrainz5::CTrack::Number() const +{ + return m_d->m_Number; +} + +std::ostream& MusicBrainz5::CTrack::Serialise(std::ostream& os) const +{ + os << "Track:" << std::endl; + + CEntity::Serialise(os); + + os << "\tPosition: " << Position() << std::endl; + os << "\tTitle: " << Title() << std::endl; + + if (Recording()) + os << *Recording() << std::endl; + + os << "\tLength: " << Length() << std::endl; + + if (ArtistCredit()) + os << *ArtistCredit() << std::endl; + + os << "\tNumber: " << Number() << std::endl; + + return os; +} diff --git a/src/UserRating.cc b/src/UserRating.cc new file mode 100644 index 0000000..8890786 --- /dev/null +++ b/src/UserRating.cc @@ -0,0 +1,119 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/UserRating.h" + +class MusicBrainz5::CUserRatingPrivate +{ + public: + CUserRatingPrivate() + : m_UserRating(0) + { + } + + int m_UserRating; +}; + +MusicBrainz5::CUserRating::CUserRating(const XMLNode& Node) +: CEntity(), + m_d(new CUserRatingPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "User rating node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + + if (Node.getText()) + { + ProcessItem(Node,m_d->m_UserRating); + } + } +} + +MusicBrainz5::CUserRating::CUserRating(const CUserRating& Other) +: CEntity(), + m_d(new CUserRatingPrivate) +{ + *this=Other; +} + +MusicBrainz5::CUserRating& MusicBrainz5::CUserRating::operator =(const CUserRating& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_UserRating=Other.m_d->m_UserRating; + } + + return *this; +} + +MusicBrainz5::CUserRating::~CUserRating() +{ + delete m_d; +} + +MusicBrainz5::CUserRating *MusicBrainz5::CUserRating::Clone() +{ + return new CUserRating(*this); +} + +void MusicBrainz5::CUserRating::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised userrating attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CUserRating::ParseElement(const XMLNode& Node) +{ + std::string Name=Node.getName(); + + std::cerr << "Unrecognised userrating element: '" << Name << "'" << std::endl; +} + +std::string MusicBrainz5::CUserRating::GetElementName() +{ + return "user-rating"; +} + +int MusicBrainz5::CUserRating::UserRating() const +{ + return m_d->m_UserRating; +} + +std::ostream& MusicBrainz5::CUserRating::Serialise(std::ostream& os) const +{ + os << "User rating:" << std::endl; + + CEntity::Serialise(os); + + os << "\tRating: " << UserRating() << std::endl; + + return os; +} diff --git a/src/UserTag.cc b/src/UserTag.cc new file mode 100644 index 0000000..157a31f --- /dev/null +++ b/src/UserTag.cc @@ -0,0 +1,116 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/UserTag.h" + +class MusicBrainz5::CUserTagPrivate +{ + public: + std::string m_Name; +}; + +MusicBrainz5::CUserTag::CUserTag(const XMLNode& Node) +: CEntity(), + m_d(new CUserTagPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "UserTag node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CUserTag::CUserTag(const CUserTag& Other) +: CEntity(), + m_d(new CUserTagPrivate) +{ + *this=Other; +} + +MusicBrainz5::CUserTag& MusicBrainz5::CUserTag::operator =(const CUserTag& Other) +{ + if (this!=&Other) + { + CEntity::operator =(Other); + + m_d->m_Name=Other.m_d->m_Name; + } + + return *this; +} + +MusicBrainz5::CUserTag::~CUserTag() +{ + delete m_d; +} + +MusicBrainz5::CUserTag *MusicBrainz5::CUserTag::Clone() +{ + return new CUserTag(*this); +} + +void MusicBrainz5::CUserTag::ParseAttribute(const std::string& Name, const std::string& /*Value*/) +{ + std::cerr << "Unrecognised usertag attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CUserTag::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("name"==NodeName) + { + ProcessItem(Node,m_d->m_Name); + } + else + { + std::cerr << "Unrecognised UserTag element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CUserTag::GetElementName() +{ + return "user-tag"; +} + +std::string MusicBrainz5::CUserTag::Name() const +{ + return m_d->m_Name; +} + +std::ostream& MusicBrainz5::CUserTag::Serialise(std::ostream& os) const +{ + os << "UserTag:" << std::endl; + + CEntity::Serialise(os); + + os << "\tName: " << Name() << std::endl; + + return os; +} diff --git a/src/Work.cc b/src/Work.cc new file mode 100644 index 0000000..3dd8683 --- /dev/null +++ b/src/Work.cc @@ -0,0 +1,351 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Work.h" + +#include "musicbrainz5/ArtistCredit.h" +#include "musicbrainz5/AliasList.h" +#include "musicbrainz5/Alias.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/Tag.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/UserTag.h" +#include "musicbrainz5/Rating.h" +#include "musicbrainz5/UserRating.h" +#include "musicbrainz5/ISWC.h" +#include "musicbrainz5/ISWCList.h" + +class MusicBrainz5::CWorkPrivate +{ + public: + CWorkPrivate() + : m_ArtistCredit(0), + m_ISWCList(0), + m_AliasList(0), + m_RelationListList(0), + m_TagList(0), + m_UserTagList(0), + m_Rating(0), + m_UserRating(0) + { + } + + std::string m_ID; + std::string m_Type; + std::string m_Title; + CArtistCredit *m_ArtistCredit; + CISWCList *m_ISWCList; + std::string m_Disambiguation; + CAliasList *m_AliasList; + CRelationListList *m_RelationListList; + CTagList *m_TagList; + CUserTagList *m_UserTagList; + CRating *m_Rating; + CUserRating *m_UserRating; + std::string m_Language; +}; + +MusicBrainz5::CWork::CWork(const XMLNode& Node) +: CEntity(), + m_d(new CWorkPrivate) +{ + if (!Node.isEmpty()) + { + //std::cout << "Work node: " << std::endl << Node.createXMLString(true) << std::endl; + + Parse(Node); + } +} + +MusicBrainz5::CWork::CWork(const CWork& Other) +: CEntity(), + m_d(new CWorkPrivate) +{ + *this=Other; +} + +MusicBrainz5::CWork& MusicBrainz5::CWork::operator =(const CWork& Other) +{ + if (this!=&Other) + { + Cleanup(); + + CEntity::operator =(Other); + + m_d->m_ID=Other.m_d->m_ID; + m_d->m_Type=Other.m_d->m_Type; + m_d->m_Title=Other.m_d->m_Title; + + if (Other.m_d->m_ArtistCredit) + m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); + + if (Other.m_d->m_ISWCList) + m_d->m_ISWCList=new CISWCList(*Other.m_d->m_ISWCList); + + m_d->m_Disambiguation=Other.m_d->m_Disambiguation; + + if (Other.m_d->m_AliasList) + m_d->m_AliasList=new CAliasList(*Other.m_d->m_AliasList); + + if (Other.m_d->m_RelationListList) + m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); + + if (Other.m_d->m_TagList) + m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); + + if (Other.m_d->m_UserTagList) + m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); + + if (Other.m_d->m_Rating) + m_d->m_Rating=new CRating(*Other.m_d->m_Rating); + + if (Other.m_d->m_UserRating) + m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); + + m_d->m_Language=Other.m_d->m_Language; + } + + return *this; +} + +MusicBrainz5::CWork::~CWork() +{ + Cleanup(); + + delete m_d; +} + +void MusicBrainz5::CWork::Cleanup() +{ + delete m_d->m_ArtistCredit; + m_d->m_ArtistCredit=0; + + delete m_d->m_ISWCList; + m_d->m_ISWCList=0; + + delete m_d->m_AliasList; + m_d->m_AliasList=0; + + delete m_d->m_RelationListList; + m_d->m_RelationListList=0; + + delete m_d->m_TagList; + m_d->m_TagList=0; + + delete m_d->m_UserTagList; + m_d->m_UserTagList=0; + + delete m_d->m_Rating; + m_d->m_Rating=0; + + delete m_d->m_UserRating; + m_d->m_UserRating=0; +} + +MusicBrainz5::CWork *MusicBrainz5::CWork::Clone() +{ + return new CWork(*this); +} + +void MusicBrainz5::CWork::ParseAttribute(const std::string& Name, const std::string& Value) +{ + if ("id"==Name) + m_d->m_ID=Value; + else if ("type"==Name) + m_d->m_Type=Value; + else + std::cerr << "Unrecognised work attribute: '" << Name << "'" << std::endl; +} + +void MusicBrainz5::CWork::ParseElement(const XMLNode& Node) +{ + std::string NodeName=Node.getName(); + + if ("title"==NodeName) + { + ProcessItem(Node,m_d->m_Title); + } + else if ("artist-credit"==NodeName) + { + ProcessItem(Node,m_d->m_ArtistCredit); + } + else if ("iswc-list"==NodeName) + { + ProcessItem(Node,m_d->m_ISWCList); + } + else if ("disambiguation"==NodeName) + { + ProcessItem(Node,m_d->m_Disambiguation); + } + else if ("alias-list"==NodeName) + { + ProcessItem(Node,m_d->m_AliasList); + } + else if ("relation-list"==NodeName) + { + ProcessRelationList(Node,m_d->m_RelationListList); + } + else if ("tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_TagList); + } + else if ("user-tag-list"==NodeName) + { + ProcessItem(Node,m_d->m_UserTagList); + } + else if ("rating"==NodeName) + { + ProcessItem(Node,m_d->m_Rating); + } + else if ("user-rating"==NodeName) + { + ProcessItem(Node,m_d->m_UserRating); + } + else if ("language"==NodeName) + { + ProcessItem(Node,m_d->m_Language); + } + else + { + std::cerr << "Unrecognised work element: '" << NodeName << "'" << std::endl; + } +} + +std::string MusicBrainz5::CWork::GetElementName() +{ + return "work"; +} + +std::string MusicBrainz5::CWork::ID() const +{ + return m_d->m_ID; +} + +std::string MusicBrainz5::CWork::Type() const +{ + return m_d->m_Type; +} + +std::string MusicBrainz5::CWork::Title() const +{ + return m_d->m_Title; +} + +MusicBrainz5::CArtistCredit *MusicBrainz5::CWork::ArtistCredit() const +{ + return m_d->m_ArtistCredit; +} + +MusicBrainz5::CISWCList *MusicBrainz5::CWork::ISWCList() const +{ + return m_d->m_ISWCList; +} + +std::string MusicBrainz5::CWork::Disambiguation() const +{ + return m_d->m_Disambiguation; +} + +MusicBrainz5::CAliasList *MusicBrainz5::CWork::AliasList() const +{ + return m_d->m_AliasList; +} + +MusicBrainz5::CRelationListList *MusicBrainz5::CWork::RelationListList() const +{ + return m_d->m_RelationListList; +} + +MusicBrainz5::CTagList *MusicBrainz5::CWork::TagList() const +{ + return m_d->m_TagList; +} + +MusicBrainz5::CUserTagList *MusicBrainz5::CWork::UserTagList() const +{ + return m_d->m_UserTagList; +} + +MusicBrainz5::CRating *MusicBrainz5::CWork::Rating() const +{ + return m_d->m_Rating; +} + +MusicBrainz5::CUserRating *MusicBrainz5::CWork::UserRating() const +{ + return m_d->m_UserRating; +} + +std::string MusicBrainz5::CWork::Language() const +{ + return m_d->m_Language; +} + +std::ostream& MusicBrainz5::CWork::Serialise(std::ostream& os) const +{ + os << "Work:" << std::endl; + + CEntity::Serialise(os); + + os << "\tID: " << ID() << std::endl; + os << "\tWork: " << Type() << std::endl; + os << "\tTitle: " << Title() << std::endl; + + if (ArtistCredit()) + os << *ArtistCredit() << std::endl; + + if (ISWCList()) + os << *ISWCList() << std::endl; + + os << "\tDisambiguation: " << Disambiguation() << std::endl; + + if (AliasList()) + os << *AliasList() << std::endl; + + if (RelationListList()) + os << *RelationListList() << std::endl; + + if (TagList()) + os << *TagList() << std::endl; + + if (UserTagList()) + os << *UserTagList() << std::endl; + + if (Rating()) + os << *Rating() << std::endl; + + if (UserRating()) + os << *UserRating() << std::endl; + + os << "\tLanguage: " << Language() << std::endl; + + return os; +} + diff --git a/src/c-int-medium-defines.inc b/src/c-int-medium-defines.inc new file mode 100644 index 0000000..b3c438a --- /dev/null +++ b/src/c-int-medium-defines.inc @@ -0,0 +1,34 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +/** + * @see MusicBrainz5::CMedium::ContainsDiscID + * + * @param Medium #Mb5Medium object + * @param DiscID DiscID to check + * + * @return 1 if DiscID found, 0 otherwise + */ + unsigned char mb5_medium_contains_discid(Mb5Medium Medium, const char *DiscID); diff --git a/src/c-int-medium-source.inc b/src/c-int-medium-source.inc new file mode 100644 index 0000000..ceed53b --- /dev/null +++ b/src/c-int-medium-source.inc @@ -0,0 +1,38 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +unsigned char mb5_medium_contains_discid(Mb5Medium Medium, const char *DiscID) +{ + unsigned char Ret=0; + + if (Medium) + { + MusicBrainz5::CMedium *TheMedium=reinterpret_cast(Medium); + if (TheMedium) + Ret=TheMedium->ContainsDiscID(DiscID); + } + + return Ret; +} diff --git a/src/c-int-query-defines.inc b/src/c-int-query-defines.inc new file mode 100644 index 0000000..e9e3b84 --- /dev/null +++ b/src/c-int-query-defines.inc @@ -0,0 +1,196 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +/** + * Create a new instance of #Mb5Query. + * + * @see MusicBrainz5::CQuery::CQuery + * + * @param UserAgent User agent to be passed to submissions + * @param Server Server to use, pass null to use the default server + * @param Port Port to use, pass 0 to use the default port + * + * @return The newly created #Mb5Query object. This object must be deleted once + * finished with. + */ + + Mb5Query mb5_query_new(const char *UserAgent, const char *Server, int Port); + +/** + * Set the username for authenticating to MusicBrainz + * + * @see MusicBrainz5::CQuery::SetUserName + * + * @param Query #Mb5Query object + * @param UserName Username to use + */ + void mb5_query_set_username(Mb5Query Query, const char *UserName); + +/** + * Set the password for authenticating to MusicBrainz + * + * @see MusicBrainz5::CQuery::SetPassword + * + * @param Query #Mb5Query object + * @param Password Password to use + */ + void mb5_query_set_password(Mb5Query Query, const char *Password); + +/** + * Set the proxy server + * + * @see MusicBrainz5::CQuery::SetProxyHost + * + * @param Query #Mb5Query object + * @param ProxyHost Proxy server to use + */ + void mb5_query_set_proxyhost(Mb5Query Query, const char *ProxyHost); + +/** + * Set the port to use on the proxy server + * + * @see MusicBrainz5::CQuery::SetProxyPort + * + * @param Query #Mb5Query object + * @param ProxyPort Port to use on proxy server + */ + void mb5_query_set_proxyport(Mb5Query Query, int ProxyPort); + +/** + * Set the username to use to authenticate to the proxy server + * + * @see MusicBrainz5::CQuery::SetProxyUserName + * + * @param Query #Mb5Query object + * @param ProxyUserName User name to use + */ + void mb5_query_set_proxyusername(Mb5Query Query, const char *ProxyUserName); + +/** + * Set the password to use to authenticate to the proxy server + * + * @see MusicBrainz5::CQuery::SetProxyPassword + * + * @param Query #Mb5Query object + * @param ProxyPassword Password to use + */ + void mb5_query_set_proxypassword(Mb5Query Query, const char *ProxyPassword); + +/** + * Return a list of releases that match the specified Disc ID + * + * @see MusicBrainz5::CQuery::LookupDiscID + * + * @param Query #Mb5Query object + * @param DiscID DiscID to lookup + * + * @return A #Mb5ReleaseList object. This object must be deleted once + * finished with. + */ + Mb5ReleaseList mb5_query_lookup_discid(Mb5Query Query, const char *DiscID); + +/** + * Return full information about a specific release + * + * @see MusicBrainz5::CQuery::LookupRelease + * + * @param Query #Mb5Query object + * @param Release Release to return information for + * + * @return A #Mb5Release object. This object must be deleted once + * finished with. + */ + Mb5Release mb5_query_lookup_release(Mb5Query Query, const char *Release); + +/** + * Perform a generic query + * + * @see MusicBrainz5::CQuery::Query + * + * @param Query #Mb5Query object + * @param Entity The entity to query + * @param ID The ID to query + * @param Resource The resource to query + * @param NumParams The number of parameters in the following arrays + * @param ParamNames Array of strings containing parameter names + * @param ParamValues Array of space seperated parameter values + * + * @return A #Mb5Metadata object. This object must be deleted once + * finished with. + */ + Mb5Metadata mb5_query_query(Mb5Query Query, const char *Entity, const char *ID, const char *Resource, int NumParams, char **ParamNames, char **ParamValues); + +/** + * Add a list of releases to a collection + * + * @see MusicBrainz5::CQuery::AddCollectionEntries + * + * @param Query #Mb5Query object + * @param Collection ID of collection to add releases to + * @param NumEntries The number of entries to add + * @param Entries Array of strings of release IDs to add + * + * @return 0 on failure, 1 on success + */ + unsigned char mb5_query_add_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries); + +/** + * Delete a list of releases from a collection + * + * @see MusicBrainz5::CQuery::AddCollectionEntries + * + * @param Query #Mb5Query object + * @param Collection ID of collection to delete releases from + * @param NumEntries The number of entries to delete + * @param Entries Array of strings of release IDs to delete + * + * @return 0 on failure, 1 on success + */ + unsigned char mb5_query_delete_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries); + +/** + * @see MusicBrainz5::CQuery::tQueryResult + */ + + typedef enum + { + eQuery_Success=0, + eQuery_ConnectionError, + eQuery_Timeout, + eQuery_AuthenticationError, + eQuery_FetchError, + eQuery_RequestError, + eQuery_ResourceNotFound + } tQueryResult; + +/** + * @see MusicBrainz5::CQuery::LastResult + * + * @param Query #Mb5Query object + * + * @return Last query result code + */ + tQueryResult mb5_query_get_lastresult(Mb5Query Query); + diff --git a/src/c-int-query-source.inc b/src/c-int-query-source.inc new file mode 100644 index 0000000..166a900 --- /dev/null +++ b/src/c-int-query-source.inc @@ -0,0 +1,184 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +Mb5Query mb5_query_new(const char *UserAgent, const char *Server, int Port) +{ + return new MusicBrainz5::CQuery(UserAgent, Server ? Server : "musicbrainz.org", Port!=0 ? Port : 80); +} + +MB5_C_STR_SETTER(Query,query,UserName,username) +MB5_C_STR_SETTER(Query,query,Password,password) +MB5_C_STR_SETTER(Query,query,ProxyHost,proxyhost) +MB5_C_INT_SETTER(Query,query,ProxyPort,proxyport) +MB5_C_STR_SETTER(Query,query,ProxyUserName,proxyusername) +MB5_C_STR_SETTER(Query,query,ProxyPassword,proxypassword) + +Mb5ReleaseList mb5_query_lookup_discid(Mb5Query Query, const char *DiscID) +{ + if (Query) + { + try + { + MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); + if (TheQuery) + return new MusicBrainz5::CReleaseList(TheQuery->LookupDiscID(DiscID)); + } + + catch(...) + { + } + } + + return 0; +} + +Mb5Release mb5_query_lookup_release(Mb5Query Query, const char *Release) +{ + if (Query) + { + try + { + MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); + if (TheQuery) + return new MusicBrainz5::CRelease(TheQuery->LookupRelease(Release)); + } + + catch(...) + { + } + } + + return 0; +} + +Mb5Metadata mb5_query_query(Mb5Query Query, const char *Entity, const char *ID, const char *Resource, int NumParams, char **ParamName, char **ParamValue) +{ + if (Query) + { + try + { + MusicBrainz5::CQuery::tParamMap Params; + + for (int count=0;count(Query); + if (TheQuery) + return new MusicBrainz5::CMetadata(TheQuery->Query(Entity?Entity:"", + ID?ID:"", + Resource?Resource:"", + Params)); + } + + catch(...) + { + } + } + + return 0; +} + +unsigned char mb5_query_add_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries) +{ + if (Query) + { + try + { + std::vector VecEntries; + + MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); + if (TheQuery) + { + for (int count=0;countAddCollectionEntries(Collection,VecEntries)?1:0; + } + } + + catch(...) + { + } + } + + return 0; +} + +unsigned char mb5_query_delete_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries) +{ + if (Query) + { + try + { + std::vector VecEntries; + + MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); + if (TheQuery) + { + for (int count=0;countAddCollectionEntries(Collection,VecEntries)?1:0; + } + } + + catch(...) + { + } + } + + return 0; +} + +tQueryResult mb5_query_get_lastresult(Mb5Query o) +{ + if (o) + { + try + { + return (tQueryResult)((MusicBrainz5::CQuery *)o)->LastResult(); + } + + catch (...) + { + } + } + + return eQuery_FetchError; +} + diff --git a/src/c-int-release-defines.inc b/src/c-int-release-defines.inc new file mode 100644 index 0000000..d540dfc --- /dev/null +++ b/src/c-int-release-defines.inc @@ -0,0 +1,36 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +/** + * @see MusicBrainz5::CRelease::MediaMatchingDiscID + * + * @param Release #Mb5Release object + * @param DiscID DiscID to match + * + * @return #Mb5MediumList. This object must be deleted once + * finished with. + */ + Mb5MediumList mb5_release_media_matching_discid(Mb5Release Release, const char *DiscID); + diff --git a/src/c-int-release-source.inc b/src/c-int-release-source.inc new file mode 100644 index 0000000..636fcad --- /dev/null +++ b/src/c-int-release-source.inc @@ -0,0 +1,37 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +Mb5MediumList mb5_release_media_matching_discid(Mb5Release Release, const char *DiscID) +{ + if (Release) + { + MusicBrainz5::CRelease *TheRelease=reinterpret_cast(Release); + if (TheRelease) + return new MusicBrainz5::CMediumList(TheRelease->MediaMatchingDiscID(DiscID)); + } + + return 0; +} + diff --git a/src/c-int-source-funcs.inc b/src/c-int-source-funcs.inc new file mode 100644 index 0000000..fdf2d56 --- /dev/null +++ b/src/c-int-source-funcs.inc @@ -0,0 +1,379 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/Query.h" + +#include "musicbrainz5/mb5_c.h" + +#include + +#include "musicbrainz5/Alias.h" +#include "musicbrainz5/AliasList.h" +#include "musicbrainz5/Annotation.h" +#include "musicbrainz5/AnnotationList.h" +#include "musicbrainz5/Artist.h" +#include "musicbrainz5/ArtistList.h" +#include "musicbrainz5/ArtistCredit.h" +#include "musicbrainz5/Attribute.h" +#include "musicbrainz5/AttributeList.h" +#include "musicbrainz5/CDStub.h" +#include "musicbrainz5/CDStubList.h" +#include "musicbrainz5/Collection.h" +#include "musicbrainz5/CollectionList.h" +#include "musicbrainz5/Disc.h" +#include "musicbrainz5/DiscList.h" +#include "musicbrainz5/FreeDBDisc.h" +#include "musicbrainz5/FreeDBDiscList.h" +#include "musicbrainz5/IPI.h" +#include "musicbrainz5/ISRC.h" +#include "musicbrainz5/ISRCList.h" +#include "musicbrainz5/ISWC.h" +#include "musicbrainz5/ISWCList.h" +#include "musicbrainz5/Label.h" +#include "musicbrainz5/LabelList.h" +#include "musicbrainz5/LabelInfo.h" +#include "musicbrainz5/LabelInfoList.h" +#include "musicbrainz5/Lifespan.h" +#include "musicbrainz5/Medium.h" +#include "musicbrainz5/MediumList.h" +#include "musicbrainz5/Message.h" +#include "musicbrainz5/Metadata.h" +#include "musicbrainz5/NameCredit.h" +#include "musicbrainz5/NameCreditList.h" +#include "musicbrainz5/NonMBTrack.h" +#include "musicbrainz5/NonMBTrackList.h" +#include "musicbrainz5/PUID.h" +#include "musicbrainz5/PUIDList.h" +#include "musicbrainz5/Rating.h" +#include "musicbrainz5/Recording.h" +#include "musicbrainz5/RecordingList.h" +#include "musicbrainz5/Relation.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/ReleaseGroup.h" +#include "musicbrainz5/ReleaseGroupList.h" +#include "musicbrainz5/SecondaryType.h" +#include "musicbrainz5/SecondaryTypeList.h" +#include "musicbrainz5/Tag.h" +#include "musicbrainz5/TagList.h" +#include "musicbrainz5/TextRepresentation.h" +#include "musicbrainz5/Track.h" +#include "musicbrainz5/TrackList.h" +#include "musicbrainz5/UserRating.h" +#include "musicbrainz5/UserTag.h" +#include "musicbrainz5/UserTagList.h" +#include "musicbrainz5/Work.h" +#include "musicbrainz5/WorkList.h" + +std::string GetMapName(std::map Map, int Item) +{ + std::string Ret; + + if (Item<(int)Map.size()) + { + std::map::const_iterator ThisItem=Map.begin(); + + int count=0; + + while (count Map, int Item) +{ + std::string Ret; + + if (Item<(int)Map.size()) + { + std::map::const_iterator ThisItem=Map.begin(); + + int count=0; + + while (countSet##PROP1(str); \ + } \ + catch (...) { \ + } \ + } \ + } + +#define MB5_C_INT_SETTER(TYPE1, TYPE2, PROP1, PROP2) \ + void \ + mb5_##TYPE2##_set_##PROP2(Mb5##TYPE1 o, int i) \ + { \ + if (o) \ + { \ + try { \ + ((MusicBrainz5::C##TYPE1 *)o)->Set##PROP1(i); \ + } \ + catch (...) { \ + } \ + } \ + } + +#define MB5_C_STR_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ + int \ + mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o, char *str, int len) \ + { \ + int ret=0; \ + if (str) \ + *str=0; \ + if (o) \ + { \ + try { \ + ret=((MusicBrainz5::C##TYPE1 *)o)->PROP1().length(); \ + if (str && len) \ + { \ + strncpy(str, ((MusicBrainz5::C##TYPE1 *)o)->PROP1().c_str(), len); \ + str[len-1]='\0'; \ + } \ + } \ + catch (...) { \ + str[0] = '\0'; \ + } \ + } \ + return ret; \ + } + +#define MB5_C_INT_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ + int \ + mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o) \ + { \ + if (o) \ + { \ + try { \ + return ((MusicBrainz5::C##TYPE1 *)o)->PROP1(); \ + } \ + catch (...) { \ + } \ + } \ + return 0; \ + } + +#define MB5_C_DOUBLE_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ + double \ + mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o) \ + { \ + if (o) \ + { \ + try { \ + return ((MusicBrainz5::C##TYPE1 *)o)->PROP1(); \ + } \ + catch (...) { \ + } \ + } \ + return 0; \ + } + +#define MB5_C_BOOL_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ + unsigned char \ + mb5_##TYPE2##_get_##PROP2(Mb##TYPE1 o) \ + { \ + if (o) \ + { \ + try { \ + return ((TYPE1 *)o)->PROP1() ? 1 : 0; \ + } \ + catch (...) { \ + return 0; \ + } \ + } \ + } + +#define MB5_C_OBJ_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ + Mb5##PROP1 \ + mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o) \ + { \ + if (o) \ + { \ + try { \ + return (Mb5##PROP1)((MusicBrainz5::C##TYPE1 *)o)->PROP1(); \ + } \ + catch (...) { \ + } \ + } \ + return (Mb5##PROP1)0; \ + } + +#define MB5_C_LIST_GETTER(TYPE1, TYPE2) \ + void \ + mb5_##TYPE2##_list_delete(Mb5##TYPE1 o) \ + { \ + delete (MusicBrainz5::C##TYPE1##List *)o; \ + } \ + int \ + mb5_##TYPE2##_list_size(Mb5##TYPE1##List List) \ + { \ + if (List) \ + { \ + try { \ + return ((MusicBrainz5::C##TYPE1##List *)List)->NumItems(); \ + } \ + catch (...) { \ + return 0; \ + } \ + } \ + return 0; \ + } \ + \ + Mb5##TYPE1 \ + mb5_##TYPE2##_list_item(Mb5##TYPE1##List List, int Item) \ + { \ + if (List) \ + { \ + try { \ + return ((MusicBrainz5::C##TYPE1##List *)List)->Item(Item); \ + } \ + catch (...) { \ + return (Mb5##TYPE1)0; \ + } \ + } \ + return (Mb5##TYPE1)0; \ + } \ + int \ + mb5_##TYPE2##_list_get_count(Mb5##TYPE1##List List) \ + { \ + if (List) \ + { \ + try { \ + return ((MusicBrainz5::C##TYPE1##List *)List)->Count(); \ + } \ + catch (...) { \ + return 0; \ + } \ + } \ + return 0; \ + } \ + \ + int \ + mb5_##TYPE2##_list_get_offset(Mb5##TYPE1##List List) \ + { \ + if (List) \ + { \ + try { \ + return ((MusicBrainz5::C##TYPE1##List *)List)->Offset(); \ + } \ + catch (...) { \ + return 0; \ + } \ + } \ + return 0; \ + } \ + \ + +#define MB5_C_EXT_GETTER(PROP1, PROP2) \ + int \ + mb5_entity_ext_##PROP2##s_size(Mb5Entity o) \ + { \ + if (o) \ + { \ + return ((MusicBrainz5::CEntity *)o)->Ext##PROP1##s().size(); \ + } \ + return 0; \ + } \ + int \ + mb5_entity_ext_##PROP2##_name(Mb5Entity o, int Item, char *str, int len) \ + { \ + int ret=0; \ + if (str) \ + *str=0; \ + if (o) \ + { \ + std::map Items=((MusicBrainz5::CEntity *)o)->Ext##PROP1##s(); \ + std::string Name=GetMapName(Items,Item); \ + ret=Name.length(); \ + if (str && len) \ + { \ + strncpy(str, Name.c_str(), len); \ + str[len-1]='\0'; \ + } \ + } \ + return ret; \ + } \ + int \ + mb5_entity_ext_##PROP2##_value(Mb5Entity o, int Item, char *str, int len) \ + { \ + int ret=0; \ + if (str) \ + *str=0; \ + if (o) \ + { \ + std::map Items=((MusicBrainz5::CEntity *)o)->Ext##PROP1##s(); \ + std::string Name=GetMapValue(Items,Item); \ + ret=Name.length(); \ + if (str && len) \ + { \ + strncpy(str, Name.c_str(), len); \ + str[len-1]='\0'; \ + } \ + } \ + return ret; \ + } \ + diff --git a/src/cinterface.xml b/src/cinterface.xml new file mode 100644 index 0000000..622b495 --- /dev/null +++ b/src/cinterface.xml @@ -0,0 +1,379 @@ + + + +
+ +/* + Things you should delete using the appropriate mb5_xxx_delete() function: + + * The query object you create to do the actual work + * Any object or list returned from one of the mb5_query_xxx() functions + * The return from mb5_release_media_matching_discid() function + * The return from any mb5_xxx_clone() function + + Everything else remains managed by the library, and should not be deleted + + If in doubt, valgrind is a useful way to spot leaks or things being deleted + when they shouldn't be. + +*/ + +#ifndef _MUSICBRAINZ5_MB_C_H +#define _MUSICBRAINZ5_MB_C_H + +#include "musicbrainz5/defines.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/src/make-c-interface.cc b/src/make-c-interface.cc new file mode 100644 index 0000000..e88a931 --- /dev/null +++ b/src/make-c-interface.cc @@ -0,0 +1,686 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "musicbrainz5/xmlParser.h" + +void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include, const std::string& Path); +void ProcessHeader(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); +void ProcessEntity(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); +void ProcessClass(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); +void ProcessList(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); +void ProcessDeclare(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); + +int main(int argc, const char *argv[]) +{ + for (int count=0;countisEmpty()) + { + std::cout << "Generating '" << argv[3] << "/" << argv[4] << "' and '" << argv[3] << "/" << argv[5] << "'" << std::endl; + + std::string IncludeName=std::string(argv[3])+"/"+argv[5]; + std::ofstream Include(IncludeName.c_str()); + + std::string SourceName=std::string(argv[3])+"/" + argv[4]; + std::ofstream Source(SourceName.c_str()); + + if (!Include.is_open()) + { + std::cerr << "Error opening '" << IncludeName << "'" << std::endl; + return 1; + } + + if (!Source.is_open()) + { + std::cerr << "Error opening '" << SourceName << "'" << std::endl; + return 1; + } + + for (XMLNode Node = TopNode->getChildNode(); + !Node.isEmpty(); + Node = Node.next()) + { + std::string Name=Node.getName(); + + if ("boilerplate"==Name) + ProcessBoilerplate(Node,Source,Include,argv[1]); + else if ("header"==Name) + ProcessHeader(Node,Source,Include); + else if ("declare"==Name) + ProcessDeclare(*TopNode,Source,Include); + else if ("entity"==Name) + ProcessEntity(Node,Source,Include); + else if ("class"==Name) + ProcessClass(Node,Source,Include); + else if ("list"==Name) + ProcessList(Node,Source,Include); + else + { + std::cerr << "Unrecognised item " << Name << std::endl; + return 1; + } + } + } + else + { + std::cerr << "Error reading XML: " << Results.message << " at line " << Results.line << std::endl; + return 1; + } + if (TopNode != NULL) + delete TopNode; + } + + return 0; +} + +std::ofstream *GetFile(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include) +{ + std::ofstream *File=&Source; + + if (Node.isAttributeSet("target")) + { + std::string Target=Node.getAttribute("target").value(); + if ("source"==Target) + File=&Source; + else if ("include"==Target) + File=&Include; + } + + return File; +} + +void ProcessHeader(const XMLNode& /*Node*/, std::ofstream& Source, std::ofstream& Include) +{ + std::stringstream os; + os << "/* --------------------------------------------------------------------------" << std::endl; + os << std::endl; + os << " libmusicbrainz5 - Client library to access MusicBrainz" << std::endl; + os << std::endl; + os << " Copyright (C) 2012 Andrew Hawkins" << std::endl; + os << std::endl; + os << " This file is part of libmusicbrainz5." << std::endl; + os << std::endl; + os << " This library is free software; you can redistribute it and/or" << std::endl; + os << " modify it under the terms of the GNU Lesser General Public" << std::endl; + os << " License as published by the Free Software Foundation; either" << std::endl; + os << " version 2.1 of the License, or (at your option) any later version." << std::endl; + os << std::endl; + os << " libmusicbrainz5 is distributed in the hope that it will be useful," << std::endl; + os << " but WITHOUT ANY WARRANTY; without even the implied warranty of" << std::endl; + os << " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" << std::endl; + os << " Lesser General Public License for more details." << std::endl; + os << std::endl; + os << " You should have received a copy of the GNU General Public License" << std::endl; + os << " along with this library. If not, see ." << std::endl; + os << std::endl; + os << " THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT IT!" << std::endl; + os << std::endl; + os << "----------------------------------------------------------------------------*/" << std::endl; + os << std::endl; + + Source << os.str() << std::endl; + Include << os.str() << std::endl; +} + +void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include, const std::string& Path) +{ + std::ofstream *File=GetFile(Node,Source,Include); + + if (Node.isAttributeSet("file")) + { + std::string FileName=Path+"/"+Node.getAttribute("file").value(); + std::ifstream InFile(FileName.c_str()); + if (InFile.is_open()) + *File << InFile.rdbuf() << std::endl; + else + { + std::cerr << "Error opening include file '" << FileName << "'" << std::endl; + exit(1); + } + } + else if (Node.getText()) + { + *File << Node.getText() << std::endl; + } + + *File << std::endl; +} + +void ProcessEntity(const XMLNode& /*Node*/, std::ofstream& Source, std::ofstream& Include) +{ + Include << "/**" << std::endl; + Include << " * Returns the number of extension attributes for the entity" << std::endl; + Include << " *" << std::endl; + Include << " * @param Entity #Mb5Entity object" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_entity_ext_attributes_size(Mb5Entity Entity);" << std::endl; + Include << std::endl; + + Include << "/**" << std::endl; + Include << " * Returns the name of the requested extension attribute" << std::endl; + Include << " *" << std::endl; + Include << " * @param Entity #Mb5Entity object" << std::endl; + Include << " * @param Item Item to return" << std::endl; + Include << " * @param str Returned string" << std::endl; + Include << " * @param len Number of characters available in return string" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_entity_ext_attribute_name(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; + Include << std::endl; + + Include << "/**" << std::endl; + Include << " * Returns the value of the requested extension attribute" << std::endl; + Include << " *" << std::endl; + Include << " * @param Entity #Mb5Entity object" << std::endl; + Include << " * @param Item Item to return" << std::endl; + Include << " * @param str Returned string" << std::endl; + Include << " * @param len Number of characters available in return string" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_entity_ext_attribute_value(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; + Include << std::endl; + + Include << "/**" << std::endl; + Include << " * Returns the number of extension elements for the entity" << std::endl; + Include << " *" << std::endl; + Include << " * @param Entity #Mb5Entity object" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_entity_ext_elements_size(Mb5Entity Entity);" << std::endl; + Include << std::endl; + + Include << "/**" << std::endl; + Include << " * Returns the name of the requested extension element" << std::endl; + Include << " *" << std::endl; + Include << " * @param Entity #Mb5Entity object" << std::endl; + Include << " * @param Item Item to return" << std::endl; + Include << " * @param str Returned string" << std::endl; + Include << " * @param len Number of characters available in return string" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_entity_ext_element_name(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; + Include << std::endl; + + Include << "/**" << std::endl; + Include << " * Returns the value of the requested extension element" << std::endl; + Include << " *" << std::endl; + Include << " * @param Entity #Mb5Entity object" << std::endl; + Include << " * @param Item Item to return" << std::endl; + Include << " * @param str Returned string" << std::endl; + Include << " * @param len Number of characters available in return string" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_entity_ext_element_value(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; + Include << std::endl; + + Source << " MB5_C_EXT_GETTER(Attribute,attribute)" << std::endl; + Source << " MB5_C_EXT_GETTER(Element,element)" << std::endl; + Source << std::endl; +} + +void ProcessClass(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include) +{ + if (Node.isAttributeSet("name")) + { + std::string LowerName=Node.getAttribute("name").value(); + + std::string UpperName=LowerName; + if (Node.isAttributeSet("uppername")) + UpperName=Node.getAttribute("uppername").value(); + else + UpperName[0]=toupper(UpperName[0]); + + Include << "/**" << std::endl; + Include << "* Delete an #Mb5" << UpperName << " object" << std::endl; + Include << "*" << std::endl; + Include << "* @param " << UpperName << " Object to delete" << std::endl; + Include << "*/" << std::endl; + Include << " void mb5_" << LowerName << "_delete(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_DELETE(" << UpperName << "," << LowerName << ")" << std::endl; + + Include << "/**" << std::endl; + Include << "* Clone an #Mb5" << UpperName << " object" << std::endl; + Include << "*" << std::endl; + Include << "* @param " << UpperName << " Object to clone" << std::endl; + Include << "*" << std::endl; + Include << "* @return Cloned object. This object must be deleted once" << std::endl; + Include << "* finished with." << std::endl; + Include << "*/" << std::endl; + Include << " Mb5" << UpperName << " mb5_" << LowerName << "_clone(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_CLONE(" << UpperName << "," << LowerName << ")" << std::endl; + + for (XMLNode ChildNode = Node.getChildNode(); + !ChildNode.isEmpty(); + ChildNode = ChildNode.next()) + { + std::string Name=ChildNode.getName(); + + if ("property"==Name) + { + if (ChildNode.isAttributeSet("name") && ChildNode.isAttributeSet("type")) + { + std::string PropertyLowerName=ChildNode.getAttribute("name").value(); + + std::string PropertyUpperName=PropertyLowerName; + if (ChildNode.isAttributeSet("uppername")) + PropertyUpperName=ChildNode.getAttribute("uppername").value(); + else + PropertyUpperName[0]=toupper(PropertyUpperName[0]); + + std::string PropertyType=ChildNode.getAttribute("type").value(); + + if ("string"==PropertyType) + { + bool Deprecated=false; + std::string Replacement; + + if (ChildNode.isAttributeSet("deprecated")) + { + std::string StrDeprecated=ChildNode.getAttribute("deprecated").value(); + + if (StrDeprecated=="true") + Deprecated=true; + + if (ChildNode.isAttributeSet("replacement")) + Replacement=ChildNode.getAttribute("replacement").value(); + } + + Include << "/**" << std::endl; + Include << " * "; + if (Deprecated) + Include << "@deprecated "; + + Include << "@see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + + if (Deprecated) + { + Include << " * This method is deprecated, please use #" << Replacement << "" << std::endl; + Include << " *" << std::endl; + } + + Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; + Include << " * @param str Returned string" << std::endl; + Include << " * @param len Number of characters available in return string" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " "; + + if (Deprecated) + Include << "LIBMB5_DEPRECATED(" << Replacement << ") "; + + Include << "int mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ", char *str, int len);" << std::endl; + Include << std::endl; + + Source << " MB5_C_STR_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else if ("integer"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; + Include << " *" << std::endl; + Include << " * @return Returned value" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_INT_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else if ("double"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; + Include << " *" << std::endl; + Include << " * @return Returned value" << std::endl; + Include << " */" << std::endl; + Include << " double mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_DOUBLE_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else if ("object"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; + Include << " *" << std::endl; + Include << " * @return #Mb5" << PropertyUpperName << " object" << std::endl; + Include << " */" << std::endl; + Include << " Mb5" << PropertyUpperName << " mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else if ("relationlist"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param " << UpperName << " #Mb5" << UpperName << "List object" << std::endl; + Include << " *" << std::endl; + Include << " * @return #Mb5" << PropertyUpperName << "List object" << std::endl; + Include << " */" << std::endl; + Include << " Mb5" << PropertyUpperName << "List mb5_" << LowerName << "_get_" << PropertyLowerName << "list(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "List," << PropertyLowerName << "list)" << std::endl; + } + else if ("iswc"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param " << UpperName << " #Mb5" << UpperName << "List object" << std::endl; + Include << " *" << std::endl; + Include << " * @return #Mb5" << PropertyUpperName << "List object" << std::endl; + Include << " */" << std::endl; + Include << " Mb5" << PropertyUpperName << "List mb5_" << LowerName << "_get_" << PropertyLowerName << "list(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "List," << PropertyLowerName << "list)" << std::endl; + } + else if ("ipi"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param " << UpperName << " #Mb5" << UpperName << "List object" << std::endl; + Include << " *" << std::endl; + Include << " * @return #Mb5" << PropertyUpperName << "List object" << std::endl; + Include << " */" << std::endl; + Include << " Mb5" << PropertyUpperName << "List mb5_" << LowerName << "_get_" << PropertyLowerName << "list(Mb5" << UpperName << " " << UpperName << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "List," << PropertyLowerName << "list)" << std::endl; + } + else + { + std::cerr << "Unexpected property type: '" << PropertyType << "'" << std::endl; + exit(1); + } + } + else + { + std::cerr << "Class " << LowerName << " property specified with no name or type" << std::endl; + exit(1); + } + } + } + + Source << std::endl; + } + else + { + std::cerr << "Class specified with no name" << std::endl; + exit(1); + } +} + +void ProcessList(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include) +{ + if (Node.isAttributeSet("name")) + { + std::string LowerName=Node.getAttribute("name").value(); + + std::string UpperName=LowerName; + if (Node.isAttributeSet("uppername")) + UpperName=Node.getAttribute("uppername").value(); + else + UpperName[0]=toupper(UpperName[0]); + + Include << "/**" << std::endl; + Include << " * Delete a #Mb5" << UpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to delete" << std::endl; + Include << " */" << std::endl; + Include << " void mb5_" << LowerName << "_list_delete(Mb5" << UpperName << "List List);" << std::endl; + Include << std::endl; + Include << "/**" << std::endl; + Include << " * Return the number of entries in a #Mb5" << UpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_" << LowerName << "_list_size(Mb5" << UpperName << "List List);" << std::endl; + Include << std::endl; + Include << "/**" << std::endl; + Include << " * Returns an entry from a #Mb5" << UpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " * @param Item Item number to return" << std::endl; + Include << " *" << std::endl; + Include << " * @return A #Mb5" << UpperName << " object." << std::endl; + Include << " */" << std::endl; + Include << " Mb5" << UpperName << " mb5_" << LowerName << "_list_item(Mb5" << UpperName << "List List, int Item);" << std::endl; + Include << std::endl; + Include << "/**" << std::endl; + Include << " * Return the count of entries in an #Mb5" << UpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_" << LowerName << "_list_get_count(Mb5" << UpperName << "List List);" << std::endl; + Include << std::endl; + Include << "/**" << std::endl; + Include << " * Return the offset of entries in an #Mb5" << UpperName << "List" << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_" << LowerName << "_list_get_offset(Mb5" << UpperName << "List List);" << std::endl; + Include << std::endl; + + Source << " MB5_C_LIST_GETTER(" << UpperName << "," << LowerName << ")" << std::endl; + + Include << "/**" << std::endl; + Include << "* Clone an #Mb5" << UpperName << "List object" << std::endl; + Include << "*" << std::endl; + Include << "* @param " << UpperName << "List Object to clone" << std::endl; + Include << "*" << std::endl; + Include << "* @return Cloned list. This list must be deleted once" << std::endl; + Include << "* finished with." << std::endl; + Include << "*/" << std::endl; + Include << " Mb5" << UpperName << "List mb5_" << LowerName << "_list_clone(Mb5" << UpperName << "List " << UpperName << "List" << ");" << std::endl; + Include << std::endl; + + Source << " MB5_C_CLONE(" << UpperName << "List," << LowerName << "_list)" << std::endl; + + for (XMLNode ChildNode = Node.getChildNode(); + !ChildNode.isEmpty(); + ChildNode = ChildNode.next()) + { + std::string Name=ChildNode.getName(); + + if ("property"==Name) + { + if (ChildNode.isAttributeSet("name") && ChildNode.isAttributeSet("type")) + { + std::string PropertyLowerName=ChildNode.getAttribute("name").value(); + + std::string PropertyUpperName=PropertyLowerName; + if (ChildNode.isAttributeSet("uppername")) + PropertyUpperName=ChildNode.getAttribute("uppername").value(); + else + PropertyUpperName[0]=toupper(PropertyUpperName[0]); + + std::string PropertyType=ChildNode.getAttribute("type").value(); + + if ("string"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " * @param str Returned string" << std::endl; + Include << " * @param len Number of characters available in return string" << std::endl; + Include << " *" << std::endl; + Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_" << LowerName << "_list_get_" << PropertyLowerName << "(Mb5" << UpperName << "List List, char *str, int len);" << std::endl; + Include << std::endl; + + Source << " MB5_C_STR_GETTER(" << UpperName << "List," << LowerName << "_list," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else if ("integer"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " *" << std::endl; + Include << " * @return Returned value" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_" << LowerName << "_list_get_" << PropertyLowerName << "(Mb5" << UpperName << "List List);" << std::endl; + Include << std::endl; + + Source << " MB5_C_INT_GETTER(" << UpperName << "List," << LowerName << "_list," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else if ("double"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " *" << std::endl; + Include << " * @return Returned value" << std::endl; + Include << " */" << std::endl; + Include << " double mb5_" << LowerName << "_list_get_" << PropertyLowerName << "(Mb5" << UpperName << "List List);" << std::endl; + Include << std::endl; + + Source << " MB5_C_DOUBLE_GETTER(" << UpperName << "List," << LowerName << "_list," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else if ("object"==PropertyType) + { + Include << "/**" << std::endl; + Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; + Include << " *" << std::endl; + Include << " * @param List List to use" << std::endl; + Include << " *" << std::endl; + Include << " * @return #Mb5" << PropertyUpperName << " object" << std::endl; + Include << " */" << std::endl; + Include << " int mb5_" << LowerName << "_list_get_" << PropertyLowerName << "(Mb5" << UpperName << "List List);" << std::endl; + Include << std::endl; + + Source << " MB5_C_OBJ_GETTER(" << UpperName << "List," << LowerName << "_list," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; + } + else + { + std::cerr << "Unexpected property type: '" << PropertyType << "'" << std::endl; + exit(1); + } + } + else + { + std::cerr << "List " << LowerName << " property specified with no name or type" << std::endl; + exit(1); + } + } + } + + Source << std::endl; + } + else + { + std::cerr << "List specified with no name" << std::endl; + exit(1); + } +} + +void ProcessDeclare(const XMLNode& Node, std::ofstream& /*Source*/, std::ofstream& Include) +{ + std::vector Classes; + Classes.push_back("Entity"); + + for (XMLNode ChildNode = Node.getChildNode(); + !ChildNode.isEmpty(); + ChildNode = ChildNode.next()) + { + std::string Name=ChildNode.getName(); + + if ("class"==Name || "list"==Name) + { + if (ChildNode.isAttributeSet("name")) + { + std::string UpperName=ChildNode.getAttribute("name").value(); + if (ChildNode.isAttributeSet("uppername")) + UpperName=ChildNode.getAttribute("uppername").value(); + else + UpperName[0]=toupper(UpperName[0]); + + if ("list"==Name) + UpperName+="List"; + + Classes.push_back(UpperName); + } + else + { + std::cerr << "Entity, Class or List specified with no name or type" << std::endl; + exit(1); + } + } + } + + for (std::vector::const_iterator Class=Classes.begin();Class!=Classes.end();Class++) + { + Include << " typedef void *Mb5" << *Class << ";" << std::endl; + } + + Include << std::endl; + +} diff --git a/src/xmlParser.cc b/src/xmlParser.cc new file mode 100644 index 0000000..e63df55 --- /dev/null +++ b/src/xmlParser.cc @@ -0,0 +1,205 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Christophe Fergeau + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include "config.h" +#include "musicbrainz5/defines.h" + +#include "musicbrainz5/xmlParser.h" + +#include +#include + +XMLResults::XMLResults() + : line(0), + code(eXMLErrorNone) +{} + +XMLNode::XMLNode(xmlNodePtr node) + : mNode(node) +{ +} + +XMLNode::~XMLNode() +{ +} + +XMLNode XMLNode::emptyNode() +{ + return XMLNode(NULL); +} + +XMLNode *XMLRootNode::parseFile(const std::string &filename, XMLResults* results) +{ + xmlDocPtr doc; + + doc = xmlParseFile(filename.c_str()); + if ((doc == NULL) && (results != NULL)) { + xmlErrorPtr error = xmlGetLastError(); + results->message = error->message; + results->line = error->line; + results->code = error->code; + } + + return new XMLRootNode(doc); +} + +XMLNode *XMLRootNode::parseString(const std::string &xml, XMLResults* results) +{ + xmlDocPtr doc; + + doc = xmlParseMemory(xml.c_str(), xml.length()); + if ((doc == NULL) && (results != NULL)) { + xmlErrorPtr error = xmlGetLastError(); + results->message = error->message; + results->line = error->line; + results->code = error->code; + } + + return new XMLRootNode(doc); +} + +const char *XMLNode::getName() const +{ + return (char *)mNode->name; +} + +const char *XMLNode::getText() const +{ + if (mNode->children == NULL) + return NULL; + if (!xmlNodeIsText(mNode->children)) + return NULL; + + return (char*)mNode->children->content; +} + +xmlAttrPtr XMLNode::getAttributeRaw(const char *name) const +{ + xmlAttrPtr attr; + + for (attr = mNode->properties; attr != NULL; attr = attr->next) + if (strcmp(name, (char *)attr->name) == 0) + return attr; + + return NULL; +} + +const XMLAttribute XMLNode::getAttribute(const char *name) const +{ + xmlAttrPtr attr; + + if (name == NULL) + return XMLAttribute(mNode->properties); + + attr = this->getAttributeRaw(name); + if (attr != NULL) + return XMLAttribute(attr); + + return XMLAttribute(NULL); +} + +bool XMLNode::isAttributeSet(const char *name) const +{ + return (this->getAttributeRaw(name) != NULL); +} + +bool XMLNode::operator ==(const XMLNode &rhs) const +{ + return mNode == rhs.mNode; +} + +bool operator !=(const XMLNode &lhs, const XMLNode &rhs) +{ + return !(lhs == rhs); +} + +XMLRootNode::XMLRootNode(xmlDocPtr doc): XMLNode(xmlDocGetRootElement(doc)), + mDoc(doc) +{ +} + +XMLRootNode::~XMLRootNode() +{ + if (mDoc != NULL) + xmlFreeDoc(mDoc); +} + +static xmlNodePtr skipTextNodes(xmlNodePtr node) +{ + xmlNodePtr it = node; + + while ((it != NULL) && xmlNodeIsText(it)) + it = it->next; + + return it; +} + +XMLNode XMLNode::next() const +{ + return XMLNode(skipTextNodes(mNode->next)); +} + +XMLNode XMLNode::getChildNode(const char *name) const +{ + xmlNodePtr it; + if (name == NULL) + return XMLNode(skipTextNodes(mNode->children)); + + for (it = mNode->children; it != NULL; it = it->next) { + if (xmlNodeIsText(it)) + continue; + if (strcmp(name, (char *)it->name) == 0) + return XMLNode(it); + } + + return emptyNode(); +} + +bool XMLNode::isEmpty() const +{ + return mNode == NULL; +} + +XMLAttribute::XMLAttribute(xmlAttrPtr attr) + : mAttr(attr) +{ +} + +bool XMLAttribute::isEmpty() const { + return (mAttr == NULL); +} + +std::string XMLAttribute::name() const { + return std::string((const char *)mAttr->name); +} + +std::string XMLAttribute::value() const { + return std::string((const char *)mAttr->children->content); +} + +const XMLAttribute XMLAttribute::next() const { + return XMLAttribute(mAttr->next); +} + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..9d87908 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,25 @@ +INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_SOURCE_DIR}/../include + ${CMAKE_CURRENT_BINARY_DIR}/../include + ${LIBXML2_INCLUDE_DIR} +) +LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES} ${LIBXML2_LIBRARIES}) +ADD_EXECUTABLE(mbtest mbtest.cc) +ADD_EXECUTABLE(ctest ctest.c) + +IF(CMAKE_COMPILER_IS_GNUCXX) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors") + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) +ENDIF(CMAKE_COMPILER_IS_GNUCXX) + +IF(CMAKE_COMPILER_IS_GNUCC) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic-errors") + IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") + ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) + set_source_files_properties(ctest.c PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") + set_source_files_properties(mbtest.cc PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") +ENDIF(CMAKE_COMPILER_IS_GNUCC) + diff --git a/tests/ctest.c b/tests/ctest.c new file mode 100644 index 0000000..4c4b506 --- /dev/null +++ b/tests/ctest.c @@ -0,0 +1,820 @@ +/* -------------------------------------------------------------------------- + + libmusicbrainz5 - Client library to access MusicBrainz + + Copyright (C) 2012 Andrew Hawkins + + This file is part of libmusicbrainz5. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + libmusicbrainz5 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this library. If not, see . + + $Id$ + +----------------------------------------------------------------------------*/ + +#include +#include +#include + +#include "musicbrainz5/mb5_c.h" + +void PrintRelationList(Mb5RelationList RelationList) +{ + char Type[256]; + int count; + + mb5_relation_list_get_targettype(RelationList,Type,sizeof(Type)); + printf("Target type is '%s'\n",Type); + + for (count=0;count. + + $Id$ + +----------------------------------------------------------------------------*/ + +#include + +#include + +#include "musicbrainz5/Query.h" +#include "musicbrainz5/Release.h" +#include "musicbrainz5/ReleaseGroup.h" +#include "musicbrainz5/Medium.h" +#include "musicbrainz5/MediumList.h" +#include "musicbrainz5/NameCredit.h" +#include "musicbrainz5/ArtistCredit.h" +#include "musicbrainz5/Artist.h" +#include "musicbrainz5/Alias.h" +#include "musicbrainz5/HTTPFetch.h" +#include "musicbrainz5/Track.h" +#include "musicbrainz5/Recording.h" +#include "musicbrainz5/Collection.h" +#include "musicbrainz5/CollectionList.h" +#include "musicbrainz5/RelationListList.h" +#include "musicbrainz5/RelationList.h" +#include "musicbrainz5/Relation.h" +#include "musicbrainz5/Work.h" +#include "musicbrainz5/ISWC.h" +#include "musicbrainz5/ISWCList.h" +#include "musicbrainz5/SecondaryType.h" +#include "musicbrainz5/SecondaryTypeList.h" +#include "musicbrainz5/IPI.h" +#include "musicbrainz5/IPIList.h" +#include "musicbrainz5/Lifespan.h" + +void PrintRelationList(MusicBrainz5::CRelationList *RelationList) +{ + std::cout << "Target type: '" << RelationList->TargetType() << "'" << std::endl; + + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CRelation *Relation=RelationList->Item(count); + std::cout << "Relation: " << count << " - Type '" << Relation->Type() << "', Target '" << Relation->Target() << "'" << std::endl; + } +} + +int main(int argc, const char *argv[]) +{ + MusicBrainz5::CQuery MB2("MBTest/v1.0","test.musicbrainz.org"); + + MusicBrainz5::CQuery::tParamMap Params5; + Params5["inc"]="aliases"; + MusicBrainz5::CMetadata Metadata5=MB2.Query("artist","4b585938-f271-45e2-b19a-91c634b5e396","",Params5); + MusicBrainz5::CArtist *Artist=Metadata5.Artist(); + if (Artist) + { + MusicBrainz5::CLifespan *Lifespan=Artist->Lifespan(); + if (Lifespan) + { + std::cout << "Begin: " << Lifespan->Begin() << std::endl; + std::cout << "End: " << Lifespan->End() << std::endl; + std::cout << "Ended: " << Lifespan->Ended() << std::endl; + } + } + + return 0; + + MusicBrainz5::CMetadata Metadata8=MB2.Query("release-group","2eefe885-f050-426d-93f0-29c5eb8b4f9a"); + std::cout << Metadata8 << std::endl; + return 0; + + MusicBrainz5::CMetadata Metadata7=MB2.Query("artist","4b585938-f271-45e2-b19a-91c634b5e396"); + Artist=Metadata7.Artist(); + if (Artist) + { + MusicBrainz5::CIPIList *IPIList=Artist->IPIList(); + if (IPIList) + { + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CIPI *IPI=IPIList->Item(count); + if (IPI) + { + std::cout << "IPI " << count << ": " << IPI->IPI() << std::endl; + } + } + } + } + + return 0; + + MusicBrainz5::CMetadata Metadata6=MB2.Query("release-group","2eefe885-f050-426d-93f0-29c5eb8b4f9a"); + MusicBrainz5::CReleaseGroup *ReleaseGroup=Metadata6.ReleaseGroup(); + if (ReleaseGroup) + { + std::cout << "ID: " << ReleaseGroup->ID() << std::endl; + std::cout << "PrimaryType: " << ReleaseGroup->PrimaryType() << std::endl; + std::cout << "Title: " << ReleaseGroup->Title() << std::endl; + std::cout << "Disambiguation: " << ReleaseGroup->Disambiguation() << std::endl; + std::cout << "FirstReleaseDate: " << ReleaseGroup->FirstReleaseDate() << std::endl; + + MusicBrainz5::CSecondaryTypeList *SecondaryTypeList=ReleaseGroup->SecondaryTypeList(); + if (SecondaryTypeList) + { + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CSecondaryType *SecondaryType=SecondaryTypeList->Item(count); + if (SecondaryType) + { + std::cout << "Secondary type " << count << " = " << SecondaryType->SecondaryType() << std::endl; + } + } + } + } + + return 0; + + MusicBrainz5::CMetadata Metadata4=MB2.Query("work","b0d17375-5593-390e-a936-1a65ce74c630"); + + MusicBrainz5::CWork *ThisWork=Metadata4.Work(); + if (ThisWork) + { + std::cout << "ID: '" << ThisWork->ID() << "'" << std::endl; + std::cout << "Title: '" << ThisWork->Title() << "'" << std::endl; + + MusicBrainz5::CISWCList *ISWCList=ThisWork->ISWCList(); + if (ISWCList) + { + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CISWC *ISWC=ISWCList->Item(count); + std::cout << "ISWC " << count << " - '" << ISWC->ISWC() << "'" << std::endl; + } + } + + std::cout << "Disambiguation: '" << ThisWork->Disambiguation() << "'" << std::endl; + std::cout << "Language: '" << ThisWork->Language() << "'" << std::endl; + } + + MusicBrainz5::CQuery::tParamMap Params3; + Params3["inc"]="media recordings"; + + Metadata4=MB2.Query("release","ae050d13-7f86-495e-9918-10d8c0ac58e8","",Params3); + MusicBrainz5::CRelease *Release2=Metadata4.Release(); + if (Release2) + { + MusicBrainz5::CMediumList *MediumList=Release2->MediumList(); + if (MediumList) + { + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CMedium *Medium=MediumList->Item(count); + if (Medium) + { + MusicBrainz5::CTrackList *TrackList=Medium->TrackList(); + if (TrackList) + { + for (int track=0;trackNumItems();track++) + { + MusicBrainz5::CTrack *Track=TrackList->Item(track); + if (Track) + { + std::cout << "Position: " << Track->Position() << std::endl; + std::cout << "Title: " << Track->Title() << std::endl; + std::cout << "Length: " << Track->Length() << std::endl; + std::cout << "Number: " << Track->Number() << std::endl; + } + } + } + } + } + } + } + + return 0; + + MusicBrainz5::CQuery MB("MBTest/v1.0"); + + if (argc>1) + { + std::cout << "Setting username: '" << argv[1] << "'" << std::endl; + MB.SetUserName(argv[1]); + } + + if (argc>2) + { + std::cout << "Setting password: '" << argv[2] << "'" << std::endl; + MB.SetPassword(argv[2]); + } + + MusicBrainz5::CQuery::tParamMap Params2; + Params2["inc"]="artists release-groups url-rels work-level-rels work-rels artist-rels"; + MusicBrainz5::CMetadata Metadata3=MB.Query("recording","3631f569-520d-40ff-a1ee-076604723275","",Params2); + MusicBrainz5::CRecording *Recording=Metadata3.Recording(); + if (Recording) + { + MusicBrainz5::CRelationListList *RelationListList=Recording->RelationListList(); + for (int count=0;countNumItems();count++) + { + MusicBrainz5::CRelationList *RelationList=RelationListList->Item(count); + PrintRelationList(RelationList); + } + } + + return 0; + + MusicBrainz5::CQuery::tParamMap Params; + Params["inc"]="artists labels recordings release-groups url-rels discids recording-level-rels work-level-rels work-rels artist-rels"; + + MusicBrainz5::CMetadata Metadata2=MB.Query("release","ef4596f0-5554-443a-aea9-247d2e250f61","",Params); + + MusicBrainz5::CRelease *Release=Metadata2.Release(); + if (Release) + { + MusicBrainz5::CMediumList *MediumList=Release->MediumList(); + + if (MediumList) + { + for (int MediumNum=0;MediumNumNumItems();MediumNum++) + { + MusicBrainz5::CMedium *Medium=MediumList->Item(MediumNum); + if (Medium) + { + MusicBrainz5::CTrackList *TrackList=Medium->TrackList(); + if (TrackList) + { + for (int TrackNum=0;TrackNumNumItems();TrackNum++) + { + MusicBrainz5::CTrack *Track=TrackList->Item(TrackNum); + if (Track) + { + MusicBrainz5::CRecording *Recording=Track->Recording(); + if (Recording) + { + MusicBrainz5::CRelationListList *RelationListList=Recording->RelationListList(); + if (RelationListList) + { + std::cout << RelationListList->NumItems() << " items" << std::endl; + for (int RelationListNum=0;RelationListNumNumItems();RelationListNum++) + { + MusicBrainz5::CRelationList *RelationList=RelationListList->Item(RelationListNum); + PrintRelationList(RelationList); + } + } + } + } + } + } + } + } + } + } + + return 0; + + MusicBrainz5::CMetadata Metadata=MB.Query("collection"); + MusicBrainz5::CCollectionList *CollectionList=Metadata.CollectionList(); + if (CollectionList && 0!=CollectionList->NumItems()) + { + MusicBrainz5::CCollection *Collection=CollectionList->Item(0); + std::cout << "ID is " << Collection->ID() << std::endl; + + MB.Query("collection",Collection->ID(),"releases"); + + std::vector Releases; + Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); + Releases.push_back("f6335672-c521-4129-86c3-490d20533e08"); + bool Ret=MB.AddCollectionEntries(Collection->ID(),Releases); + std::cout << "AddCollectionEntries returns " << std::boolalpha << Ret << std::endl; + + MB.Query("collection",Collection->ID(),"releases"); + + Releases.clear(); + Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); + Ret=MB.DeleteCollectionEntries(Collection->ID(),Releases); + std::cout << "DeleteCollectionEntries returns " << std::boolalpha << Ret << std::endl; + + MB.Query("collection",Collection->ID(),"releases"); + } + + return 0; + + std::string DiscID="arIS30RPWowvwNEqsqdDnZzDGhk-"; + + if (argc==2) + DiscID=argv[1]; + + MusicBrainz5::CReleaseList ReleaseList=MB.LookupDiscID(DiscID); + + for (int count=0;countID()); + + std::cout << "Full release: " << std::endl; + + std::cout << FullRelease << std::endl; + + std::cout << "Release group title: '" << FullRelease.ReleaseGroup()->Title() << "'" << std::endl; + + std::cout << std::endl << std::endl << "Media matching " << DiscID << ":" << std::endl; + + MusicBrainz5::CMediumList MediaList=FullRelease.MediaMatchingDiscID(DiscID); + + for (int count=0;count