aboutsummaryrefslogtreecommitdiff
// -*- C++ -*-
//  Boost general library 'format'   ---------------------------
//  See http://www.boost.org for updates, documentation, and revision history.

//  (C) Samuel Krempp 2001
//                  krempp@crans.ens-cachan.fr
//  Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// ideas taken from Rüdiger Loos's format class
// and Karl Nelson's ofstream (also took its parsing code as basis for printf parsing)

// ------------------------------------------------------------------------------
// format_class.hpp :  class interface
// ------------------------------------------------------------------------------


#ifndef BOOST_FORMAT_CLASS_HPP
#define BOOST_FORMAT_CLASS_HPP

#include <vector>
#include <string>

#include <boost/format/format_fwd.hpp>
#include <boost/format/internals_fwd.hpp>

#include <boost/format/internals.hpp>

namespace boost {

class basic_format 
{
public:
  typedef std::string                string_t;
  typedef BOOST_IO_STD ostringstream internal_stream_t;
private:
  typedef BOOST_IO_STD ostream       stream_t;
  typedef io::detail::stream_format_state  stream_format_state;
  typedef io::detail::format_item          format_item_t;

public:
  basic_format(const char* str);
  basic_format(const string_t& s);
#ifndef BOOST_NO_STD_LOCALE
  basic_format(const char* str, const std::locale & loc);
  basic_format(const string_t& s, const std::locale & loc);
#endif // no locale
  basic_format(const basic_format& x);
  basic_format& operator= (const basic_format& x);

  basic_format& clear(); // empty the string buffers (except bound arguments, see clear_binds() )

  // pass arguments through those operators :
  template<class T>  basic_format&   operator%(const T& x) 
  { 
    return io::detail::feed<const T&>(*this,x);
  }

#ifndef BOOST_NO_OVERLOAD_FOR_NON_CONST
  template<class T>  basic_format&   operator%(T& x) 
  {
    return io::detail::feed<T&>(*this,x);
  }
#endif


  // system for binding arguments :
  template<class T>  
  basic_format&         bind_arg(int argN, const T& val) 
  {
    return io::detail::bind_arg_body(*this, argN, val); 
  }
  basic_format&         clear_bind(int argN);
  basic_format&         clear_binds();

  // modify the params of a directive, by applying a manipulator :
  template<class T> 
  basic_format&  modify_item(int itemN, const T& manipulator) 
  {
    return io::detail::modify_item_body(*this, itemN, manipulator) ;
  }

  // Choosing which errors will throw exceptions :
  unsigned char exceptions() const;
  unsigned char exceptions(unsigned char newexcept);

  // final output
  string_t str() const;
  friend BOOST_IO_STD ostream& 
  operator<< ( BOOST_IO_STD ostream& , const basic_format& ); 
                      

  template<class T>  friend basic_format&  
  io::detail::feed(basic_format&, T);
    
  template<class T>  friend   
  void io::detail::distribute(basic_format&, T);
  
  template<class T>  friend
  basic_format&  io::detail::modify_item_body(basic_format&, int, const T&);

  template<class T> friend
  basic_format&  io::detail::bind_arg_body(basic_format&, int, const T&);

// make the members private only if the friend templates are supported
private:

  // flag bits, used for style_
  enum style_values  { ordered = 1,        // set only if all directives are  positional directives
                       special_needs = 4 };     

  // parse the format string :
  void parse(const string_t&);

  int                           style_;         // style of format-string :  positional or not, etc
  int                           cur_arg_;       // keep track of wich argument will come
  int                           num_args_;      // number of expected arguments
  mutable bool                  dumped_;        // true only after call to str() or <<
  std::vector<format_item_t>    items_;         // vector of directives (aka items)
  string_t                      prefix_;        // piece of string to insert before first item

  std::vector<bool>             bound_;         // stores which arguments were bound
                                                //   size = num_args OR zero
  internal_stream_t             oss_;           // the internal stream.
  stream_format_state           state0_;        // reference state for oss_
  unsigned char                 exceptions_;
}; // class basic_format


} // namespace boost


