1
/* ipuz-puzzle.h
2
 *
3
 * Copyright 2021 Jonathan Blandford <jrb@gnome.org>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
 *
19
 * SPDX-License-Identifier: (LGPL-2.1-or-later OR MIT)
20
 */
21

            
22
#pragma once
23

            
24
#include <glib-object.h>
25
#include <json-glib/json-glib.h>
26
#include <libipuz/ipuz-style.h>
27
#include <libipuz/ipuz-puzzle-info.h>
28

            
29

            
30
G_BEGIN_DECLS
31

            
32

            
33
typedef enum
34
{
35
  IPUZ_PUZZLE_ACROSTIC,
36
  IPUZ_PUZZLE_ARROWWORD,
37
  IPUZ_PUZZLE_BARRED,
38
  IPUZ_PUZZLE_CROSSWORD,
39
  IPUZ_PUZZLE_CRYPTIC,
40
  IPUZ_PUZZLE_FILIPPINE,
41
  IPUZ_PUZZLE_UNKNOWN,
42
} IPuzPuzzleKind;
43

            
44

            
45
#define IPUZ_TYPE_PUZZLE (ipuz_puzzle_get_type ())
46
1038
G_DECLARE_DERIVABLE_TYPE (IPuzPuzzle, ipuz_puzzle, IPUZ, PUZZLE, GObject);
47

            
48

            
49
typedef void (*IPuzStyleForeachFunc) (const gchar *style_name,
50
                                      IPuzStyle   *style,
51
                                      gpointer     user_data);
52

            
53

            
54
typedef struct _IPuzPuzzleClass IPuzPuzzleClass;
55
struct _IPuzPuzzleClass
56
{
57
  GObjectClass parent_class;
58

            
59
  /* Virtual functions */
60
  void                (*load_node)      (IPuzPuzzle     *puzzle,
61
                                         const char     *member_name,
62
                                         JsonNode       *node);
63
  void                (*post_load_node) (IPuzPuzzle     *puzzle,
64
                                         const char     *member_name,
65
                                         JsonNode       *node);
66
  void                (*fixup)          (IPuzPuzzle     *puzzle);
67
  void                (*validate)       (IPuzPuzzle     *puzzle);
68
  gboolean            (*equal)          (IPuzPuzzle     *puzzle_a,
69
                                         IPuzPuzzle     *puzzle_b);
70
  void                (*build)          (IPuzPuzzle     *puzzle,
71
                                         JsonBuilder    *builder);
72
  IPuzPuzzleFlags     (*get_flags)      (IPuzPuzzle     *puzzle);
73
  void                (*clone)          (IPuzPuzzle     *src,
74
                                         IPuzPuzzle     *dest);
75
  const char * const *(*get_kind_str)   (IPuzPuzzle     *puzzle);
76
  void                (*set_style)      (IPuzPuzzle     *puzzle,
77
                                         const char     *style_name,
78
                                         IPuzStyle      *style);
79
  void                (*calculate_info) (IPuzPuzzle     *puzzle,
80
                                         IPuzPuzzleInfo *info);
81
};
82

            
83

            
84
IPuzPuzzle      *ipuz_puzzle_new_from_json   (JsonNode              *root,
85
                                              GError               **error);
86
IPuzPuzzle      *ipuz_puzzle_new_from_file   (const char            *filename,
87
                                              GError               **error);
88
IPuzPuzzle      *ipuz_puzzle_new_from_stream (GInputStream          *stream,
89
                                              GCancellable          *cancellable,
90
                                              GError               **error);
91
IPuzPuzzle      *ipuz_puzzle_new_from_data   (const gchar           *data,
92
                                              gsize                  length,
93
                                              GError               **error);
94
gboolean         ipuz_puzzle_save_to_file    (IPuzPuzzle            *puzzle,
95
                                              const char            *filename,
96
                                              GError               **error);
97
gboolean         ipuz_puzzle_save_to_stream  (IPuzPuzzle            *puzzle,
98
                                              GOutputStream         *stream,
99
                                              GCancellable          *cancellable,
100
                                              GError               **error);
101
gchar           *ipuz_puzzle_save_to_data    (IPuzPuzzle            *puzzle,
102
                                              gsize                 *length);
103
IPuzPuzzle      *ipuz_puzzle_deep_copy       (IPuzPuzzle            *puzzle);
104
gboolean         ipuz_puzzle_equal           (IPuzPuzzle            *puzzle_a,
105
                                              IPuzPuzzle            *puzzle_b);
106

            
107
IPuzPuzzleKind   ipuz_puzzle_get_puzzle_kind (IPuzPuzzle            *puzzle);
108
IPuzPuzzleFlags  ipuz_puzzle_get_flags       (IPuzPuzzle            *puzzle);
109
IPuzPuzzleInfo  *ipuz_puzzle_get_info        (IPuzPuzzle            *puzzle);
110
IPuzCharset     *ipuz_puzzle_get_charset     (IPuzPuzzle            *self);
111
void             ipuz_puzzle_set_charset     (IPuzPuzzle            *self,
112
                                              IPuzCharset           *charset);
113
const gchar     *ipuz_puzzle_get_charset_str (IPuzPuzzle            *self);
114
void             ipuz_puzzle_set_charset_str (IPuzPuzzle            *self,
115
                                              const gchar           *charset_str);
116
IPuzStyle       *ipuz_puzzle_get_style       (IPuzPuzzle            *self,
117
                                              const gchar           *style_name);
118
void             ipuz_puzzle_set_style       (IPuzPuzzle            *self,
119
                                              const gchar           *style_name,
120
                                              IPuzStyle             *style);
121
void             ipuz_puzzle_style_foreach   (IPuzPuzzle            *self,
122
                                              IPuzStyleForeachFunc   func,
123
                                              gpointer               user_data);
124

            
125

            
126
G_END_DECLS