#endif // BOOST_FORMAT_CLASS_HPP
-07tests: telephony: Remove obsolete parsing tests....Fixes <https://issues.guix.gnu.org/56343>. * tests/services/telephony.scm (parse-dbus-reply, parse-account-ids) (parse-account-details, parse-contacts, getAccountList-reply): Delete procedures. ("parse-account-ids"): Delete test. (getAccountDetails-reply): Delete procedure. ("parse-account-details; username, alias and display name"): Delete test. (getContacts-reply): Delete procedure. ("parse-account-contacts"): Delete test. (getContacts-empty-reply): Delete procedure. ("parse-account-contacts, empty array"): Delete test. Reported-by: Ludovic Courtès <ludo@gnu.org> Maxim Cournoyer 2022-06-24services: configuration: Report the location of field type errors....Previously field type errors would be reported in a non-standard way, and without any source location information. This fixes it. * gnu/services/configuration.scm (configuration-field-error): Add a 'loc' parameter and honor it. Use 'formatted-message' instead of plain 'format'. (define-configuration-helper)[field-sanitizer]: New procedure. Use it. Use STEM as the identifier of the syntactic constructor of the record type. Add a 'sanitize' property to each field. Remove now useless STEM macro that would call 'validate-configuration'. * gnu/services/mail.scm (serialize-listener-configuration): Adjust to new 'configuration-field-error' prototype. * tests/services/configuration.scm ("wrong type for a field"): New test. * po/guix/POTFILES.in: Add gnu/services/configuration.scm. Ludovic Courtès 2022-06-15services: configuration: Use *unspecified* instead of 'disabled....Use *unspecified* as a marker for field values that have not been set. Rationale: 'disabled may easily clash with user values for boolean fields, is confusing (i.e. its meaning is *not* boolean false, but unspecified) and it also passes silently through the symbol? predicate of a field of type symbol. * gnu/services/configuration.scm (configuration-missing-default-value): Renamed from configuration-no-default-value. (define-maybe-helper): Use *unspecified* instead of 'disabled, and make the default value optional. * gnu/home/services/desktop.scm (home-redshift-configuration): Change (maybe-xyz 'disabled) to maybe-xyz. * gnu/services/authentication.scm (nslcd-configuration): Likewise. * gnu/services/cgit.scm (repository-cgit-configuration): Likewise. * gnu/services/file-sharing.scm (serialize-maybe-string) (serialize-maybe-file-object): Use 'unspecified?' instead of (eq? val 'disabled). * gnu/services/messaging.scm (raw-content?): Likewise. (ssl-configuration): Change (maybe-xyz 'disabled) to maybe-xyz. (prosody-configuration): Likewise. * gnu/services/file-sharing.scm (transmission-daemon-configuration): Likewise. * gnu/services/messaging.scm (define-all-configurations): Use *unspecified* instead of 'disabled'. * gnu/services/networking.scm (opendht-configuration): Likewise. * gnu/services/pm.scm (tlp-configuration): Likewise. * gnu/services/telephony.scm (jami-account): Likewise. (jami-configuration): Likewise. * gnu/services/vpn.scm (openvpn-client-configuration): Likewise. * tests/services/configuration.scm ("maybe type, no default") ("maybe type, with default"): New tests. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Attila Lendvai 2022-06-15services: configuration: Support (field1 maybe-number "") format....As opposed to explicitly using 'disabled as value, or using the (field1 (maybe-number) "") format. It's mostly the work of Maxime Devos shared under #54674, with some modifications by Attila Lendvai. * gnu/services/configuration.scm (normalize-field-type+def): New function. (define-configuration-helper) (define-configuration): Support new field format. * tests/services/configuration.scm (config-with-maybe-number->string): New function. ("maybe value serialization of the instance"): New test. ("maybe value serialization of the instance, unspecified"): New test. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Attila Lendvai 2021-08-02Reinstate "services: Add a service for Jami."...This reverts commit 4673f817938d9d2b1b40a072ab2e0c44a32ccc97, which reverted commit 69dcc24c9f0cdfea674eb690e7755d26a25ced2b with the fix detailed below. Thanks to Christopher Baines for reporting the failure and proposing a fix. * guix/self.scm (compiled-guix) [*system-test-modules*]: Add the test data files via the 'extra-files' argument. * gnu/local.mk (dist_patch_DATA): Move the tests/data/jami-dummy-account.dat file to... * gnu/local.mk (MODULES_NOT_COMPILED): ... here. Maxim Cournoyer 2021-08-02Revert "services: Add a service for Jami."...This reverts commit 69dcc24c9f0cdfea674eb690e7755d26a25ced2b. It broke 'guix pull'. Maxim Cournoyer 2021-08-02services: Add a service for Jami....* gnu/services/telephony.scm (string-or-computed-file?) (string-list?, account-fingerprint-list?): New procedures. (maybe-string-list, maybe-account-fingerprint-list) (maybe-boolean, maybe-string, jami-account-list): New configuration field types. (serialize-string-list, serialize-boolean, serialize-string) (jami-account, jami-account->alist, jami-configuration) (jami-account-list?, jami-account-list-maybe): New procedures. (%jami-accounts): New variable. (jami-configuration->command-line-arguments): New procedure. (jami-dbus-session-activation, jami-shepherd-services): New procedures. (jami-service-type): New variable. * gnu/build/jami-service.scm: New file. * gnu/tests/data/jami-dummy-account.dat: Likewise. * gnu/tests/telephony.scm: Likewise. * gnu/local.mk (GNU_SYSTEM_MODULES): Register them. * Makefile.am (SCM_TESTS): Register the test file. (dist_patch_DATA): Register the new data file. * doc/guix.texi (Telephony Services): Document it. Maxim Cournoyer 2021-06-29services: configuration: Allow specifying prefix for serializer names....Sometimes two configurations might have the same types for their field values, but the values might be serialized in two completely different ways (e.g. because the two programs have different configuration languages). An example of this would be the ‘serialize-boolean’ procedure in (gnu services mail) and (gnu services getmail). They both serialize a boolean value, but because the Dovecot’s configuration language has a different syntax to the configuration language for Getmail, two different procedures have to be defined. One way to workaround this would be to specify custom serializers for many fields in order to separate the serialization of the values that have the same type but serialize in different ways. This could get very tedious, especially if there are many configurations in the same module. Another way would be to move one of the configurations to its own module, like what was done with (gnu services getmail). However, this would mean that there would be multiple modules containing configurations for related programs, e.g. we have (gnu services mail) and (gnu services getmail), it doesn’t make much sense to keep the Getmail configuration in its own module. This patch will allow one to write something like this: (define-configuration foo-configuration (bar (string "bob") "Option bar.") (prefix bar-)) and the value of the ‘bar’ field would be serialized using a procedure named ‘bar-serialize-string’ instead of just ‘serialize-string’. * gnu/services/configuration.scm (define-maybe-helper): Accept ‘prefix’ argument for using serializer with custom prefix. (define-maybe): Pattern match on ‘prefix’ literal. (define-configuration-helper): Accept ‘prefix’ argument for using serializer with custom prefix. (define-configuration): Pattern match on ‘prefix’ literal. * tests/services/configuration.scm ("serialize-configuration with prefix"): New test. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Xinglu Chen